src/Provers/classical.ML
author lcp
Fri, 25 Nov 1994 10:43:50 +0100
changeset 747 bdc066781063
parent 681 9b02474744ca
child 982 4fe0b642b7d5
permissions -rw-r--r--
deepen_tac: modified due to outcome of experiments. Its choice of unsafe rule to expand is still non-deterministic.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     1
(*  Title: 	Provers/classical
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1992  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
Theorem prover for classical reasoning, including predicate calculus, set
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
theory, etc.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
Rules must be classified as intr, elim, safe, hazardous.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
A rule is unsafe unless it can be applied blindly without harmful results.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
For a rule to be safe, its premises and conclusion should be logically
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
equivalent.  There should be no variables in the premises that are not in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
the conclusion.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
signature CLASSICAL_DATA =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
  sig
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    19
  val mp	: thm    	(* [| P-->Q;  P |] ==> Q *)
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    20
  val not_elim	: thm		(* [| ~P;  P |] ==> R *)
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    21
  val classical	: thm		(* (~P ==> P) ==> P *)
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    22
  val sizef 	: thm -> int	(* size function for BEST_FIRST *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
  val hyp_subst_tacs: (int -> tactic) list
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
(*Higher precedence than := facilitates use of references*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
infix 4 addSIs addSEs addSDs addIs addEs addDs;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
signature CLASSICAL =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
  sig
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
  type claset
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    33
  val empty_cs		: claset
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    34
  val addDs 		: claset * thm list -> claset
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    35
  val addEs 		: claset * thm list -> claset
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    36
  val addIs 		: claset * thm list -> claset
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    37
  val addSDs		: claset * thm list -> claset
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    38
  val addSEs		: claset * thm list -> claset
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    39
  val addSIs		: claset * thm list -> claset
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    40
  val print_cs		: claset -> unit
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    41
  val rep_claset	: claset -> {safeIs: thm list, safeEs: thm list, 
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    42
				     hazIs: thm list, hazEs: thm list}
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    43
  val best_tac 		: claset -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    44
  val contr_tac 	: int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    45
  val depth_tac		: claset -> int -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    46
  val deepen_tac	: claset -> int -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    47
  val dup_elim		: thm -> thm
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    48
  val dup_intr		: thm -> thm
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    49
  val dup_step_tac	: claset -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    50
  val eq_mp_tac		: int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    51
  val fast_tac 		: claset -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    52
  val haz_step_tac 	: claset -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    53
  val joinrules 	: thm list * thm list -> (bool * thm) list
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    54
  val mp_tac		: int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    55
  val safe_tac 		: claset -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    56
  val safe_step_tac 	: claset -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    57
  val slow_step_tac 	: claset -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    58
  val slow_best_tac 	: claset -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    59
  val slow_tac 		: claset -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    60
  val step_tac 		: claset -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    61
  val swap		: thm                 (* ~P ==> (~Q ==> P) ==> Q *)
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    62
  val swapify 		: thm list -> thm list
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    63
  val swap_res_tac 	: thm list -> int -> tactic
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    64
  val inst_step_tac 	: claset -> int -> tactic
747
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
    65
  val inst0_step_tac 	: claset -> int -> tactic
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
    66
  val instp_step_tac 	: claset -> int -> tactic
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
functor ClassicalFun(Data: CLASSICAL_DATA): CLASSICAL = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    73
local open Data in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
(** Useful tactics for classical reasoning **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
val imp_elim = make_elim mp;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
(*Solve goal that assumes both P and ~P. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
val contr_tac = eresolve_tac [not_elim]  THEN'  assume_tac;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    82
(*Finds P-->Q and P in the assumptions, replaces implication by Q.
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    83
  Could do the same thing for P<->Q and P... *)
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    84
fun mp_tac i = eresolve_tac [not_elim, imp_elim] i  THEN  assume_tac i;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    85
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
(*Like mp_tac but instantiates no variables*)
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    87
fun eq_mp_tac i = ematch_tac [not_elim, imp_elim] i  THEN  eq_assume_tac i;
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    88
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
    89
val swap = rule_by_tactic (etac thin_rl 1) (not_elim RS classical);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
(*Creates rules to eliminate ~A, from rules to introduce A*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    92
fun swapify intrs = intrs RLN (2, [swap]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    93
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    94
(*Uses introduction rules in the normal way, or on negated assumptions,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    95
  trying rules in order. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    96
fun swap_res_tac rls = 
54
3dea30013b58 classical/swap_res_tac: recoded to allow backtracking
lcp
parents: 0
diff changeset
    97
    let fun addrl (rl,brls) = (false, rl) :: (true, rl RSN (2,swap)) :: brls
3dea30013b58 classical/swap_res_tac: recoded to allow backtracking
lcp
parents: 0
diff changeset
    98
    in  assume_tac 	ORELSE' 
3dea30013b58 classical/swap_res_tac: recoded to allow backtracking
lcp
parents: 0
diff changeset
    99
	contr_tac 	ORELSE' 
3dea30013b58 classical/swap_res_tac: recoded to allow backtracking
lcp
parents: 0
diff changeset
   100
        biresolve_tac (foldr addrl (rls,[]))
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   101
    end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   102
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   103
(*Duplication of hazardous rules, for complete provers*)
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   104
fun dup_intr th = standard (th RS classical);
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   105
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   106
fun dup_elim th = th RSN (2, revcut_rl) |> assumption 2 |> Sequence.hd |> 
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   107
                  rule_by_tactic (TRYALL (etac revcut_rl));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   108
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   109
(*** Classical rule sets ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   110
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   111
type netpair = (int*(bool*thm)) Net.net * (int*(bool*thm)) Net.net;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   112
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
datatype claset =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   114
  CS of {safeIs		: thm list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   115
	 safeEs		: thm list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   116
	 hazIs		: thm list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   117
	 hazEs		: thm list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   118
	 safe0_netpair	: netpair,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   119
	 safep_netpair	: netpair,
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   120
	 haz_netpair  	: netpair,
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   121
	 dup_netpair	: netpair};
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   122
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   123
fun rep_claset (CS{safeIs,safeEs,hazIs,hazEs,...}) = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   124
    {safeIs=safeIs, safeEs=safeEs, hazIs=hazIs, hazEs=hazEs};
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   125
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   126
(*For use with biresolve_tac.  Combines intrs with swap to catch negated
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   127
  assumptions; pairs elims with true; sorts. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   128
fun joinrules (intrs,elims) =  
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   129
  sort lessb 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   130
    (map (pair true) (elims @ swapify intrs)  @
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   131
     map (pair false) intrs);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   132
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   133
val build = build_netpair(Net.empty,Net.empty);
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   134
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   135
(*Make a claset from the four kinds of rules*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   136
fun make_cs {safeIs,safeEs,hazIs,hazEs} =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   137
  let val (safe0_brls, safep_brls) = (*0 subgoals vs 1 or more*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   138
          take_prefix (fn brl => subgoals_of_brl brl=0)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   139
             (joinrules(safeIs, safeEs))
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   140
  in CS{safeIs = safeIs, 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   141
        safeEs = safeEs,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   142
	hazIs = hazIs,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   143
	hazEs = hazEs,
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   144
	safe0_netpair = build safe0_brls,
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   145
	safep_netpair = build safep_brls,
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   146
	haz_netpair = build (joinrules(hazIs, hazEs)),
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   147
	dup_netpair = build (joinrules(map dup_intr hazIs, 
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   148
				       map dup_elim hazEs))}
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   149
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   150
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   151
(*** Manipulation of clasets ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   152
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   153
val empty_cs = make_cs{safeIs=[], safeEs=[], hazIs=[], hazEs=[]};
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   154
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   155
fun print_cs (CS{safeIs,safeEs,hazIs,hazEs,...}) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   156
 (writeln"Introduction rules";  prths hazIs;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   157
  writeln"Safe introduction rules";  prths safeIs;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   158
  writeln"Elimination rules";  prths hazEs;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   159
  writeln"Safe elimination rules";  prths safeEs;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   160
  ());
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   161
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   162
fun (CS{safeIs,safeEs,hazIs,hazEs,...}) addSIs ths =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   163
  make_cs {safeIs=ths@safeIs, safeEs=safeEs, hazIs=hazIs, hazEs=hazEs};
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   164
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   165
fun (CS{safeIs,safeEs,hazIs,hazEs,...}) addSEs ths =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   166
  make_cs {safeIs=safeIs, safeEs=ths@safeEs, hazIs=hazIs, hazEs=hazEs};
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   167
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   168
fun cs addSDs ths = cs addSEs (map make_elim ths);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   169
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   170
fun (CS{safeIs,safeEs,hazIs,hazEs,...}) addIs ths =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   171
  make_cs {safeIs=safeIs, safeEs=safeEs, hazIs=ths@hazIs, hazEs=hazEs};
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   172
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   173
fun (CS{safeIs,safeEs,hazIs,hazEs,...}) addEs ths =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   174
  make_cs {safeIs=safeIs, safeEs=safeEs, hazIs=hazIs, hazEs=ths@hazEs};
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   175
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   176
fun cs addDs ths = cs addEs (map make_elim ths);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   177
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   178
(*** Simple tactics for theorem proving ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   179
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   180
(*Attack subgoals using safe inferences -- matching, not resolution*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   181
fun safe_step_tac (CS{safe0_netpair,safep_netpair,...}) = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   182
  FIRST' [eq_assume_tac,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   183
	  eq_mp_tac,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   184
	  bimatch_from_nets_tac safe0_netpair,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   185
	  FIRST' hyp_subst_tacs,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   186
	  bimatch_from_nets_tac safep_netpair] ;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   187
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   188
(*Repeatedly attack subgoals using safe inferences -- it's deterministic!*)
747
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   189
fun safe_tac cs = REPEAT_DETERM_FIRST (safe_step_tac cs);
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   190
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   191
(*But these unsafe steps at least solve a subgoal!*)
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   192
fun inst0_step_tac (CS{safe0_netpair,safep_netpair,...}) =
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   193
  assume_tac 			  APPEND' 
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   194
  contr_tac 			  APPEND' 
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   195
  biresolve_from_nets_tac safe0_netpair;
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   196
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   197
(*These are much worse since they could generate more and more subgoals*)
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   198
fun instp_step_tac (CS{safep_netpair,...}) =
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   199
  biresolve_from_nets_tac safep_netpair;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   200
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   201
(*These steps could instantiate variables and are therefore unsafe.*)
747
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   202
fun inst_step_tac cs = inst0_step_tac cs APPEND' instp_step_tac cs;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   203
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   204
fun haz_step_tac (cs as (CS{haz_netpair,...})) = 
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   205
  biresolve_from_nets_tac haz_netpair;
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   206
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   207
(*Single step for the prover.  FAILS unless it makes progress. *)
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   208
fun step_tac cs i = 
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   209
  FIRST [safe_tac cs, inst_step_tac cs i, haz_step_tac cs i];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   210
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   211
(*Using a "safe" rule to instantiate variables is unsafe.  This tactic
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   212
  allows backtracking from "safe" rules to "unsafe" rules here.*)
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   213
fun slow_step_tac cs i = 
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   214
    safe_tac cs ORELSE (inst_step_tac cs i APPEND haz_step_tac cs i);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   215
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   216
(*** The following tactics all fail unless they solve one goal ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   217
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   218
(*Dumb but fast*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   219
fun fast_tac cs = SELECT_GOAL (DEPTH_SOLVE (step_tac cs 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   220
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   221
(*Slower but smarter than fast_tac*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   222
fun best_tac cs = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   223
  SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, sizef) (step_tac cs 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   224
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   225
fun slow_tac cs = SELECT_GOAL (DEPTH_SOLVE (slow_step_tac cs 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   226
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   227
fun slow_best_tac cs = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   228
  SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, sizef) (slow_step_tac cs 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   229
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   230
747
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   231
(*** Complete tactic, loosely based upon LeanTaP This tactic is the outcome
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   232
  of much experimentation!  Changing APPEND to ORELSE below would prove
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   233
  easy theorems faster, but loses completeness -- and many of the harder
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   234
  theorems such as 43. ***)
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   235
747
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   236
(*Non-deterministic!  Could always expand the first unsafe connective.
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   237
  That's hard to implement and did not perform better in experiments, due to
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   238
  greater search depth required.*)
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   239
fun dup_step_tac (cs as (CS{dup_netpair,...})) = 
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   240
  biresolve_from_nets_tac dup_netpair;
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   241
747
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   242
(*Searching to depth m.*)
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   243
fun depth_tac cs m i = STATE(fn state => 
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   244
  SELECT_GOAL 
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   245
    (REPEAT_DETERM1 (safe_step_tac cs 1) THEN_ELSE
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   246
     (DEPTH_SOLVE (depth_tac cs m 1),
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   247
      inst0_step_tac cs 1  APPEND
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   248
      COND (K(m=0)) no_tac
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   249
        ((instp_step_tac cs 1 APPEND dup_step_tac cs 1)
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   250
	 THEN DEPTH_SOLVE (depth_tac cs (m-1) 1))))
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   251
  i);
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   252
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   253
(*Iterative deepening tactical.  Allows us to "deepen" any search tactic*)
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   254
fun DEEPEN tacf m i = STATE(fn state => 
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   255
   if has_fewer_prems i state then no_tac
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   256
   else (writeln ("Depth = " ^ string_of_int m);
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   257
	 tacf m i  ORELSE  DEEPEN tacf (m+2) i));
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   258
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   259
fun safe_depth_tac cs m = 
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   260
  SUBGOAL 
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   261
    (fn (prem,i) =>
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   262
      let val deti =
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   263
	  (*No Vars in the goal?  No need to backtrack between goals.*)
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   264
	  case term_vars prem of
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   265
	      []	=> DETERM 
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   266
	    | _::_	=> I
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   267
      in  SELECT_GOAL (TRY (safe_tac cs) THEN 
747
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   268
		       DEPTH_SOLVE (deti (depth_tac cs m 1))) i
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   269
      end);
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   270
747
bdc066781063 deepen_tac: modified due to outcome of experiments. Its
lcp
parents: 681
diff changeset
   271
fun deepen_tac cs = DEEPEN (safe_depth_tac cs);
681
9b02474744ca Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents: 469
diff changeset
   272
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   273
end; 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   274
end;