src/Tools/Metis/src/Proof.sml
author desharna
Thu, 09 Jul 2020 11:39:16 +0200
changeset 72004 913162a47d9f
parent 45778 df6e210fb44c
permissions -rw-r--r--
Update Metis to 2.4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     1
(* ========================================================================= *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     2
(* PROOFS IN FIRST ORDER LOGIC                                               *)
72004
913162a47d9f Update Metis to 2.4
desharna
parents: 45778
diff changeset
     3
(* Copyright (c) 2001 Joe Leslie-Hurd, distributed under the BSD License     *)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     4
(* ========================================================================= *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     5
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     6
structure Proof :> Proof =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     7
struct
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     8
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     9
open Useful;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    10
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    11
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    12
(* A type of first order logic proofs.                                       *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    13
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    14
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    15
datatype inference =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    16
    Axiom of LiteralSet.set
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    17
  | Assume of Atom.atom
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    18
  | Subst of Subst.subst * Thm.thm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    19
  | Resolve of Atom.atom * Thm.thm * Thm.thm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    20
  | Refl of Term.term
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    21
  | Equality of Literal.literal * Term.path * Term.term;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    22
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    23
type proof = (Thm.thm * inference) list;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    24
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    25
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    26
(* Printing.                                                                 *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    27
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    28
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    29
fun inferenceType (Axiom _) = Thm.Axiom
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    30
  | inferenceType (Assume _) = Thm.Assume
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    31
  | inferenceType (Subst _) = Thm.Subst
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    32
  | inferenceType (Resolve _) = Thm.Resolve
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    33
  | inferenceType (Refl _) = Thm.Refl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    34
  | inferenceType (Equality _) = Thm.Equality;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    35
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    36
local
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    37
  fun ppAssume atm = Print.sequence Print.break (Atom.pp atm);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    38
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    39
  fun ppSubst ppThm (sub,thm) =
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    40
      Print.sequence Print.break
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    41
        (Print.inconsistentBlock 1
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    42
           [Print.ppString "{",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    43
            Print.ppOp2 " =" Print.ppString Subst.pp ("sub",sub),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    44
            Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    45
            Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    46
            Print.ppOp2 " =" Print.ppString ppThm ("thm",thm),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    47
            Print.ppString "}"]);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    48
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    49
  fun ppResolve ppThm (res,pos,neg) =
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    50
      Print.sequence Print.break
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    51
        (Print.inconsistentBlock 1
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    52
           [Print.ppString "{",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    53
            Print.ppOp2 " =" Print.ppString Atom.pp ("res",res),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    54
            Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    55
            Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    56
            Print.ppOp2 " =" Print.ppString ppThm ("pos",pos),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    57
            Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    58
            Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    59
            Print.ppOp2 " =" Print.ppString ppThm ("neg",neg),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    60
            Print.ppString "}"]);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    61
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    62
  fun ppRefl tm = Print.sequence Print.break (Term.pp tm);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    63
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    64
  fun ppEquality (lit,path,res) =
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    65
      Print.sequence Print.break
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    66
        (Print.inconsistentBlock 1
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    67
           [Print.ppString "{",
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    68
            Print.ppOp2 " =" Print.ppString Literal.pp ("lit",lit),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    69
            Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    70
            Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    71
            Print.ppOp2 " =" Print.ppString Term.ppPath ("path",path),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    72
            Print.ppString ",",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    73
            Print.break,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    74
            Print.ppOp2 " =" Print.ppString Term.pp ("res",res),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
    75
            Print.ppString "}"]);
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    76
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    77
  fun ppInf ppAxiom ppThm inf =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    78
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    79
        val infString = Thm.inferenceTypeToString (inferenceType inf)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    80
      in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    81
        Print.inconsistentBlock 2
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    82
          [Print.ppString infString,
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    83
           (case inf of
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    84
              Axiom cl => ppAxiom cl
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    85
            | Assume x => ppAssume x
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    86
            | Subst x => ppSubst ppThm x
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    87
            | Resolve x => ppResolve ppThm x
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    88
            | Refl x => ppRefl x
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    89
            | Equality x => ppEquality x)]
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    90
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    91
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    92
  fun ppAxiom cl =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    93
      Print.sequence
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
    94
        Print.break
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    95
        (Print.ppMap
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    96
           LiteralSet.toList
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    97
           (Print.ppBracket "{" "}" (Print.ppOpList "," Literal.pp)) cl);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    98
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    99
  val ppInference = ppInf ppAxiom Thm.pp;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   100
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   101
  fun pp prf =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   102
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   103
        fun thmString n = "(" ^ Int.toString n ^ ")"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   104
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   105
        val prf = enumerate prf
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   106
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   107
        fun ppThm th =
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   108
            Print.ppString
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   109
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   110
              val cl = Thm.clause th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   111
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   112
              fun pred (_,(th',_)) = LiteralSet.equal (Thm.clause th') cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   113
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   114
              case List.find pred prf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   115
                NONE => "(?)"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   116
              | SOME (n,_) => thmString n
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   117
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   118
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   119
        fun ppStep (n,(th,inf)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   120
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   121
              val s = thmString n
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   122
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   123
              Print.sequence
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   124
                (Print.consistentBlock (1 + size s)
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   125
                   [Print.ppString (s ^ " "),
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   126
                    Thm.pp th,
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   127
                    Print.breaks 2,
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   128
                    Print.ppBracket "[" "]" (ppInf (K Print.skip) ppThm) inf])
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   129
                Print.newline
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   130
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   131
      in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   132
        Print.consistentBlock 0
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   133
          [Print.ppString "START OF PROOF",
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   134
           Print.newline,
42102
fcfd07f122d4 new version of Metis 2.3 (29 Dec. 2010)
blanchet
parents: 39502
diff changeset
   135
           Print.program (List.map ppStep prf),
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39353
diff changeset
   136
           Print.ppString "END OF PROOF"]
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   137
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   138
(*MetisDebug
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   139
      handle Error err => raise Bug ("Proof.pp: shouldn't fail:\n" ^ err);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   140
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   141
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   142
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   143
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   144
val inferenceToString = Print.toString ppInference;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   145
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   146
val toString = Print.toString pp;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   147
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   148
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   149
(* Reconstructing single inferences.                                         *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   150
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   151
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   152
fun parents (Axiom _) = []
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   153
  | parents (Assume _) = []
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   154
  | parents (Subst (_,th)) = [th]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   155
  | parents (Resolve (_,th,th')) = [th,th']
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   156
  | parents (Refl _) = []
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   157
  | parents (Equality _) = [];
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   158
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   159
fun inferenceToThm (Axiom cl) = Thm.axiom cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   160
  | inferenceToThm (Assume atm) = Thm.assume (true,atm)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   161
  | inferenceToThm (Subst (sub,th)) = Thm.subst sub th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   162
  | inferenceToThm (Resolve (atm,th,th')) = Thm.resolve (true,atm) th th'
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   163
  | inferenceToThm (Refl tm) = Thm.refl tm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   164
  | inferenceToThm (Equality (lit,path,r)) = Thm.equality lit path r;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   165
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   166
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   167
  fun reconstructSubst cl cl' =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   168
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   169
        fun recon [] =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   170
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   171
(*MetisTrace3
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   172
              val () = Print.trace LiteralSet.pp "reconstructSubst: cl" cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   173
              val () = Print.trace LiteralSet.pp "reconstructSubst: cl'" cl'
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   174
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   175
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   176
              raise Bug "can't reconstruct Subst rule"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   177
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   178
          | recon (([],sub) :: others) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   179
            if LiteralSet.equal (LiteralSet.subst sub cl) cl' then sub
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   180
            else recon others
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   181
          | recon ((lit :: lits, sub) :: others) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   182
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   183
              fun checkLit (lit',acc) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   184
                  case total (Literal.match sub lit) lit' of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   185
                    NONE => acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   186
                  | SOME sub => (lits,sub) :: acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   187
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   188
              recon (LiteralSet.foldl checkLit others cl')
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   189
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   190
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   191
        Subst.normalize (recon [(LiteralSet.toList cl, Subst.empty)])
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   192
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   193
(*MetisDebug
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   194
      handle Error err =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   195
        raise Bug ("Proof.recontructSubst: shouldn't fail:\n" ^ err);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   196
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   197
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   198
  fun reconstructResolvant cl1 cl2 cl =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   199
      (if not (LiteralSet.subset cl1 cl) then
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   200
         LiteralSet.pick (LiteralSet.difference cl1 cl)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   201
       else if not (LiteralSet.subset cl2 cl) then
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   202
         Literal.negate (LiteralSet.pick (LiteralSet.difference cl2 cl))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   203
       else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   204
         (* A useless resolution, but we must reconstruct it anyway *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   205
         let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   206
           val cl1' = LiteralSet.negate cl1
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   207
           and cl2' = LiteralSet.negate cl2
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   208
           val lits = LiteralSet.intersectList [cl1,cl1',cl2,cl2']
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   209
         in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   210
           if not (LiteralSet.null lits) then LiteralSet.pick lits
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   211
           else raise Bug "can't reconstruct Resolve rule"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   212
         end)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   213
(*MetisDebug
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   214
      handle Error err =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   215
        raise Bug ("Proof.recontructResolvant: shouldn't fail:\n" ^ err);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   216
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   217
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   218
  fun reconstructEquality cl =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   219
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   220
(*MetisTrace3
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   221
        val () = Print.trace LiteralSet.pp "Proof.reconstructEquality: cl" cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   222
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   223
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   224
        fun sync s t path (f,a) (f',a') =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   225
            if not (Name.equal f f' andalso length a = length a') then NONE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   226
            else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   227
              let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   228
                val itms = enumerate (zip a a')
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   229
              in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   230
                case List.filter (not o uncurry Term.equal o snd) itms of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   231
                  [(i,(tm,tm'))] =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   232
                  let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   233
                    val path = i :: path
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   234
                  in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   235
                    if Term.equal tm s andalso Term.equal tm' t then
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   236
                      SOME (List.rev path)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   237
                    else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   238
                      case (tm,tm') of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   239
                        (Term.Fn f_a, Term.Fn f_a') => sync s t path f_a f_a'
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   240
                      | _ => NONE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   241
                  end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   242
                | _ => NONE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   243
              end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   244
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   245
        fun recon (neq,(pol,atm),(pol',atm')) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   246
            if pol = pol' then NONE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   247
            else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   248
              let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   249
                val (s,t) = Literal.destNeq neq
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   250
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   251
                val path =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   252
                    if not (Term.equal s t) then sync s t [] atm atm'
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   253
                    else if not (Atom.equal atm atm') then NONE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   254
                    else Atom.find (Term.equal s) atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   255
              in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   256
                case path of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   257
                  SOME path => SOME ((pol',atm),path,t)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   258
                | NONE => NONE
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   259
              end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   260
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   261
        val candidates =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   262
            case List.partition Literal.isNeq (LiteralSet.toList cl) of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   263
              ([l1],[l2,l3]) => [(l1,l2,l3),(l1,l3,l2)]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   264
            | ([l1,l2],[l3]) => [(l1,l2,l3),(l1,l3,l2),(l2,l1,l3),(l2,l3,l1)]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   265
            | ([l1],[l2]) => [(l1,l1,l2),(l1,l2,l1)]
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   266
            | _ => raise Bug "reconstructEquality: malformed"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   267
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   268
(*MetisTrace3
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   269
        val ppCands =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   270
            Print.ppList (Print.ppTriple Literal.pp Literal.pp Literal.pp)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   271
        val () = Print.trace ppCands
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   272
                   "Proof.reconstructEquality: candidates" candidates
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   273
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   274
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   275
        case first recon candidates of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   276
          SOME info => info
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   277
        | NONE => raise Bug "can't reconstruct Equality rule"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   278
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   279
(*MetisDebug
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   280
      handle Error err =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   281
        raise Bug ("Proof.recontructEquality: shouldn't fail:\n" ^ err);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   282
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   283
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   284
  fun reconstruct cl (Thm.Axiom,[]) = Axiom cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   285
    | reconstruct cl (Thm.Assume,[]) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   286
      (case LiteralSet.findl Literal.positive cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   287
         SOME (_,atm) => Assume atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   288
       | NONE => raise Bug "malformed Assume inference")
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   289
    | reconstruct cl (Thm.Subst,[th]) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   290
      Subst (reconstructSubst (Thm.clause th) cl, th)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   291
    | reconstruct cl (Thm.Resolve,[th1,th2]) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   292
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   293
        val cl1 = Thm.clause th1
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   294
        and cl2 = Thm.clause th2
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   295
        val (pol,atm) = reconstructResolvant cl1 cl2 cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   296
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   297
        if pol then Resolve (atm,th1,th2) else Resolve (atm,th2,th1)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   298
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   299
    | reconstruct cl (Thm.Refl,[]) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   300
      (case LiteralSet.findl (K true) cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   301
         SOME lit => Refl (Literal.destRefl lit)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   302
       | NONE => raise Bug "malformed Refl inference")
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   303
    | reconstruct cl (Thm.Equality,[]) = Equality (reconstructEquality cl)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   304
    | reconstruct _ _ = raise Bug "malformed inference";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   305
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   306
  fun thmToInference th =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   307
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   308
(*MetisTrace3
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   309
        val () = Print.trace Thm.pp "Proof.thmToInference: th" th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   310
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   311
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   312
        val cl = Thm.clause th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   313
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   314
        val thmInf = Thm.inference th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   315
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   316
(*MetisTrace3
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   317
        val ppThmInf = Print.ppPair Thm.ppInferenceType (Print.ppList Thm.pp)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   318
        val () = Print.trace ppThmInf "Proof.thmToInference: thmInf" thmInf
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   319
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   320
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   321
        val inf = reconstruct cl thmInf
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   322
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   323
(*MetisTrace3
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   324
        val () = Print.trace ppInference "Proof.thmToInference: inf" inf
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   325
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   326
(*MetisDebug
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   327
        val () =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   328
            let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   329
              val th' = inferenceToThm inf
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   330
            in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   331
              if LiteralSet.equal (Thm.clause th') cl then ()
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   332
              else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   333
                raise
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   334
                  Bug
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   335
                    ("Proof.thmToInference: bad inference reconstruction:" ^
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   336
                     "\n  th = " ^ Thm.toString th ^
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   337
                     "\n  inf = " ^ inferenceToString inf ^
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   338
                     "\n  inf th = " ^ Thm.toString th')
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   339
            end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   340
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   341
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   342
        inf
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   343
      end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   344
(*MetisDebug
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   345
      handle Error err =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   346
        raise Bug ("Proof.thmToInference: shouldn't fail:\n" ^ err);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   347
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   348
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   349
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   350
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   351
(* Reconstructing whole proofs.                                              *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   352
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   353
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   354
local
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   355
  val emptyThms : Thm.thm LiteralSetMap.map = LiteralSetMap.new ();
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   356
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   357
  fun addThms (th,ths) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   358
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   359
        val cl = Thm.clause th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   360
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   361
        if LiteralSetMap.inDomain cl ths then ths
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   362
        else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   363
          let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   364
            val (_,pars) = Thm.inference th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   365
            val ths = List.foldl addThms ths pars
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   366
          in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   367
            if LiteralSetMap.inDomain cl ths then ths
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   368
            else LiteralSetMap.insert ths (cl,th)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   369
          end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   370
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   371
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   372
  fun mkThms th = addThms (th,emptyThms);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   373
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   374
  fun addProof (th,(ths,acc)) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   375
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   376
        val cl = Thm.clause th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   377
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   378
        case LiteralSetMap.peek ths cl of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   379
          NONE => (ths,acc)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   380
        | SOME th =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   381
          let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   382
            val (_,pars) = Thm.inference th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   383
            val (ths,acc) = List.foldl addProof (ths,acc) pars
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   384
            val ths = LiteralSetMap.delete ths cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   385
            val acc = (th, thmToInference th) :: acc
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   386
          in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   387
            (ths,acc)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   388
          end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   389
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   390
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   391
  fun mkProof ths th =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   392
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   393
        val (ths,acc) = addProof (th,(ths,[]))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   394
(*MetisTrace4
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   395
        val () = Print.trace Print.ppInt "Proof.proof: unnecessary clauses" (LiteralSetMap.size ths)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   396
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   397
      in
45778
df6e210fb44c updated Metis to 20110926 version
blanchet
parents: 42102
diff changeset
   398
        List.rev acc
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   399
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   400
in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   401
  fun proof th =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   402
      let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   403
(*MetisTrace3
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   404
        val () = Print.trace Thm.pp "Proof.proof: th" th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   405
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   406
        val ths = mkThms th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   407
        val infs = mkProof ths th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   408
(*MetisTrace3
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   409
        val () = Print.trace Print.ppInt "Proof.proof: size" (length infs)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   410
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   411
      in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   412
        infs
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   413
      end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   414
end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   415
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   416
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   417
(* Free variables.                                                           *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   418
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   419
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   420
fun freeIn v =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   421
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   422
      fun free th_inf =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   423
          case th_inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   424
            (_, Axiom lits) => LiteralSet.freeIn v lits
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   425
          | (_, Assume atm) => Atom.freeIn v atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   426
          | (th, Subst _) => Thm.freeIn v th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   427
          | (_, Resolve _) => false
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   428
          | (_, Refl tm) => Term.freeIn v tm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   429
          | (_, Equality (lit,_,tm)) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   430
            Literal.freeIn v lit orelse Term.freeIn v tm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   431
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   432
      List.exists free
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   433
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   434
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   435
val freeVars =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   436
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   437
      fun inc (th_inf,set) =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   438
          NameSet.union set
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   439
          (case th_inf of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   440
             (_, Axiom lits) => LiteralSet.freeVars lits
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   441
           | (_, Assume atm) => Atom.freeVars atm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   442
           | (th, Subst _) => Thm.freeVars th
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   443
           | (_, Resolve _) => NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   444
           | (_, Refl tm) => Term.freeVars tm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   445
           | (_, Equality (lit,_,tm)) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   446
             NameSet.union (Literal.freeVars lit) (Term.freeVars tm))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   447
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   448
      List.foldl inc NameSet.empty
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   449
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   450
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   451
end