24584

1 
(* Title: Sequents/modal.ML

7096

2 
ID: $Id$


3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory


4 
Copyright 1992 University of Cambridge


5 


6 
Simple modal reasoner


7 
*)


8 


9 


10 
signature MODAL_PROVER_RULE =


11 
sig


12 
val rewrite_rls : thm list


13 
val safe_rls : thm list


14 
val unsafe_rls : thm list


15 
val bound_rls : thm list


16 
val aside_rls : thm list


17 
end;


18 


19 
signature MODAL_PROVER =


20 
sig


21 
val rule_tac : thm list > int >tactic


22 
val step_tac : int > tactic


23 
val solven_tac : int > int > tactic


24 
val solve_tac : int > tactic


25 
end;


26 


27 
functor Modal_ProverFun (Modal_Rule: MODAL_PROVER_RULE) : MODAL_PROVER =


28 
struct


29 
local open Modal_Rule


30 
in


31 


32 
(*Returns the list of all formulas in the sequent*)


33 
fun forms_of_seq (Const("SeqO",_) $ P $ u) = P :: forms_of_seq u


34 
 forms_of_seq (H $ u) = forms_of_seq u


35 
 forms_of_seq _ = [];


36 


37 
(*Tests whether two sequences (left or right sides) could be resolved.


38 
seqp is a premise (subgoal), seqc is a conclusion of an objectrule.


39 
Assumes each formula in seqc is surrounded by sequence variables


40 
 checks that each concl formula looks like some subgoal formula.*)


41 
fun could_res (seqp,seqc) =


42 
forall (fn Qc => exists (fn Qp => could_unify (Qp,Qc))


43 
(forms_of_seq seqp))


44 
(forms_of_seq seqc);


45 


46 
(*Tests whether two sequents GH could be resolved, comparing each side.*)


47 
fun could_resolve_seq (prem,conc) =


48 
case (prem,conc) of


49 
(_ $ Abs(_,_,leftp) $ Abs(_,_,rightp),


50 
_ $ Abs(_,_,leftc) $ Abs(_,_,rightc)) =>


51 
could_res (leftp,leftc) andalso could_res (rightp,rightc)


52 
 _ => false;


53 


54 
(*Like filt_resolve_tac, using could_resolve_seq


55 
Much faster than resolve_tac when there are many rules.


56 
Resolve subgoal i using the rules, unless more than maxr are compatible. *)


57 
fun filseq_resolve_tac rules maxr = SUBGOAL(fn (prem,i) =>


58 
let val rls = filter_thms could_resolve_seq (maxr+1, prem, rules)


59 
in if length rls > maxr then no_tac else resolve_tac rls i


60 
end);


61 


62 
fun fresolve_tac rls n = filseq_resolve_tac rls 999 n;


63 


64 
(* NB No back tracking possible with aside rules *)


65 


66 
fun aside_tac n = DETERM(REPEAT (filt_resolve_tac aside_rls 999 n));


67 
fun rule_tac rls n = fresolve_tac rls n THEN aside_tac n;


68 


69 
val fres_safe_tac = fresolve_tac safe_rls;


70 
val fres_unsafe_tac = fresolve_tac unsafe_rls THEN' aside_tac;


71 
val fres_bound_tac = fresolve_tac bound_rls;


72 


73 
fun UPTOGOAL n tf = let fun tac i = if i<n then all_tac


74 
else tf(i) THEN tac(i1)


75 
in fn st => tac (nprems_of st) st end;


76 


77 
(* Depth first search bounded by d *)


78 
fun solven_tac d n state = state >


79 
(if d<0 then no_tac


80 
else if (nprems_of state = 0) then all_tac


81 
else (DETERM(fres_safe_tac n) THEN UPTOGOAL n (solven_tac d)) ORELSE


82 
((fres_unsafe_tac n THEN UPTOGOAL n (solven_tac d)) APPEND


83 
(fres_bound_tac n THEN UPTOGOAL n (solven_tac (d1)))));


84 


85 
fun solve_tac d = rewrite_goals_tac rewrite_rls THEN solven_tac d 1;


86 


87 
fun step_tac n =


88 
COND (has_fewer_prems 1) all_tac


89 
(DETERM(fres_safe_tac n) ORELSE


90 
(fres_unsafe_tac n APPEND fres_bound_tac n));


91 


92 
end;


93 
end;
