src/Tools/Metis/src/Resolution.sml
author blanchet
Mon, 13 Sep 2010 21:09:43 +0200
changeset 39348 6f9c9899f99f
child 39349 2d0a4361c3ef
permissions -rw-r--r--
new version of the Metis files
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
(* THE RESOLUTION PROOF PROCEDURE                                            *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     3
(* Copyright (c) 2001-2007 Joe Hurd, distributed under the GNU GPL version 2 *)
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 Resolution :> Resolution =
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 resolution proof procedures.                                    *)
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
type parameters =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    16
     {active : Active.parameters,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    17
      waiting : Waiting.parameters};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    18
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    19
datatype resolution =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    20
    Resolution of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    21
      {parameters : parameters,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    22
       active : Active.active,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    23
       waiting : Waiting.waiting};
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
(* Basic operations.                                                         *)
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
val default : parameters =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    30
    {active = Active.default,
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    31
     waiting = Waiting.default};
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    32
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    33
fun new parameters ths =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    34
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    35
      val {active = activeParm, waiting = waitingParm} = parameters
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    36
      val (active,cls) = Active.new activeParm ths  (* cls = factored ths *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    37
      val waiting = Waiting.new waitingParm cls
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    38
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    39
      Resolution {parameters = parameters, active = active, waiting = waiting}
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    40
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    41
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    42
fun active (Resolution {active = a, ...}) = a;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    43
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    44
fun waiting (Resolution {waiting = w, ...}) = w;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    45
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    46
val pp =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    47
    Print.ppMap
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    48
      (fn Resolution {active,waiting,...} =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    49
          "Resolution(" ^ Int.toString (Active.size active) ^
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    50
          "<-" ^ Int.toString (Waiting.size waiting) ^ ")")
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    51
      Print.ppString;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    52
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    53
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    54
(* The main proof loop.                                                      *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    55
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    56
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    57
datatype decision =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    58
    Contradiction of Thm.thm
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    59
  | Satisfiable of Thm.thm list;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    60
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    61
datatype state =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    62
    Decided of decision
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    63
  | Undecided of resolution;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    64
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    65
fun iterate resolution =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    66
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    67
      val Resolution {parameters,active,waiting} = resolution
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    68
(*MetisTrace2
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    69
      val () = Print.trace Active.pp "Resolution.iterate: active" active
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    70
      val () = Print.trace Waiting.pp "Resolution.iterate: waiting" waiting
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    71
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    72
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    73
      case Waiting.remove waiting of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    74
        NONE =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    75
        Decided (Satisfiable (map Clause.thm (Active.saturation active)))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    76
      | SOME ((d,cl),waiting) =>
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    77
        if Clause.isContradiction cl then
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    78
          Decided (Contradiction (Clause.thm cl))
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    79
        else
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    80
          let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    81
(*MetisTrace1
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    82
            val () = Print.trace Clause.pp "Resolution.iterate: cl" cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    83
*)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    84
            val (active,cls) = Active.add active cl
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    85
            val waiting = Waiting.add waiting (d,cls)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    86
          in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    87
            Undecided
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    88
              (Resolution
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    89
                 {parameters = parameters, active = active, waiting = waiting})
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
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    92
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    93
fun loop resolution =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    94
    case iterate resolution of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    95
      Decided decision => decision
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    96
    | Undecided resolution => loop resolution;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    97
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    98
end