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