src/FOL/simpdata.ML
author wenzelm
Sun Nov 09 17:04:14 2014 +0100 (2014-11-09)
changeset 58957 c9e744ea8a38
parent 58838 59203adfc33f
child 58963 26bf09b95dda
permissions -rw-r--r--
proper context for match_tac etc.;
wenzelm@9889
     1
(*  Title:      FOL/simpdata.ML
clasohm@1459
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
lcp@282
     3
    Copyright   1994  University of Cambridge
clasohm@0
     4
wenzelm@9889
     5
Simplification data for FOL.
clasohm@0
     6
*)
clasohm@0
     7
lcp@282
     8
(*Make meta-equalities.  The operator below is Trueprop*)
oheimb@5555
     9
lcp@282
    10
fun mk_meta_eq th = case concl_of th of
wenzelm@41310
    11
    _ $ (Const(@{const_name eq},_)$_$_)   => th RS @{thm eq_reflection}
wenzelm@41310
    12
  | _ $ (Const(@{const_name iff},_)$_$_) => th RS @{thm iff_reflection}
wenzelm@10431
    13
  | _                           =>
oheimb@5555
    14
  error("conclusion must be a =-equality or <->");;
oheimb@5555
    15
oheimb@5555
    16
fun mk_eq th = case concl_of th of
wenzelm@56245
    17
    Const(@{const_name Pure.eq},_)$_$_ => th
wenzelm@41310
    18
  | _ $ (Const(@{const_name eq},_)$_$_)   => mk_meta_eq th
wenzelm@41310
    19
  | _ $ (Const(@{const_name iff},_)$_$_) => mk_meta_eq th
haftmann@38500
    20
  | _ $ (Const(@{const_name Not},_)$_)      => th RS @{thm iff_reflection_F}
wenzelm@26288
    21
  | _                           => th RS @{thm iff_reflection_T};
clasohm@0
    22
paulson@6114
    23
(*Replace premises x=y, X<->Y by X==Y*)
wenzelm@36546
    24
fun mk_meta_prems ctxt =
wenzelm@36546
    25
    rule_by_tactic ctxt
wenzelm@26288
    26
      (REPEAT_FIRST (resolve_tac [@{thm meta_eq_to_obj_eq}, @{thm def_imp_iff}]));
paulson@6114
    27
wenzelm@9713
    28
(*Congruence rules for = or <-> (instead of ==)*)
wenzelm@51717
    29
fun mk_meta_cong ctxt rl =
wenzelm@51717
    30
  Drule.zero_var_indexes (mk_meta_eq (mk_meta_prems ctxt rl))
wenzelm@35021
    31
    handle THM _ =>
wenzelm@35021
    32
      error("Premises and conclusion of congruence rules must use =-equality or <->");
oheimb@5555
    33
oheimb@5304
    34
val mksimps_pairs =
wenzelm@41310
    35
  [(@{const_name imp}, [@{thm mp}]), (@{const_name conj}, [@{thm conjunct1}, @{thm conjunct2}]),
haftmann@38500
    36
   (@{const_name All}, [@{thm spec}]), (@{const_name True}, []), (@{const_name False}, [])];
oheimb@5304
    37
oheimb@5304
    38
fun mk_atomize pairs =
oheimb@5304
    39
  let fun atoms th =
oheimb@5304
    40
        (case concl_of th of
haftmann@38500
    41
           Const(@{const_name Trueprop},_) $ p =>
oheimb@5304
    42
             (case head_of p of
oheimb@5304
    43
                Const(a,_) =>
haftmann@17325
    44
                  (case AList.lookup (op =) pairs a of
wenzelm@32952
    45
                     SOME(rls) => maps atoms ([th] RL rls)
skalberg@15531
    46
                   | NONE => [th])
oheimb@5304
    47
              | _ => [th])
oheimb@5304
    48
         | _ => [th])
oheimb@5304
    49
  in atoms end;
oheimb@5304
    50
wenzelm@51717
    51
fun mksimps pairs (_: Proof.context) = map mk_eq o mk_atomize pairs o gen_all;
lcp@981
    52
paulson@1914
    53
paulson@4349
    54
(** make simplification procedures for quantifier elimination **)
wenzelm@42458
    55
structure Quantifier1 = Quantifier1
wenzelm@42458
    56
