author  haftmann 
Thu, 18 Nov 2010 17:01:15 +0100  
changeset 40602  91e583511113 
parent 38500  d5477ee35820 
child 41449  7339f0e7c513 
permissions  rwrr 
24584  1 
(* Title: Sequents/modal.ML 
7096  2 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 
3 
Copyright 1992 University of Cambridge 

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  6 
*) 
7 

8 

9 
signature MODAL_PROVER_RULE = 

10 
sig 

11 
val rewrite_rls : thm list 

12 
val safe_rls : thm list 

13 
val unsafe_rls : thm list 

14 
val bound_rls : thm list 

15 
val aside_rls : thm list 

16 
end; 

17 

18 
signature MODAL_PROVER = 

19 
sig 

20 
val rule_tac : thm list > int >tactic 

21 
val step_tac : int > tactic 

22 
val solven_tac : int > int > tactic 

23 
val solve_tac : int > tactic 

24 
end; 

25 

26 
functor Modal_ProverFun (Modal_Rule: MODAL_PROVER_RULE) : MODAL_PROVER = 

27 
struct 

28 
local open Modal_Rule 

29 
in 

30 

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

38500  32 
fun forms_of_seq (Const(@{const_name SeqO'},_) $ P $ u) = P :: forms_of_seq u 
7096  33 
 forms_of_seq (H $ u) = forms_of_seq u 
34 
 forms_of_seq _ = []; 

35 

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

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

38 
Assumes each formula in seqc is surrounded by sequence variables 

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

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  42 
(forms_of_seq seqp)) 
43 
(forms_of_seq seqc); 

44 

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

46 
fun could_resolve_seq (prem,conc) = 

47 
case (prem,conc) of 

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

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

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

51 
 _ => false; 

52 

53 
(*Like filt_resolve_tac, using could_resolve_seq 

54 
Much faster than resolve_tac when there are many rules. 

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

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

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

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

59 
end); 

60 

61 
fun fresolve_tac rls n = filseq_resolve_tac rls 999 n; 

62 

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

64 

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

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

67 

68 
val fres_safe_tac = fresolve_tac safe_rls; 

69 
val fres_unsafe_tac = fresolve_tac unsafe_rls THEN' aside_tac; 

70 
val fres_bound_tac = fresolve_tac bound_rls; 

71 

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

73 
else tf(i) THEN tac(i1) 

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

75 

76 
(* Depth first search bounded by d *) 

77 
fun solven_tac d n state = state > 

78 
(if d<0 then no_tac 

79 
else if (nprems_of state = 0) then all_tac 

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

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

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

83 

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

85 

86 
fun step_tac n = 

87 
COND (has_fewer_prems 1) all_tac 

88 
(DETERM(fres_safe_tac n) ORELSE 

32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tabwidth;
wenzelm
parents:
29269
diff
changeset

89 
(fres_unsafe_tac n APPEND fres_bound_tac n)); 
7096  90 

91 
end; 

92 
end; 