src/Sequents/prover.ML
changeset 7097 5ab37ed3d53c
parent 6054 4a4f6ad607a1
child 7122 87b233b31889
     1.1 --- a/src/Sequents/prover.ML	Tue Jul 27 19:00:55 1999 +0200
     1.2 +++ b/src/Sequents/prover.ML	Tue Jul 27 19:01:46 1999 +0200
     1.3 @@ -2,12 +2,14 @@
     1.4      ID:         $Id$
     1.5      Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     1.6      Copyright   1992  University of Cambridge
     1.7 +
     1.8 +Simple classical reasoner for the sequent calculus, based on "theorem packs"
     1.9  *)
    1.10  
    1.11  
    1.12 -(**** Theorem Packs ****)
    1.13  
    1.14 -(* based largely on LK *)
    1.15 +(*Higher precedence than := facilitates use of references*)
    1.16 +infix 4 add_safes add_unsafes;
    1.17  
    1.18  datatype pack = Pack of thm list * thm list;
    1.19  
    1.20 @@ -19,17 +21,37 @@
    1.21  
    1.22  val empty_pack = Pack([],[]);
    1.23  
    1.24 -infix 4 add_safes add_unsafes;
    1.25 +fun warn_duplicates [] = []
    1.26 +  | warn_duplicates dups =
    1.27 +      (warning (String.concat ("Ignoring duplicate theorems:\n"::
    1.28 +			       map (suffix "\n" o string_of_thm) dups));
    1.29 +       dups);
    1.30  
    1.31  fun (Pack(safes,unsafes)) add_safes ths   = 
    1.32 -    Pack(sort (make_ord less) (ths@safes), unsafes);
    1.33 +    let val dups = warn_duplicates (gen_inter eq_thm (ths,safes))
    1.34 +	val ths' = gen_rems eq_thm (ths,dups)
    1.35 +    in
    1.36 +        Pack(sort (make_ord less) (ths'@safes), unsafes)
    1.37 +    end;
    1.38  
    1.39  fun (Pack(safes,unsafes)) add_unsafes ths = 
    1.40 -    Pack(safes, sort (make_ord less) (ths@unsafes));
    1.41 +    let val dups = warn_duplicates (gen_inter eq_thm (ths,unsafes))
    1.42 +	val ths' = gen_rems eq_thm (ths,dups)
    1.43 +    in
    1.44 +	Pack(safes, sort (make_ord less) (ths'@unsafes))
    1.45 +    end;
    1.46 +
    1.47 +fun merge_pack (Pack(safes,unsafes), Pack(safes',unsafes')) =
    1.48 +        Pack(sort (make_ord less) (safes@safes'), 
    1.49 +	     sort (make_ord less) (unsafes@unsafes'));
    1.50  
    1.51  
    1.52 +fun print_pack (Pack(safes,unsafes)) =
    1.53 +    (writeln "Safe rules:";  print_thms safes;
    1.54 +     writeln "Unsafe rules:"; print_thms unsafes);
    1.55 +
    1.56  (*Returns the list of all formulas in the sequent*)
    1.57 -fun forms_of_seq (Const("Sequents.SeqO'",_) $ P $ u) = P :: forms_of_seq u
    1.58 +fun forms_of_seq (Const("SeqO'",_) $ P $ u) = P :: forms_of_seq u
    1.59    | forms_of_seq (H $ u) = forms_of_seq u
    1.60    | forms_of_seq _ = [];
    1.61  
    1.62 @@ -112,11 +134,13 @@
    1.63  
    1.64  
    1.65  (*Tries safe rules only*)
    1.66 -fun safe_goal_tac (Pack(safes,unsafes)) = reresolve_tac safes;
    1.67 +fun safe_tac (Pack(safes,unsafes)) = reresolve_tac safes;
    1.68 +
    1.69 +val safe_goal_tac = safe_tac;   (*backwards compatibility*)
    1.70  
    1.71  (*Tries a safe rule or else a unsafe rule.  Single-step for tracing. *)
    1.72  fun step_tac (thm_pack as Pack(safes,unsafes)) =
    1.73 -    safe_goal_tac thm_pack  ORELSE'
    1.74 +    safe_tac thm_pack  ORELSE'
    1.75      filseq_resolve_tac unsafes 9999;
    1.76  
    1.77  
    1.78 @@ -138,87 +162,38 @@
    1.79  
    1.80  
    1.81  
    1.82 -signature MODAL_PROVER_RULE =
    1.83 -sig
    1.84 -    val rewrite_rls      : thm list
    1.85 -    val safe_rls         : thm list
    1.86 -    val unsafe_rls       : thm list
    1.87 -    val bound_rls        : thm list
    1.88 -    val aside_rls        : thm list
    1.89 -end;
    1.90 -
    1.91 -signature MODAL_PROVER = 
    1.92 -sig
    1.93 -    val rule_tac   : thm list -> int ->tactic
    1.94 -    val step_tac   : int -> tactic
    1.95 -    val solven_tac : int -> int -> tactic
    1.96 -    val solve_tac  : int -> tactic
    1.97 -end;
    1.98 +structure ProverArgs =
    1.99 +  struct
   1.100 +  val name = "Sequents/prover";
   1.101 +  type T = pack ref;
   1.102 +  val empty = ref empty_pack
   1.103 +  fun copy (ref pack) = ref pack;
   1.104 +  val prep_ext = copy;
   1.105 +  fun merge (ref pack1, ref pack2) = ref (merge_pack (pack1, pack2));
   1.106 +  fun print _ (ref pack) = print_pack pack;
   1.107 +  end;
   1.108  
   1.109 -functor Modal_ProverFun (Modal_Rule: MODAL_PROVER_RULE) : MODAL_PROVER = 
   1.110 -struct
   1.111 -local open Modal_Rule
   1.112 -in 
   1.113 +structure ProverData = TheoryDataFun(ProverArgs);
   1.114  
   1.115 -(*Returns the list of all formulas in the sequent*)
   1.116 -fun forms_of_seq (Const("Sequents.SeqO",_) $ P $ u) = P :: forms_of_seq u
   1.117 -  | forms_of_seq (H $ u) = forms_of_seq u
   1.118 -  | forms_of_seq _ = [];
   1.119 -
   1.120 -(*Tests whether two sequences (left or right sides) could be resolved.
   1.121 -  seqp is a premise (subgoal), seqc is a conclusion of an object-rule.
   1.122 -  Assumes each formula in seqc is surrounded by sequence variables
   1.123 -  -- checks that each concl formula looks like some subgoal formula.*)
   1.124 -fun could_res (seqp,seqc) =
   1.125 -      forall (fn Qc => exists (fn Qp => could_unify (Qp,Qc)) 
   1.126 -                              (forms_of_seq seqp))
   1.127 -             (forms_of_seq seqc);
   1.128 +val prover_setup = [ProverData.init];
   1.129  
   1.130 -(*Tests whether two sequents G|-H could be resolved, comparing each side.*)
   1.131 -fun could_resolve_seq (prem,conc) =
   1.132 -  case (prem,conc) of
   1.133 -      (_ $ Abs(_,_,leftp) $ Abs(_,_,rightp),
   1.134 -       _ $ Abs(_,_,leftc) $ Abs(_,_,rightc)) =>
   1.135 -          could_res (leftp,leftc)  andalso  could_res (rightp,rightc)
   1.136 -    | _ => false;
   1.137 +val print_thm_pack = ProverData.print;
   1.138 +val thm_pack_ref_of_sg = ProverData.get_sg;
   1.139 +val thm_pack_ref_of = ProverData.get;
   1.140  
   1.141 -(*Like filt_resolve_tac, using could_resolve_seq
   1.142 -  Much faster than resolve_tac when there are many rules.
   1.143 -  Resolve subgoal i using the rules, unless more than maxr are compatible. *)
   1.144 -fun filseq_resolve_tac rules maxr = SUBGOAL(fn (prem,i) =>
   1.145 -  let val rls = filter_thms could_resolve_seq (maxr+1, prem, rules)
   1.146 -  in  if length rls > maxr  then  no_tac  else resolve_tac rls i
   1.147 -  end);
   1.148 +(* access global thm_pack *)
   1.149  
   1.150 -fun fresolve_tac rls n = filseq_resolve_tac rls 999 n;
   1.151 -
   1.152 -(* NB No back tracking possible with aside rules *)
   1.153 -
   1.154 -fun aside_tac n = DETERM(REPEAT (filt_resolve_tac aside_rls 999 n));
   1.155 -fun rule_tac rls n = fresolve_tac rls n THEN aside_tac n;
   1.156 +val thm_pack_of_sg = ! o thm_pack_ref_of_sg;
   1.157 +val thm_pack_of = thm_pack_of_sg o sign_of;
   1.158  
   1.159 -val fres_safe_tac = fresolve_tac safe_rls;
   1.160 -val fres_unsafe_tac = fresolve_tac unsafe_rls THEN' aside_tac;
   1.161 -val fres_bound_tac = fresolve_tac bound_rls;
   1.162 +val thm_pack = thm_pack_of o Context.the_context;
   1.163 +val thm_pack_ref = thm_pack_ref_of_sg o sign_of o Context.the_context;
   1.164  
   1.165 -fun UPTOGOAL n tf = let fun tac i = if i<n then all_tac
   1.166 -                                    else tf(i) THEN tac(i-1)
   1.167 -                    in fn st => tac (nprems_of st) st end;
   1.168 +
   1.169 +(* change global thm_pack *)
   1.170  
   1.171 -(* Depth first search bounded by d *)
   1.172 -fun solven_tac d n state = state |>
   1.173 -       (if d<0 then no_tac
   1.174 -        else if (nprems_of state = 0) then all_tac 
   1.175 -        else (DETERM(fres_safe_tac n) THEN UPTOGOAL n (solven_tac d)) ORELSE
   1.176 -                 ((fres_unsafe_tac n  THEN UPTOGOAL n (solven_tac d)) APPEND
   1.177 -                   (fres_bound_tac n  THEN UPTOGOAL n (solven_tac (d-1)))));
   1.178 +fun change_thm_pack f x = thm_pack_ref () := (f (thm_pack (), x));
   1.179  
   1.180 -fun solve_tac d = rewrite_goals_tac rewrite_rls THEN solven_tac d 1;
   1.181 +val Add_safes = change_thm_pack (op add_safes);
   1.182 +val Add_unsafes = change_thm_pack (op add_unsafes);
   1.183  
   1.184 -fun step_tac n = 
   1.185 -    COND (has_fewer_prems 1) all_tac 
   1.186 -         (DETERM(fres_safe_tac n) ORELSE 
   1.187 -	  (fres_unsafe_tac n APPEND fres_bound_tac n));
   1.188 -
   1.189 -end;
   1.190 -end;