src/FOL/intprover.ML
author wenzelm
Sun Nov 09 17:04:14 2014 +0100 (2014-11-09)
changeset 58957 c9e744ea8a38
parent 51798 ad3a241def73
child 58963 26bf09b95dda
permissions -rw-r--r--
proper context for match_tac etc.;
wenzelm@31974
     1
(*  Title:      FOL/intprover.ML
clasohm@1459
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     3
    Copyright   1992  University of Cambridge
clasohm@0
     4
clasohm@0
     5
A naive prover for intuitionistic logic
clasohm@0
     6
paulson@2601
     7
BEWARE OF NAME CLASHES WITH CLASSICAL TACTICS -- use IntPr.fast_tac ...
clasohm@0
     8
clasohm@0
     9
Completeness (for propositional logic) is proved in 
clasohm@0
    10
clasohm@0
    11
Roy Dyckhoff.
clasohm@0
    12
Contraction-Free Sequent Calculi for Intuitionistic Logic.
lcp@1005
    13
J. Symbolic Logic  57(3), 1992, pages 795-807.
lcp@1005
    14
lcp@1005
    15
The approach was developed independently by Roy Dyckhoff and L C Paulson.
clasohm@0
    16
*)
clasohm@0
    17
clasohm@0
    18
signature INT_PROVER = 
wenzelm@51798
    19
sig
wenzelm@51798
    20
  val best_tac: Proof.context -> int -> tactic
wenzelm@51798
    21
  val best_dup_tac: Proof.context -> int -> tactic
wenzelm@51798
    22
  val fast_tac: Proof.context -> int -> tactic
clasohm@0
    23
  val inst_step_tac: int -> tactic
wenzelm@51798
    24
  val safe_step_tac: Proof.context -> int -> tactic
clasohm@0
    25
  val safe_brls: (bool * thm) list
wenzelm@51798
    26
  val safe_tac: Proof.context -> tactic
wenzelm@51798
    27
  val step_tac: Proof.context -> int -> tactic
wenzelm@51798
    28
  val step_dup_tac: Proof.context -> int -> tactic
clasohm@0
    29
  val haz_brls: (bool * thm) list
paulson@5203
    30
  val haz_dup_brls: (bool * thm) list
wenzelm@51798
    31
end;
clasohm@0
    32
clasohm@0
    33
paulson@2601
    34
structure IntPr : INT_PROVER   = 
clasohm@0
    35
struct
clasohm@0
    36
clasohm@0
    37
(*Negation is treated as a primitive symbol, with rules notI (introduction),
clasohm@0
    38
  not_to_imp (converts the assumption ~P to P-->False), and not_impE
clasohm@0
    39
  (handles double negations).  Could instead rewrite by not_def as the first
clasohm@0
    40
  step of an intuitionistic proof.
clasohm@0
    41
*)
wenzelm@4440
    42
val safe_brls = sort (make_ord lessb)
haftmann@38500
    43
    [ (true, @{thm FalseE}), (false, @{thm TrueI}), (false, @{thm refl}),
haftmann@38500
    44
      (false, @{thm impI}), (false, @{thm notI}), (false, @{thm allI}),
haftmann@38500
    45
      (true, @{thm conjE}), (true, @{thm exE}),
haftmann@38500
    46
      (false, @{thm conjI}), (true, @{thm conj_impE}),
haftmann@38500
    47
      (true, @{thm disj_impE}), (true, @{thm disjE}), 
haftmann@38500
    48
      (false, @{thm iffI}), (true, @{thm iffE}), (true, @{thm not_to_imp}) ];
clasohm@0
    49
clasohm@0
    50
val haz_brls =
haftmann@38500
    51
    [ (false, @{thm disjI1}), (false, @{thm disjI2}), (false, @{thm exI}), 
haftmann@38500
    52
      (true, @{thm allE}), (true, @{thm not_impE}), (true, @{thm imp_impE}), (true, @{thm iff_impE}),
haftmann@38500
    53
      (true, @{thm all_impE}), (true, @{thm ex_impE}), (true, @{thm impE}) ];
clasohm@0
    54
paulson@5203
    55
val haz_dup_brls =
haftmann@38500
    56
    [ (false, @{thm disjI1}), (false, @{thm disjI2}), (false, @{thm exI}),
haftmann@38500
    57
      (true, @{thm all_dupE}), (true, @{thm not_impE}), (true, @{thm imp_impE}), (true, @{thm iff_impE}),
haftmann@38500
    58
      (true, @{thm all_impE}), (true, @{thm ex_impE}), (true, @{thm impE}) ];
paulson@5203
    59
clasohm@0
    60
(*0 subgoals vs 1 or more: the p in safep is for positive*)
clasohm@0
    61
val (safe0_brls, safep_brls) =
haftmann@17496
    62
    List.partition (curry (op =) 0 o subgoals_of_brl) safe_brls;
clasohm@0
    63
clasohm@0
    64
(*Attack subgoals using safe inferences -- matching, not resolution*)
wenzelm@51798
    65
fun safe_step_tac ctxt =
wenzelm@51798
    66
  FIRST' [
wenzelm@51798
    67
    eq_assume_tac,
wenzelm@51798
    68
    eq_mp_tac,
wenzelm@58957
    69
    bimatch_tac ctxt safe0_brls,
wenzelm@51798
    70
    hyp_subst_tac ctxt,
wenzelm@58957
    71
    bimatch_tac ctxt safep_brls];
clasohm@0
    72
clasohm@0
    73
(*Repeatedly attack subgoals using safe inferences -- it's deterministic!*)
wenzelm@51798
    74
fun safe_tac ctxt = REPEAT_DETERM_FIRST (safe_step_tac ctxt);
clasohm@0
    75
clasohm@0
    76
(*These steps could instantiate variables and are therefore unsafe.*)
clasohm@0
    77
val inst_step_tac =
clasohm@0
    78
  assume_tac APPEND' mp_tac APPEND' 
clasohm@0
    79
  biresolve_tac (safe0_brls @ safep_brls);
clasohm@0
    80
clasohm@0
    81
(*One safe or unsafe step. *)
wenzelm@51798
    82
fun step_tac ctxt i = FIRST [safe_tac ctxt, inst_step_tac i, biresolve_tac haz_brls i];
clasohm@0
    83
wenzelm@51798
    84
fun step_dup_tac ctxt i = FIRST [safe_tac ctxt, inst_step_tac i, biresolve_tac haz_dup_brls i];
paulson@5203
    85
clasohm@0
    86
(*Dumb but fast*)
wenzelm@51798
    87
fun fast_tac ctxt = SELECT_GOAL (DEPTH_SOLVE (step_tac ctxt 1));
clasohm@0
    88
clasohm@0
    89
(*Slower but smarter than fast_tac*)
wenzelm@51798
    90
fun best_tac ctxt =
wenzelm@51798
    91
  SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, size_of_thm) (step_tac ctxt 1));
clasohm@0
    92
paulson@5203
    93
(*Uses all_dupE: allows multiple use of universal assumptions.  VERY slow.*)
wenzelm@51798
    94
fun best_dup_tac ctxt =
wenzelm@51798
    95
  SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, size_of_thm) (step_dup_tac ctxt 1));
paulson@5203
    96
paulson@5203
    97
clasohm@0
    98
end;
clasohm@0
    99