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