src/Sequents/modal.ML
 changeset 7096 8c9278991d9c child 24584 01e83ffa6c54
1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/Sequents/modal.ML	Tue Jul 27 19:00:55 1999 +0200
1.3 @@ -0,0 +1,93 @@
1.4 +(*  Title:      LK/modal.ML
1.5 +    ID:         \$Id\$
1.6 +    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
1.7 +    Copyright   1992  University of Cambridge
1.8 +
1.9 +Simple modal reasoner
1.10 +*)
1.11 +
1.12 +
1.13 +signature MODAL_PROVER_RULE =
1.14 +sig
1.15 +    val rewrite_rls      : thm list
1.16 +    val safe_rls         : thm list
1.17 +    val unsafe_rls       : thm list
1.18 +    val bound_rls        : thm list
1.19 +    val aside_rls        : thm list
1.20 +end;
1.21 +
1.22 +signature MODAL_PROVER =
1.23 +sig
1.24 +    val rule_tac   : thm list -> int ->tactic
1.25 +    val step_tac   : int -> tactic
1.26 +    val solven_tac : int -> int -> tactic
1.27 +    val solve_tac  : int -> tactic
1.28 +end;
1.29 +
1.30 +functor Modal_ProverFun (Modal_Rule: MODAL_PROVER_RULE) : MODAL_PROVER =
1.31 +struct
1.32 +local open Modal_Rule
1.33 +in
1.34 +
1.35 +(*Returns the list of all formulas in the sequent*)
1.36 +fun forms_of_seq (Const("SeqO",_) \$ P \$ u) = P :: forms_of_seq u
1.37 +  | forms_of_seq (H \$ u) = forms_of_seq u
1.38 +  | forms_of_seq _ = [];
1.39 +
1.40 +(*Tests whether two sequences (left or right sides) could be resolved.
1.41 +  seqp is a premise (subgoal), seqc is a conclusion of an object-rule.
1.42 +  Assumes each formula in seqc is surrounded by sequence variables
1.43 +  -- checks that each concl formula looks like some subgoal formula.*)
1.44 +fun could_res (seqp,seqc) =
1.45 +      forall (fn Qc => exists (fn Qp => could_unify (Qp,Qc))
1.46 +                              (forms_of_seq seqp))
1.47 +             (forms_of_seq seqc);
1.48 +
1.49 +(*Tests whether two sequents G|-H could be resolved, comparing each side.*)
1.50 +fun could_resolve_seq (prem,conc) =
1.51 +  case (prem,conc) of
1.52 +      (_ \$ Abs(_,_,leftp) \$ Abs(_,_,rightp),
1.53 +       _ \$ Abs(_,_,leftc) \$ Abs(_,_,rightc)) =>
1.54 +          could_res (leftp,leftc)  andalso  could_res (rightp,rightc)
1.55 +    | _ => false;
1.56 +
1.57 +(*Like filt_resolve_tac, using could_resolve_seq
1.58 +  Much faster than resolve_tac when there are many rules.
1.59 +  Resolve subgoal i using the rules, unless more than maxr are compatible. *)
1.60 +fun filseq_resolve_tac rules maxr = SUBGOAL(fn (prem,i) =>
1.61 +  let val rls = filter_thms could_resolve_seq (maxr+1, prem, rules)
1.62 +  in  if length rls > maxr  then  no_tac  else resolve_tac rls i
1.63 +  end);
1.64 +
1.65 +fun fresolve_tac rls n = filseq_resolve_tac rls 999 n;
1.66 +
1.67 +(* NB No back tracking possible with aside rules *)
1.68 +
1.69 +fun aside_tac n = DETERM(REPEAT (filt_resolve_tac aside_rls 999 n));
1.70 +fun rule_tac rls n = fresolve_tac rls n THEN aside_tac n;
1.71 +
1.72 +val fres_safe_tac = fresolve_tac safe_rls;
1.73 +val fres_unsafe_tac = fresolve_tac unsafe_rls THEN' aside_tac;
1.74 +val fres_bound_tac = fresolve_tac bound_rls;
1.75 +
1.76 +fun UPTOGOAL n tf = let fun tac i = if i<n then all_tac
1.77 +                                    else tf(i) THEN tac(i-1)
1.78 +                    in fn st => tac (nprems_of st) st end;
1.79 +
1.80 +(* Depth first search bounded by d *)
1.81 +fun solven_tac d n state = state |>
1.82 +       (if d<0 then no_tac
1.83 +        else if (nprems_of state = 0) then all_tac
1.84 +        else (DETERM(fres_safe_tac n) THEN UPTOGOAL n (solven_tac d)) ORELSE
1.85 +                 ((fres_unsafe_tac n  THEN UPTOGOAL n (solven_tac d)) APPEND
1.86 +                   (fres_bound_tac n  THEN UPTOGOAL n (solven_tac (d-1)))));
1.87 +
1.88 +fun solve_tac d = rewrite_goals_tac rewrite_rls THEN solven_tac d 1;
1.89 +
1.90 +fun step_tac n =
1.91 +    COND (has_fewer_prems 1) all_tac
1.92 +         (DETERM(fres_safe_tac n) ORELSE
1.93 +	  (fres_unsafe_tac n APPEND fres_bound_tac n));
1.94 +
1.95 +end;
1.96 +end;