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