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