src/HOL/TPTP/TPTP_Proof_Reconstruction.thy
author haftmann
Mon, 14 Apr 2025 20:19:05 +0200
changeset 82509 c476149a3790
parent 80910 406a85a25189
permissions -rw-r--r--
tuned
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
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1506
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1507
    scrubup_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1508
    |> break_seq
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1509
    |> tap (fn (_, rest) => \<^assert> (null (Seq.list_of rest)))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1510
    |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1511
    |> TERMFUN (snd (*discard hypotheses*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1512
                 #> get_skolem_conc_const) NONE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1513
    |> switch (fold (fn x => fn l => if is_some x then the x :: l else l)) []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1514
    |> map Const
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1515
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1516
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1517
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1518
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1519
fun exists_tac ctxt feats consts_diff =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1520
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1521
    val ex_var =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1522
      if loop_can_feature [Existential_Var] feats andalso consts_diff <> [] then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1523
        new_skolem_tac ctxt consts_diff
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1524
        (*We're making sure that each skolem constant is used once in instantiations.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1525
      else K no_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1526
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1527
    val ex_free =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1528
      if loop_can_feature [Existential_Free] feats andalso consts_diff = [] then
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 58941
diff changeset
  1529
        eresolve_tac ctxt @{thms polar_exE}
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1530
      else K no_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1531
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1532
    ex_var APPEND' ex_free
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1533
  end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1534
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1535
fun forall_tac ctxt feats =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1536
  if loop_can_feature [Universal] feats then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1537
    forall_pos_tac ctxt
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1538
  else K no_tac
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1539
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1540
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1541
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1542
subsubsection "Finite types"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1543
(*lift quantification from a singleton literal to a singleton clause*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1544
lemma forall_pos_lift:
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
  1545
"\<lbrakk>(\<forall>X. P X) = True; \<forall>X. (P X = True) \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R" by auto
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1546
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1547
(*predicate over the type of the leading quantified variable*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1548
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1549
ML \<open>
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1550
fun extcnf_forall_special_pos_tac ctxt =
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1551
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1552
    val bool =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1553
      ["True", "False"]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1554
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1555
    val bool_to_bool =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1556
      ["% _ . True", "% _ . False", "% x . x", "Not"]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1557
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1558
    val tacs =
59763
56d2c357e6b5 tuned signature;
wenzelm
parents: 59760
diff changeset
  1559
      map (fn t_s =>  (* FIXME proper context!? *)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1560
       Rule_Insts.eres_inst_tac \<^context> [((("x", 0), Position.none), t_s)] [] @{thm allE}
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1561
       THEN' assume_tac ctxt)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1562
  in
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1563
    (TRY o eresolve_tac ctxt @{thms forall_pos_lift})
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1564
    THEN' (assume_tac ctxt
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1565
           ORELSE' FIRST'
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1566
            (*FIXME could check the type of the leading quantified variable, instead of trying everything*)
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1567
            (tacs (bool @ bool_to_bool)))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1568
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1569
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1570
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1571
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1572
subsubsection "Emulator"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1573
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1574
lemma efq: "[|A = True; A = False|] ==> R" by auto
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1575
ML \<open>
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1576
fun efq_tac ctxt =
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1577
  (eresolve_tac ctxt @{thms efq} THEN' assume_tac ctxt)
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1578
  ORELSE' assume_tac ctxt
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1579
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1580
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1581
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1582
(*This is applied to all subgoals, repeatedly*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1583
fun extcnf_combined_main ctxt feats consts_diff =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1584
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1585
    (*This is applied to subgoals which don't have a conclusion
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1586
      consisting of a Skolem definition*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1587
    fun extcnf_combined_tac' ctxt i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1588
      let
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1589
        val skolem_consts_used_so_far = which_skolem_concs_used ctxt st
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
  1590
        val consts_diff' = subtract (op =) skolem_consts_used_so_far consts_diff
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1591
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1592
        fun feat_to_tac feat =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1593
          case feat of
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1594
              Close_Branch => trace_tac' ctxt "mark: closer" (efq_tac ctxt)
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1595
            | ConjI => trace_tac' ctxt "mark: conjI" (resolve_tac ctxt @{thms conjI})
59533
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1596
            | King_Cong => trace_tac' ctxt "mark: expander_animal" (expander_animal ctxt)
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1597
            | Break_Hypotheses => trace_tac' ctxt "mark: break_hypotheses" (break_hypotheses_tac ctxt)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1598
            | RemoveRedundantQuantifications => K all_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1599
(*
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1600
FIXME Building this into the loop instead.. maybe not the ideal choice
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1601
            | RemoveRedundantQuantifications =>
59533
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1602
                trace_tac' ctxt "mark: strip_unused_variable_hyp"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1603
                 (REPEAT_DETERM o remove_redundant_quantification_in_lit)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1604
*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1605
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1606
            | Assumption => assume_tac ctxt
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1607
(*FIXME both Existential_Free and Existential_Var run same code*)
59533
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1608
            | Existential_Free => trace_tac' ctxt "mark: forall_neg" (exists_tac ctxt feats consts_diff')
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1609
            | Existential_Var => trace_tac' ctxt "mark: forall_neg" (exists_tac ctxt feats consts_diff')
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1610
            | Universal => trace_tac' ctxt "mark: forall_pos" (forall_tac ctxt feats)
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1611
            | Not_pos => trace_tac' ctxt "mark: not_pos" (dresolve_tac ctxt @{thms leo2_rules(9)})
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1612
            | Not_neg => trace_tac' ctxt "mark: not_neg" (dresolve_tac ctxt @{thms leo2_rules(10)})
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1613
            | Or_pos => trace_tac' ctxt "mark: or_pos" (dresolve_tac ctxt @{thms leo2_rules(5)}) (*could add (6) for negated conjunction*)
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1614
            | Or_neg => trace_tac' ctxt "mark: or_neg" (dresolve_tac ctxt @{thms leo2_rules(7)})
59533
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1615
            | Equal_pos => trace_tac' ctxt "mark: equal_pos" (dresolve_tac ctxt (@{thms eq_pos_bool} @ [@{thm leo2_rules(3)}, @{thm eq_pos_func}]))
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1616
            | Equal_neg => trace_tac' ctxt "mark: equal_neg" (dresolve_tac ctxt [@{thm eq_neg_bool}, @{thm leo2_rules(4)}])
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1617
            | Donkey_Cong => trace_tac' ctxt "mark: donkey_cong" (simper_animal ctxt THEN' ex_expander_tac ctxt)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1618
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1619
            | Extuni_Bool2 => trace_tac' ctxt "mark: extuni_bool2" (dresolve_tac ctxt @{thms extuni_bool2})
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1620
            | Extuni_Bool1 => trace_tac' ctxt "mark: extuni_bool1" (dresolve_tac ctxt @{thms extuni_bool1})
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1621
            | Extuni_Bind => trace_tac' ctxt "mark: extuni_triv" (eresolve_tac ctxt @{thms extuni_triv})
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1622
            | Extuni_Triv => trace_tac' ctxt "mark: extuni_triv" (eresolve_tac ctxt @{thms extuni_triv})
59533
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1623
            | Extuni_Dec => trace_tac' ctxt "mark: extuni_dec_tac" (extuni_dec_tac ctxt)
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1624
            | Extuni_FlexRigid => trace_tac' ctxt "mark: extuni_flex_rigid" (assume_tac ctxt ORELSE' asm_full_simp_tac ctxt)
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1625
            | Extuni_Func => trace_tac' ctxt "mark: extuni_func" (dresolve_tac ctxt @{thms extuni_func})
59533
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1626
            | Polarity_switch => trace_tac' ctxt "mark: polarity_switch" (eresolve_tac ctxt @{thms polarity_switch})
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1627
            | Forall_special_pos => trace_tac' ctxt "mark: dorall_special_pos" (extcnf_forall_special_pos_tac ctxt)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1628
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1629
        val core_tac =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1630
          get_loop_feats feats
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1631
          |> map feat_to_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1632
          |> FIRST'
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1633
      in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1634
        core_tac i st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1635
      end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1636
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1637
    (*This is applied to all subgoals, repeatedly*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1638
    fun extcnf_combined_tac ctxt i =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1639
      COND (TERMPRED (fn _ => true) conc_is_skolem_def (SOME i))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1640
        no_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1641
        (extcnf_combined_tac' ctxt i)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1642
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1643
    val core_tac = CHANGED (ALLGOALS (IF_UNSOLVED o TRY o extcnf_combined_tac ctxt))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1644
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1645
    val full_tac = REPEAT core_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1646
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1647
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1648
    CHANGED
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1649
      (if can_feature (InnerLoopOnce []) feats then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1650
         core_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1651
       else full_tac)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1652
  end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1653
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1654
val interpreted_consts =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1655
  [\<^const_name>\<open>HOL.All\<close>, \<^const_name>\<open>HOL.Ex\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1656
   \<^const_name>\<open>Hilbert_Choice.Eps\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1657
   \<^const_name>\<open>HOL.conj\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1658
   \<^const_name>\<open>HOL.disj\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1659
   \<^const_name>\<open>HOL.eq\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1660
   \<^const_name>\<open>HOL.implies\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1661
   \<^const_name>\<open>HOL.The\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1662
   \<^const_name>\<open>HOL.Ex1\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1663
   \<^const_name>\<open>HOL.Not\<close>,
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1664
   (* @{const_name HOL.iff}, *) (*FIXME do these exist?*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1665
   (* @{const_name HOL.not_equal}, *)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1666
   \<^const_name>\<open>HOL.False\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1667
   \<^const_name>\<open>HOL.True\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1668
   \<^const_name>\<open>Pure.imp\<close>]
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1669
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1670
fun strip_qtfrs_tac ctxt =
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1671
  REPEAT_DETERM (HEADGOAL (resolve_tac ctxt @{thms allI}))
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1672
  THEN REPEAT_DETERM (HEADGOAL (eresolve_tac ctxt @{thms exE}))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1673
  THEN HEADGOAL (canonicalise_qtfr_order ctxt)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1674
  THEN
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1675
    ((REPEAT (HEADGOAL (nominal_inst_parametermatch_tac ctxt @{thm allE})))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1676
     APPEND (REPEAT (HEADGOAL (inst_parametermatch_tac ctxt [@{thm allE}]))))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1677
  (*FIXME need to handle "@{thm exI}"?*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1678
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1679
(*difference in constants between the hypothesis clause and the conclusion clause*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1680
fun clause_consts_diff thm =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1681
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1682
    val t =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
  1683
      Thm.prop_of thm
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1684
      |> Logic.dest_implies
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1685
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1686
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1687
      (*This bit should not be needed, since Leo2 inferences don't have parameters*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1688
      |> TPTP_Reconstruct.strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1689
      |> snd
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1690
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1691
    val do_diff =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1692
      Logic.dest_implies
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1693
      #> uncurry TPTP_Reconstruct.new_consts_between
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1694
      #> filter
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1695
           (fn Const (n, _) =>
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
  1696
             not (member (op =) interpreted_consts n))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1697
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1698
    if head_of t = Logic.implies then do_diff t
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1699
    else []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1700
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1701
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1702
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1703
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1704
(*remove quantification in hypothesis clause (! X. t), if
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1705
  X not free in t*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1706
fun remove_redundant_quantification ctxt i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1707
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1708
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
  1709
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1710
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1711
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1712
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1713
    if null gls then raise NO_GOALS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1714
    else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1715
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1716
        val (params, (hyp_clauses, conc_clause)) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1717
          rpair (i - 1) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1718
          |> uncurry nth
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1719
          |> TPTP_Reconstruct.strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1720
          |> apsnd Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1721
      in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1722
        (*this is to fail gracefully in case this tactic is applied to a goal which doesn't have a single hypothesis*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1723
        if length hyp_clauses > 1 then no_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1724
        else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1725
          let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1726
            val hyp_clause = the_single hyp_clauses
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1727
            val sep_prefix =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1728
              HOLogic.dest_Trueprop
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1729
              #> TPTP_Reconstruct.strip_top_All_vars
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1730
              #> apfst rev
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1731
            val (hyp_prefix, hyp_body) = sep_prefix hyp_clause
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1732
            val (conc_prefix, conc_body) = sep_prefix conc_clause
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1733
          in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1734
            if null hyp_prefix orelse
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
  1735
              member (op =) conc_prefix (hd hyp_prefix) orelse
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
  1736
              member (op =)  (Term.add_frees hyp_body []) (hd hyp_prefix) then
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1737
              no_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1738
            else
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59763
diff changeset
  1739
              Rule_Insts.eres_inst_tac ctxt [((("x", 0), Position.none), "(@X. False)")] []
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59639
diff changeset
  1740
                @{thm allE} i st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1741
          end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1742
     end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1743
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1744
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1745
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1746
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1747
fun remove_redundant_quantification_ignore_skolems ctxt i =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1748
  COND (TERMPRED (fn _ => true) conc_is_skolem_def (SOME i))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1749
    no_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1750
    (remove_redundant_quantification ctxt i)
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1751
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1752
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1753
lemma drop_redundant_literal_qtfr:
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
  1754
  "(\<forall>X. P) = True \<Longrightarrow> P = True"
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
  1755
  "(\<exists>X. P) = True \<Longrightarrow> P = True"
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
  1756
  "(\<forall>X. P) = False \<Longrightarrow> P = False"
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
  1757
  "(\<exists>X. P) = False \<Longrightarrow> P = False"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1758
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1759
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1760
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1761
(*remove quantification in the literal "(! X. t) = True/False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1762
  in the singleton hypothesis clause, if X not free in t*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1763
fun remove_redundant_quantification_in_lit ctxt i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1764
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1765
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
  1766
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1767
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1768
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1769
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1770
    if null gls then raise NO_GOALS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1771
    else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1772
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1773
        val (params, (hyp_clauses, conc_clause)) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1774
          rpair (i - 1) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1775
          |> uncurry nth
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1776
          |> TPTP_Reconstruct.strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1777
          |> apsnd Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1778
      in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1779
        (*this is to fail gracefully in case this tactic is applied to a goal which doesn't have a single hypothesis*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1780
        if length hyp_clauses > 1 then no_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1781
        else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1782
          let
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1783
            fun literal_content (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ lhs $ (rhs as \<^term>\<open>True\<close>)) = SOME (lhs, rhs)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1784
              | literal_content (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ lhs $ (rhs as \<^term>\<open>False\<close>)) = SOME (lhs, rhs)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1785
              | literal_content t = NONE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1786
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1787
            val hyp_clause =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1788
              the_single hyp_clauses
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1789
              |> HOLogic.dest_Trueprop
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1790
              |> literal_content
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1791
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1792
          in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1793
            if is_none hyp_clause then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1794
              no_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1795
            else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1796
              let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1797
                val (hyp_lit_prefix, hyp_lit_body) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1798
                  the hyp_clause
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1799
                  |> (fn (t, polarity) =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1800
                       TPTP_Reconstruct.strip_top_All_vars t
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1801
                       |> apfst rev)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1802
              in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1803
                if null hyp_lit_prefix orelse
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
  1804
                  member (op =)  (Term.add_frees hyp_lit_body []) (hd hyp_lit_prefix) then
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1805
                  no_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1806
                else
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 58941
diff changeset
  1807
                  dresolve_tac ctxt @{thms drop_redundant_literal_qtfr} i st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1808
              end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1809
          end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1810
     end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1811
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1812
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1813
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1814
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1815
fun remove_redundant_quantification_in_lit_ignore_skolems ctxt i =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1816
  COND (TERMPRED (fn _ => true) conc_is_skolem_def (SOME i))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1817
    no_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1818
    (remove_redundant_quantification_in_lit ctxt i)
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1819
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1820
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1821
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1822
fun extcnf_combined_tac ctxt prob_name_opt feats skolem_consts = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1823
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1824
    val thy = Proof_Context.theory_of ctxt
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1825
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1826
    (*Initially, st consists of a single goal, showing the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1827
      hypothesis clause implying the conclusion clause.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1828
      There are no parameters.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1829
    val consts_diff =
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 63167
diff changeset
  1830
      union (=) skolem_consts
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1831
       (if can_feature ConstsDiff feats then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1832
          clause_consts_diff st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1833
        else [])
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1834
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1835
    val main_tac =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1836
      if can_feature (LoopOnce []) feats orelse can_feature (InnerLoopOnce []) feats then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1837
        extcnf_combined_main ctxt feats consts_diff
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1838
      else if can_feature (Loop []) feats then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1839
        BEST_FIRST (TERMPRED (fn _ => true) conc_is_skolem_def NONE, size_of_thm)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1840
(*FIXME maybe need to weaken predicate to include "solved form"?*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1841
         (extcnf_combined_main ctxt feats consts_diff)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1842
      else all_tac (*to allow us to use the cleaning features*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1843
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1844
    (*Remove hypotheses from Skolem definitions,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1845
      then remove duplicate subgoals,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1846
      then we should be left with skolem definitions:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1847
        absorb them as axioms into the theory.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1848
    val cleanup =
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1849
      cleanup_skolem_defs ctxt feats
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1850
      THEN remove_duplicates_tac feats
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1851
      THEN (if can_feature AbsorbSkolemDefs feats then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1852
              ALLGOALS (absorb_skolem_def ctxt prob_name_opt)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1853
            else all_tac)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1854
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1855
    val have_loop_feats =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1856
      (get_loop_feats feats; true)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1857
      handle NO_LOOP_FEATS => false
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1858
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1859
    val tec =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1860
      (if can_feature StripQuantifiers feats then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1861
         (REPEAT (CHANGED (strip_qtfrs_tac ctxt)))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1862
       else all_tac)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1863
      THEN (if can_feature Flip_Conclusion feats then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1864
             HEADGOAL (flip_conclusion_tac ctxt)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1865
           else all_tac)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1866
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1867
      (*after stripping the quantifiers any remaining quantifiers
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1868
        can be simply eliminated -- they're redundant*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1869
      (*FIXME instead of just using allE, instantiate to a silly
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1870
         term, to remove opportunities for unification.*)
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1871
      THEN (REPEAT_DETERM (eresolve_tac ctxt @{thms allE} 1))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1872
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1873
      THEN (REPEAT_DETERM (resolve_tac ctxt @{thms allI} 1))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1874
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1875
      THEN (if have_loop_feats then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1876
              REPEAT (CHANGED
59533
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1877
              ((ALLGOALS (TRY o clause_breaker_tac ctxt)) (*brush away literals which don't change*)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1878
               THEN
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1879
                (*FIXME move this to a different level?*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1880
                (if loop_can_feature [Polarity_switch] feats then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1881
                   all_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1882
                 else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1883
                   (TRY (IF_UNSOLVED (HEADGOAL (remove_redundant_quantification_ignore_skolems ctxt))))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1884
                   THEN (TRY (IF_UNSOLVED (HEADGOAL (remove_redundant_quantification_in_lit_ignore_skolems ctxt)))))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1885
               THEN (TRY main_tac)))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1886
            else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1887
              all_tac)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1888
      THEN IF_UNSOLVED cleanup
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1889
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1890
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1891
    DEPTH_SOLVE (CHANGED tec) st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1892
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1893
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1894
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1895
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1896
subsubsection "unfold_def"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1897
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1898
(*this is used when handling unfold_tac, because the skeleton includes the definitions conjoined with the goal. it turns out that, for my tactic, the definitions are harmful. instead of modifying the skeleton (which may be nontrivial) i'm just dropping the information using this lemma. obviously, and from the name, order matters here.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1899
lemma drop_first_hypothesis [rule_format]: "\<lbrakk>A; B\<rbrakk> \<Longrightarrow> B" by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1900
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1901
(*Unfold_def works by reducing the goal to a meta equation,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1902
  then working on it until it can be discharged by atac,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1903
  or reflexive, or else turned back into an object equation
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1904
  and broken down further.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1905
lemma un_meta_polarise: "(X \<equiv> True) \<Longrightarrow> X" by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1906
lemma meta_polarise: "X \<Longrightarrow> X \<equiv> True" by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1907
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1908
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1909
fun unfold_def_tac ctxt depends_on_defs = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1910
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1911
    (*This is used when we end up with something like
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1912
        (A & B) \<equiv> True \<Longrightarrow> (B & A) \<equiv> True.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1913
      It breaks down this subgoal until it can be trivially
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1914
      discharged.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1915
     *)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1916
    val kill_meta_eqs_tac =
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1917
      dresolve_tac ctxt @{thms un_meta_polarise}
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1918
      THEN' resolve_tac ctxt @{thms meta_polarise}
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1919
      THEN' (REPEAT_DETERM o (eresolve_tac ctxt @{thms conjE}))
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1920
      THEN' (REPEAT_DETERM o (resolve_tac ctxt @{thms conjI} ORELSE' assume_tac ctxt))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1921
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1922
    val continue_reducing_tac =
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1923
      resolve_tac ctxt @{thms meta_eq_to_obj_eq} 1
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1924
      THEN (REPEAT_DETERM (ex_expander_tac ctxt 1))
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1925
      THEN TRY (polarise_subgoal_hyps ctxt 1) (*no need to REPEAT_DETERM here, since there should only be one hypothesis*)
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1926
      THEN TRY (dresolve_tac ctxt @{thms eq_reflection} 1)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1927
      THEN (TRY ((CHANGED o rewrite_goal_tac ctxt
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1928
              (@{thm expand_iff} :: @{thms simp_meta})) 1))
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1929
      THEN HEADGOAL (resolve_tac ctxt @{thms reflexive}
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1930
                     ORELSE' assume_tac ctxt
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1931
                     ORELSE' kill_meta_eqs_tac)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1932
60318
ab785001b51d tuned spelling;
wenzelm
parents: 59882
diff changeset
  1933
    val tactic =
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1934
      (resolve_tac ctxt @{thms polarise} 1 THEN assume_tac ctxt 1)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1935
      ORELSE
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1936
        (REPEAT_DETERM (eresolve_tac ctxt @{thms conjE} 1 THEN
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1937
          eresolve_tac ctxt @{thms drop_first_hypothesis} 1)
60319
127c2f00ca94 standardize towards Thm.eta_long_conversion, which just does eta_long conversion;
wenzelm
parents: 60318
diff changeset
  1938
         THEN PRIMITIVE (Conv.fconv_rule Thm.eta_long_conversion)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1939
         THEN (REPEAT_DETERM (ex_expander_tac ctxt 1))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1940
         THEN (TRY ((CHANGED o rewrite_goal_tac ctxt @{thms simp_meta}) 1))
60319
127c2f00ca94 standardize towards Thm.eta_long_conversion, which just does eta_long conversion;
wenzelm
parents: 60318
diff changeset
  1941
         THEN PRIMITIVE (Conv.fconv_rule Thm.eta_long_conversion)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1942
         THEN
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1943
           (HEADGOAL (assume_tac ctxt)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1944
           ORELSE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1945
            (unfold_tac ctxt depends_on_defs
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1946
             THEN IF_UNSOLVED continue_reducing_tac)))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1947
  in
60318
ab785001b51d tuned spelling;
wenzelm
parents: 59882
diff changeset
  1948
    tactic st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1949
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1950
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1951
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1952
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1953
subsection "Handling split 'preprocessing'"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1954
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1955
lemma split_tranfs:
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
  1956
  "\<forall>x. P x \<and> Q x \<equiv> (\<forall>x. P x) \<and> (\<forall>x. Q x)"
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
  1957
  "\<not> (\<not> A) \<equiv> A"
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
  1958
  "\<exists>x. A \<equiv> A"
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
  1959
  "(A \<and> B) \<and> C \<equiv> A \<and> B \<and> C"
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
  1960
  "A = B \<equiv> (A \<longrightarrow> B) \<and> (B \<longrightarrow> A)"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1961
by (rule eq_reflection, auto)+
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1962
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1963
(*Same idiom as ex_expander_tac*)
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1964
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1965
fun split_simp_tac (ctxt : Proof.context) i =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1966
   let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1967
     val simpset =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1968
       fold Simplifier.add_simp @{thms split_tranfs} (empty_simpset ctxt)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1969
   in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1970
     CHANGED (asm_full_simp_tac simpset i)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1971
   end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1972
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1973
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1974
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1975
subsection "Alternative reconstruction tactics"
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1976
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1977
(*An "auto"-based proof reconstruction, where we attempt to reconstruct each inference
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1978
  using auto_tac. A realistic tactic would inspect the inference name and act
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1979
  accordingly.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1980
fun auto_based_reconstruction_tac ctxt prob_name n =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1981
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1982
    val thy = Proof_Context.theory_of ctxt
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1983
    val pannot = TPTP_Reconstruct.get_pannot_of_prob thy prob_name
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1984
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1985
    TPTP_Reconstruct.inference_at_node
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1986
     thy
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1987
     prob_name (#meta pannot) n
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1988
      |> the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1989
      |> (fn {inference_fmla, ...} =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1990
          Goal.prove ctxt [] [] inference_fmla
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1991
           (fn pdata => auto_tac (#context pdata)))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1992
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1993
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1994
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1995
(*An oracle-based reconstruction, which is only used to test the shunting part of the system*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1996
oracle oracle_iinterp = "fn t => t"
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1997
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1998
fun oracle_based_reconstruction_tac ctxt prob_name n =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1999
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2000
    val thy = Proof_Context.theory_of ctxt
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2001
    val pannot = TPTP_Reconstruct.get_pannot_of_prob thy prob_name
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2002
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2003
    TPTP_Reconstruct.inference_at_node
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2004
     thy
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2005
     prob_name (#meta pannot) n
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2006
      |> the
59639
f596ed647018 clarified context;
wenzelm
parents: 59621
diff changeset
  2007
      |> (fn {inference_fmla, ...} => Thm.cterm_of ctxt inference_fmla)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2008
      |> oracle_iinterp
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2009
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  2010
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2011
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2012
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2013
subsection "Leo2 reconstruction tactic"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2014
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  2015
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2016
(*Failure reports can be adjusted to avoid interrupting
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2017
  an overall reconstruction process*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2018
fun fail ctxt x =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2019
  if unexceptional_reconstruction ctxt then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2020
    (warning x; raise INTERPRET_INFERENCE)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2021
  else error x
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2022
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2023
fun interpret_leo2_inference_tac ctxt prob_name node =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2024
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2025
    val thy = Proof_Context.theory_of ctxt
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2026
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2027
    val _ =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2028
      if Config.get ctxt tptp_trace_reconstruction then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2029
        tracing ("interpret_inference reconstructing node" ^ node ^ " of " ^ TPTP_Problem_Name.mangle_problem_name prob_name)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2030
      else ()
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2031
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2032
    val pannot = TPTP_Reconstruct.get_pannot_of_prob thy prob_name
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2033
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2034
    fun nonfull_extcnf_combined_tac feats =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2035
      extcnf_combined_tac ctxt (SOME prob_name)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2036
       [ConstsDiff,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2037
        StripQuantifiers,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2038
        InnerLoopOnce (Break_Hypotheses :: (*FIXME RemoveRedundantQuantifications :: *) feats),
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2039
        AbsorbSkolemDefs]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2040
       []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2041
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2042
    val source_inf_opt =
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
  2043
      AList.lookup (op =) (#meta pannot)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2044
      #> the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2045
      #> #source_inf_opt
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2046
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2047
    (*FIXME integrate this with other lookup code, or in the early analysis*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2048
    local
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2049
      fun node_is_of_role role node =
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
  2050
        AList.lookup (op =) (#meta pannot) node |> the
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2051
        |> #role
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2052
        |> (fn role' => role = role')
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2053
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2054
      fun roled_dependencies_names role =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2055
        let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2056
          fun values () =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2057
            case role of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2058
                TPTP_Syntax.Role_Definition =>
59858
890b68e1e8b6 support for strictly private name space entries;
wenzelm
parents: 59780
diff changeset
  2059
                  map (apsnd Binding.name_of) (#defs pannot)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2060
              | TPTP_Syntax.Role_Axiom =>
59858
890b68e1e8b6 support for strictly private name space entries;
wenzelm
parents: 59780
diff changeset
  2061
                  map (apsnd Binding.name_of) (#axs pannot)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2062
              | _ => raise UNSUPPORTED_ROLE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2063
          in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2064
            if is_none (source_inf_opt node) then []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2065
            else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2066
              case the (source_inf_opt node) of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2067
                  TPTP_Proof.Inference (_, _, parent_inf) =>
58412
f65f11f4854c more standard Isabelle/ML operations;
wenzelm
parents: 58411
diff changeset
  2068
                    map TPTP_Proof.parent_name parent_inf
f65f11f4854c more standard Isabelle/ML operations;
wenzelm
parents: 58411
diff changeset
  2069
                    |> filter (node_is_of_role role)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2070
                    |> (*FIXME currently definitions are not
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2071
                         included in the proof annotations, so
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2072
                         i'm using all the definitions available
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2073
                         in the proof. ideally i should only
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2074
                         use the ones in the proof annotation.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2075
                       (fn x =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2076
                         if role = TPTP_Syntax.Role_Definition then
59858
890b68e1e8b6 support for strictly private name space entries;
wenzelm
parents: 59780
diff changeset
  2077
                           let fun values () = map (apsnd Binding.name_of) (#defs pannot)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2078
                           in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2079
                             map snd (values ())
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2080
                           end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2081
                         else
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
  2082
                         map (fn node => AList.lookup (op =) (values ()) node |> the) x)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2083
                | _ => []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2084
         end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2085
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2086
      val roled_dependencies =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2087
        roled_dependencies_names
59858
890b68e1e8b6 support for strictly private name space entries;
wenzelm
parents: 59780
diff changeset
  2088
        #> map (Global_Theory.get_thm thy)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2089
    in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2090
      val depends_on_defs = roled_dependencies TPTP_Syntax.Role_Definition
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2091
      val depends_on_axs = roled_dependencies TPTP_Syntax.Role_Axiom
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2092
      val depends_on_defs_names = roled_dependencies_names TPTP_Syntax.Role_Definition
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2093
    end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2094
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2095
    fun get_binds source_inf_opt =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2096
      case the source_inf_opt of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2097
          TPTP_Proof.Inference (_, _, parent_inf) =>
58411
wenzelm
parents: 57773
diff changeset
  2098
            maps
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2099
              (fn TPTP_Proof.Parent _ => []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2100
                | TPTP_Proof.ParentWithDetails (_, parent_details) => parent_details)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2101
              parent_inf
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2102
        | _ => []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2103
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2104
    val inference_name =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2105
      case TPTP_Reconstruct.inference_at_node thy prob_name (#meta pannot) node of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2106
          NONE => fail ctxt "Cannot reconstruct rule: no information"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2107
        | SOME {inference_name, ...} => inference_name
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2108
    val default_tac = HEADGOAL (blast_tac ctxt)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2109
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2110
    case inference_name of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2111
      "fo_atp_e" =>
57773
2719eb9d40fe Metis is being used to emulate E steps;
sultana
parents: 56252
diff changeset
  2112
        HEADGOAL (Metis_Tactic.metis_tac [] ATP_Problem_Generate.combs_or_liftingN ctxt [])
2719eb9d40fe Metis is being used to emulate E steps;
sultana
parents: 56252
diff changeset
  2113
        (*NOTE To treat E as an oracle use the following line:
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2114
        HEADGOAL (etac (oracle_based_reconstruction_tac ctxt prob_name node))
57773
2719eb9d40fe Metis is being used to emulate E steps;
sultana
parents: 56252
diff changeset
  2115
        *)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2116
    | "copy" =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2117
         HEADGOAL
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  2118
          (assume_tac ctxt
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2119
           ORELSE'
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  2120
              (resolve_tac ctxt @{thms polarise}
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  2121
               THEN' assume_tac ctxt))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2122
    | "polarity_switch" => nonfull_extcnf_combined_tac [Polarity_switch]
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  2123
    | "solved_all_splits" => solved_all_splits_tac ctxt
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2124
    | "extcnf_not_pos" => nonfull_extcnf_combined_tac [Not_pos]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2125
    | "extcnf_forall_pos" => nonfull_extcnf_combined_tac [Universal]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2126
    | "negate_conjecture" => fail ctxt "Should not handle negate_conjecture here"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2127
    | "unfold_def" => unfold_def_tac ctxt depends_on_defs
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2128
    | "extcnf_not_neg" => nonfull_extcnf_combined_tac [Not_neg]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2129
    | "extcnf_or_neg" => nonfull_extcnf_combined_tac [Or_neg]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2130
    | "extcnf_equal_pos" => nonfull_extcnf_combined_tac [Equal_pos]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2131
    | "extcnf_equal_neg" => nonfull_extcnf_combined_tac [Equal_neg]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2132
    | "extcnf_forall_special_pos" =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2133
         nonfull_extcnf_combined_tac [Forall_special_pos]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2134
         ORELSE HEADGOAL (blast_tac ctxt)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2135
    | "extcnf_or_pos" => nonfull_extcnf_combined_tac [Or_pos]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2136
    | "extuni_bool2" => nonfull_extcnf_combined_tac [Extuni_Bool2]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2137
    | "extuni_bool1" => nonfull_extcnf_combined_tac [Extuni_Bool1]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2138
    | "extuni_dec" =>
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  2139
        HEADGOAL (assume_tac ctxt)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2140
        ORELSE nonfull_extcnf_combined_tac [Extuni_Dec]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2141
    | "extuni_bind" => nonfull_extcnf_combined_tac [Extuni_Bind]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2142
    | "extuni_triv" => nonfull_extcnf_combined_tac [Extuni_Triv]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2143
    | "extuni_flex_rigid" => nonfull_extcnf_combined_tac [Extuni_FlexRigid]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2144
    | "prim_subst" => nonfull_extcnf_combined_tac [Assumption]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2145
    | "bind" =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2146
        let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2147
          val ordered_binds = get_binds (source_inf_opt node)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2148
        in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2149
          bind_tac ctxt prob_name ordered_binds
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2150
        end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2151
    | "standard_cnf" => HEADGOAL (standard_cnf_tac ctxt)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2152
    | "extcnf_forall_neg" =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2153
        nonfull_extcnf_combined_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2154
         [Existential_Var(* , RemoveRedundantQuantifications *)] (*FIXME RemoveRedundantQuantifications*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2155
    | "extuni_func" =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2156
        nonfull_extcnf_combined_tac [Extuni_Func, Existential_Var]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2157
    | "replace_leibnizEQ" => nonfull_extcnf_combined_tac [Assumption]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2158
    | "replace_andrewsEQ" => nonfull_extcnf_combined_tac [Assumption]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2159
    | "split_preprocessing" =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2160
         (REPEAT (HEADGOAL (split_simp_tac ctxt)))
60319
127c2f00ca94 standardize towards Thm.eta_long_conversion, which just does eta_long conversion;
wenzelm
parents: 60318
diff changeset
  2161
         THEN TRY (PRIMITIVE (Conv.fconv_rule Thm.eta_long_conversion))
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  2162
         THEN HEADGOAL (assume_tac ctxt)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2163
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2164
    (*FIXME some of these could eventually be handled specially*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2165
    | "fac_restr" => default_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2166
    | "sim" => default_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2167
    | "res" => default_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2168
    | "rename" => default_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2169
    | "flexflex" => default_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2170
    | other => fail ctxt ("Unknown inference rule: " ^ other)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2171
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  2172
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2173
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  2174
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2175
fun interpret_leo2_inference ctxt prob_name node =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2176
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2177
    val thy = Proof_Context.theory_of ctxt
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2178
    val pannot = TPTP_Reconstruct.get_pannot_of_prob thy prob_name
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2179
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2180
    val (inference_name, inference_fmla) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2181
      case TPTP_Reconstruct.inference_at_node thy prob_name (#meta pannot) node of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2182
          NONE => fail ctxt "Cannot reconstruct rule: no information"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2183
        | SOME {inference_name, inference_fmla, ...} =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2184
            (inference_name, inference_fmla)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2185
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2186
    val proof_outcome =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2187
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2188
        fun prove () =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2189
          Goal.prove ctxt [] [] inference_fmla
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2190
           (fn pdata => interpret_leo2_inference_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2191
            (#context pdata) prob_name node)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2192
      in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2193
        if informative_failure ctxt then SOME (prove ())
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2194
        else try prove ()
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2195
      end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2196
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2197
  in case proof_outcome of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2198
      NONE => fail ctxt (Pretty.string_of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2199
        (Pretty.block
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2200
          [Pretty.str ("Failed inference reconstruction for '" ^
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2201
            inference_name ^ "' at node " ^ node ^ ":\n"),
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2202
           Syntax.pretty_term ctxt inference_fmla]))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2203
    | SOME thm => thm
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2204
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  2205
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2206
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  2207
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2208
(*filter a set of nodes based on which inference rule was used to
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2209
  derive a node*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2210
fun nodes_by_inference (fms : TPTP_Reconstruct.formula_meaning list) inference_rule =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2211
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2212
    fun fold_fun n l =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2213
      case TPTP_Reconstruct.node_info fms #source_inf_opt n of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2214
          NONE => l
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2215
        | SOME (TPTP_Proof.File _) => l
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2216
        | SOME (TPTP_Proof.Inference (rule_name, _, _)) =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2217
            if rule_name = inference_rule then n :: l
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2218
            else l
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2219
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2220
    fold fold_fun (map fst fms) []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2221
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  2222
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2223
55597
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2224
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2225
section "Importing proofs and reconstructing theorems"
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2226
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  2227
ML \<open>
55597
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2228
(*Preprocessing carried out on a LEO-II proof.*)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2229
fun leo2_on_load (pannot : TPTP_Reconstruct.proof_annotation) thy =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2230
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2231
    val ctxt = Proof_Context.init_global thy
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  2232
    val dud = ("", Binding.empty, \<^term>\<open>False\<close>)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2233
    val pre_skolem_defs =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2234
      nodes_by_inference (#meta pannot) "extcnf_forall_neg" @
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2235
       nodes_by_inference (#meta pannot) "extuni_func"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2236
      |> map (fn x =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2237
              (interpret_leo2_inference ctxt (#problem_name pannot) x; dud)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2238
               handle NO_SKOLEM_DEF (s, bnd, t) => (s, bnd, t))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2239
      |> filter (fn (x, _, _) => x <> "") (*In case no skolem constants were introduced in that inference*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2240
    val skolem_defs = map (fn (x, y, _) => (x, y)) pre_skolem_defs
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2241
    val thy' =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2242
      fold (fn skolem_def => fn thy =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2243
             let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2244
               val ((s, thm), thy') = Thm.add_axiom_global skolem_def thy
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2245
               (* val _ = warning ("Added skolem definition " ^ s ^ ": " ^  @{make_string thm}) *) (*FIXME use of make_string*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2246
             in thy' end)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2247
       (map (fn (_, y, z) => (y, z)) pre_skolem_defs)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2248
       thy
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2249
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2250
    ({problem_name = #problem_name pannot,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2251
      skolem_defs = skolem_defs,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2252
      defs = #defs pannot,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2253
      axs = #axs pannot,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2254
      meta = #meta pannot},
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2255
     thy')
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2256
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  2257
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  2258
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  2259
ML \<open>
55597
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2260
(*Imports and reconstructs a LEO-II proof.*)
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2261
fun reconstruct_leo2 path thy =
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2262
  let
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2263
    val prob_file = Path.base path
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2264
    val dir = Path.dir path
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2265
    val thy' = TPTP_Reconstruct.import_thm true [dir, prob_file] path leo2_on_load thy
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2266
    val ctxt =
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2267
      Context.Theory thy'
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2268
      |> Context.proof_of
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2269
    val prob_name =
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2270
      Path.implode prob_file
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2271
      |> TPTP_Problem_Name.parse_problem_name
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2272
    val theorem =
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2273
      TPTP_Reconstruct.reconstruct ctxt
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2274
       (TPTP_Reconstruct.naive_reconstruct_tac ctxt interpret_leo2_inference)
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2275
       prob_name
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2276
  in
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2277
    (*NOTE we could return the theorem value alone, since
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2278
       users could get the thy value from the thm value.*)
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2279
    (thy', theorem)
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2280
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  2281
\<close>
55597
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
  2282
57773
2719eb9d40fe Metis is being used to emulate E steps;
sultana
parents: 56252
diff changeset
  2283
end