(
paulson@4349
    57
  (*abstract syntax*)
wenzelm@42460
    58
  fun dest_eq (Const (@{const_name eq}, _) $ s $ t) = SOME (s, t)
wenzelm@42460
    59
    | dest_eq _ = NONE
wenzelm@42460
    60
  fun dest_conj (Const (@{const_name conj}, _) $ s $ t) = SOME (s, t)
wenzelm@42460
    61
    | dest_conj _ = NONE
wenzelm@42460
    62
  fun dest_imp (Const (@{const_name imp}, _) $ s $ t) = SOME (s, t)
wenzelm@42460
    63
    | dest_imp _ = NONE
paulson@4349
    64
  val conj = FOLogic.conj
paulson@4349
    65
  val imp  = FOLogic.imp
paulson@4349
    66
  (*rules*)
wenzelm@26288
    67
  val iff_reflection = @{thm iff_reflection}
wenzelm@26288
    68
  val iffI = @{thm iffI}
wenzelm@26288
    69
  val iff_trans = @{thm iff_trans}
wenzelm@26288
    70
  val conjI= @{thm conjI}
wenzelm@26288
    71
  val conjE= @{thm conjE}
wenzelm@26288
    72
  val impI = @{thm impI}
wenzelm@26288
    73
  val mp   = @{thm mp}
wenzelm@26288
    74
  val uncurry = @{thm uncurry}
wenzelm@26288
    75
  val exI  = @{thm exI}
wenzelm@26288
    76
  val exE  = @{thm exE}
wenzelm@26288
    77
  val iff_allI = @{thm iff_allI}
wenzelm@26288
    78
  val iff_exI = @{thm iff_exI}
wenzelm@26288
    79
  val all_comm = @{thm all_comm}
wenzelm@26288
    80
  val ex_comm = @{thm ex_comm}
wenzelm@42458
    81
);
paulson@4349
    82
paulson@4349
    83
paulson@4349
    84
(*** Case splitting ***)
clasohm@0
    85
wenzelm@32177
    86
structure Splitter = Splitter
wenzelm@32177
    87
(
wenzelm@32177
    88
  val thy = @{theory}
wenzelm@32177
    89
  val mk_eq = mk_eq
wenzelm@26288
    90
  val meta_eq_to_iff = @{thm meta_eq_to_iff}
wenzelm@32177
    91
  val iffD = @{thm iffD2}
wenzelm@32177
    92
  val disjE = @{thm disjE}
wenzelm@32177
    93
  val conjE = @{thm conjE}
wenzelm@32177
    94
  val exE = @{thm exE}
wenzelm@32177
    95
  val contrapos = @{thm contrapos}
wenzelm@32177
    96
  val contrapos2 = @{thm contrapos2}
wenzelm@32177
    97
  val notnotD = @{thm notnotD}
wenzelm@32177
    98
);
berghofe@1722
    99
wenzelm@32177
   100
val split_tac = Splitter.split_tac;
oheimb@5304
   101
val split_inside_tac = Splitter.split_inside_tac;
wenzelm@32177
   102
val split_asm_tac = Splitter.split_asm_tac;
paulson@4325
   103
paulson@4325
   104
paulson@2074
   105
(*** Standard simpsets ***)
paulson@2074
   106
wenzelm@26288
   107
val triv_rls = [@{thm TrueI}, @{thm refl}, reflexive_thm, @{thm iff_refl}, @{thm notFalseI}];
paulson@2074
   108
wenzelm@51717
   109
fun unsafe_solver ctxt =
wenzelm@58838
   110
  FIRST' [resolve_tac (triv_rls @ Simplifier.prems_of ctxt),
wenzelm@58838
   111
    assume_tac,
wenzelm@58838
   112
    eresolve_tac @{thms FalseE}];
wenzelm@43597
   113
oheimb@2633
   114
(*No premature instantiation of variables during simplification*)
wenzelm@51717
   115
fun safe_solver ctxt =
wenzelm@58957
   116
  FIRST' [match_tac ctxt (triv_rls @ Simplifier.prems_of ctxt),
wenzelm@58957
   117
    eq_assume_tac, ematch_tac ctxt @{thms FalseE}];
oheimb@2633
   118
paulson@3910
   119
(*No simprules, but basic infastructure for simplification*)
wenzelm@17892
   120
val FOL_basic_ss =
wenzelm@51717
   121
  empty_simpset @{context}
wenzelm@10431
   122
  setSSolver (mk_solver "FOL safe" safe_solver)
wenzelm@10431
   123
  setSolver (mk_solver "FOL unsafe" unsafe_solver)
wenzelm@45625
   124
  |> Simplifier.set_subgoaler asm_simp_tac
wenzelm@45625
   125
  |> Simplifier.set_mksimps (mksimps mksimps_pairs)
wenzelm@51717
   126
  |> Simplifier.set_mkcong mk_meta_cong
wenzelm@51717
   127
  |> simpset_of;
oheimb@5304
   128
wenzelm@54998
   129
fun unfold_tac ctxt ths =
wenzelm@51717
   130
  ALLGOALS (full_simp_tac (clear_simpset (put_simpset FOL_basic_ss ctxt) addsimps ths));
wenzelm@17002
   131
oheimb@2633
   132
wenzelm@5219
   133
(*** integration of simplifier with classical reasoner ***)
oheimb@2633
   134
wenzelm@42478
   135
structure Clasimp = Clasimp
wenzelm@42478
   136
(
wenzelm@42478
   137
  structure Simplifier = Simplifier
wenzelm@42478
   138
    and Splitter = Splitter
wenzelm@42478
   139
    and Classical = Cla
wenzelm@42478
   140
    and Blast = Blast
wenzelm@42478
   141
  val iffD1 = @{thm iffD1}
wenzelm@42478
   142
  val iffD2 = @{thm iffD2}
wenzelm@42478
   143
  val notE = @{thm notE}
wenzelm@42478
   144
);
oheimb@4652
   145
open Clasimp;
oheimb@2633
   146