src/Sequents/modal.ML
author paulson
Tue Jul 27 19:00:55 1999 +0200 (1999-07-27)
changeset 7096 8c9278991d9c
child 24584 01e83ffa6c54
permissions -rw-r--r--
split off modal.ML from provers.ML
paulson@7096
     1
(*  Title:      LK/modal.ML
paulson@7096
     2
    ID:         $Id$
paulson@7096
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@7096
     4
    Copyright   1992  University of Cambridge
paulson@7096
     5
paulson@7096
     6
Simple modal reasoner
paulson@7096
     7
*)
paulson@7096
     8
paulson@7096
     9
paulson@7096
    10
signature MODAL_PROVER_RULE =
paulson@7096
    11
sig
paulson@7096
    12
    val rewrite_rls      : thm list
paulson@7096
    13
    val safe_rls         : thm list
paulson@7096
    14
    val unsafe_rls       : thm list
paulson@7096
    15
    val bound_rls        : thm list
paulson@7096
    16
    val aside_rls        : thm list
paulson@7096
    17
end;
paulson@7096
    18
paulson@7096
    19
signature MODAL_PROVER = 
paulson@7096
    20
sig
paulson@7096
    21
    val rule_tac   : thm list -> int ->tactic
paulson@7096
    22
    val step_tac   : int -> tactic
paulson@7096
    23
    val solven_tac : int -> int -> tactic
paulson@7096
    24
    val solve_tac  : int -> tactic
paulson@7096
    25
end;
paulson@7096
    26
paulson@7096
    27
functor Modal_ProverFun (Modal_Rule: MODAL_PROVER_RULE) : MODAL_PROVER = 
paulson@7096
    28
struct
paulson@7096
    29
local open Modal_Rule
paulson@7096
    30
in 
paulson@7096
    31
paulson@7096
    32
(*Returns the list of all formulas in the sequent*)
paulson@7096
    33
fun forms_of_seq (Const("SeqO",_) $ P $ u) = P :: forms_of_seq u
paulson@7096
    34
  | forms_of_seq (H $ u) = forms_of_seq u
paulson@7096
    35
  | forms_of_seq _ = [];
paulson@7096
    36
paulson@7096
    37
(*Tests whether two sequences (left or right sides) could be resolved.
paulson@7096
    38
  seqp is a premise (subgoal), seqc is a conclusion of an object-rule.
paulson@7096
    39
  Assumes each formula in seqc is surrounded by sequence variables
paulson@7096
    40
  -- checks that each concl formula looks like some subgoal formula.*)
paulson@7096
    41
fun could_res (seqp,seqc) =
paulson@7096
    42
      forall (fn Qc => exists (fn Qp => could_unify (Qp,Qc)) 
paulson@7096
    43
                              (forms_of_seq seqp))
paulson@7096
    44
             (forms_of_seq seqc);
paulson@7096
    45
paulson@7096
    46
(*Tests whether two sequents G|-H could be resolved, comparing each side.*)
paulson@7096
    47
fun could_resolve_seq (prem,conc) =
paulson@7096
    48
  case (prem,conc) of
paulson@7096
    49
      (_ $ Abs(_,_,leftp) $ Abs(_,_,rightp),
paulson@7096
    50
       _ $ Abs(_,_,leftc) $ Abs(_,_,rightc)) =>
paulson@7096
    51
          could_res (leftp,leftc)  andalso  could_res (rightp,rightc)
paulson@7096
    52
    | _ => false;
paulson@7096
    53
paulson@7096
    54
(*Like filt_resolve_tac, using could_resolve_seq
paulson@7096
    55
  Much faster than resolve_tac when there are many rules.
paulson@7096
    56
  Resolve subgoal i using the rules, unless more than maxr are compatible. *)
paulson@7096
    57
fun filseq_resolve_tac rules maxr = SUBGOAL(fn (prem,i) =>
paulson@7096
    58
  let val rls = filter_thms could_resolve_seq (maxr+1, prem, rules)
paulson@7096
    59
  in  if length rls > maxr  then  no_tac  else resolve_tac rls i
paulson@7096
    60
  end);
paulson@7096
    61
paulson@7096
    62
fun fresolve_tac rls n = filseq_resolve_tac rls 999 n;
paulson@7096
    63
paulson@7096
    64
(* NB No back tracking possible with aside rules *)
paulson@7096
    65
paulson@7096
    66
fun aside_tac n = DETERM(REPEAT (filt_resolve_tac aside_rls 999 n));
paulson@7096
    67
fun rule_tac rls n = fresolve_tac rls n THEN aside_tac n;
paulson@7096
    68
paulson@7096
    69
val fres_safe_tac = fresolve_tac safe_rls;
paulson@7096
    70
val fres_unsafe_tac = fresolve_tac unsafe_rls THEN' aside_tac;
paulson@7096
    71
val fres_bound_tac = fresolve_tac bound_rls;
paulson@7096
    72
paulson@7096
    73
fun UPTOGOAL n tf = let fun tac i = if i<n then all_tac
paulson@7096
    74
                                    else tf(i) THEN tac(i-1)
paulson@7096
    75
                    in fn st => tac (nprems_of st) st end;
paulson@7096
    76
paulson@7096
    77
(* Depth first search bounded by d *)
paulson@7096
    78
fun solven_tac d n state = state |>
paulson@7096
    79
       (if d<0 then no_tac
paulson@7096
    80
        else if (nprems_of state = 0) then all_tac 
paulson@7096
    81
        else (DETERM(fres_safe_tac n) THEN UPTOGOAL n (solven_tac d)) ORELSE
paulson@7096
    82
                 ((fres_unsafe_tac n  THEN UPTOGOAL n (solven_tac d)) APPEND
paulson@7096
    83
                   (fres_bound_tac n  THEN UPTOGOAL n (solven_tac (d-1)))));
paulson@7096
    84
paulson@7096
    85
fun solve_tac d = rewrite_goals_tac rewrite_rls THEN solven_tac d 1;
paulson@7096
    86
paulson@7096
    87
fun step_tac n = 
paulson@7096
    88
    COND (has_fewer_prems 1) all_tac 
paulson@7096
    89
         (DETERM(fres_safe_tac n) ORELSE 
paulson@7096
    90
	  (fres_unsafe_tac n APPEND fres_bound_tac n));
paulson@7096
    91
paulson@7096
    92
end;
paulson@7096
    93
end;