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