src/FOL/simpdata.ML
author wenzelm
Mon Dec 20 16:44:33 2010 +0100 (2010-12-20)
changeset 41310 65631ca437c9
parent 38715 6513ea67d95d
child 42453 cd5005020f4e
permissions -rw-r--r--
proper identifiers for consts and types;
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
nipkow@394
    17
    Const("==",_)$_$_           => 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@36546
    29
fun mk_meta_cong ss rl =
wenzelm@36546
    30
  Drule.export_without_context (mk_meta_eq (mk_meta_prems (Simplifier.the_context ss) 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@36543
    51
fun mksimps pairs (_: simpset) = 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 **)
paulson@4349
    55
structure Quantifier1 = Quantifier1Fun(
paulson@4349
    56
struct
paulson@4349
    57
  (*abstract syntax*)
wenzelm@41310
    58
  fun dest_eq((c as Const(@{const_name eq},_)) $ s $ t) = SOME(c,s,t)
skalberg@15531
    59
    | dest_eq _ = NONE;
wenzelm@41310
    60
  fun dest_conj((c as Const(@{const_name conj},_)) $ s $ t) = SOME(c,s,t)
skalberg@15531
    61
    | dest_conj _ = NONE;
wenzelm@41310
    62
  fun dest_imp((c as Const(@{const_name imp},_)) $ s $ t) = SOME(c,s,t)
skalberg@15531
    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}
paulson@4349
    81
end);
paulson@4349
    82
wenzelm@13462
    83
val defEX_regroup =
wenzelm@38715
    84
  Simplifier.simproc_global @{theory}
wenzelm@13462
    85
    "defined EX" ["EX x. P(x)"] Quantifier1.rearrange_ex;
paulson@4349
    86
paulson@4349
    87
val defALL_regroup =
wenzelm@38715
    88
  Simplifier.simproc_global @{theory}
wenzelm@13462
    89
    "defined ALL" ["ALL x. P(x)"] Quantifier1.rearrange_all;
paulson@4349
    90
paulson@4349
    91
paulson@4349
    92
(*** Case splitting ***)
clasohm@0
    93
wenzelm@32177
    94
structure Splitter = Splitter
wenzelm@32177
    95
(
wenzelm@32177
    96
  val thy = @{theory}
wenzelm@32177
    97
  val mk_eq = mk_eq
wenzelm@26288
    98
  val meta_eq_to_iff = @{thm meta_eq_to_iff}
wenzelm@32177
    99
  val iffD = @{thm iffD2}
wenzelm@32177
   100
  val disjE = @{thm disjE}
wenzelm@32177
   101
  val conjE = @{thm conjE}
wenzelm@32177
   102
  val exE = @{thm exE}
wenzelm@32177
   103
  val contrapos = @{thm contrapos}
wenzelm@32177
   104
  val contrapos2 = @{thm contrapos2}
wenzelm@32177
   105
  val notnotD = @{thm notnotD}
wenzelm@32177
   106
);
berghofe@1722
   107
wenzelm@32177
   108
val split_tac = Splitter.split_tac;
oheimb@5304
   109
val split_inside_tac = Splitter.split_inside_tac;
wenzelm@32177
   110
val split_asm_tac = Splitter.split_asm_tac;
wenzelm@32177
   111
val op addsplits = Splitter.addsplits;
wenzelm@32177
   112
val op delsplits = Splitter.delsplits;
paulson@4325
   113
paulson@4325
   114
paulson@2074
   115
(*** Standard simpsets ***)
paulson@2074
   116
wenzelm@26288
   117
val triv_rls = [@{thm TrueI}, @{thm refl}, reflexive_thm, @{thm iff_refl}, @{thm notFalseI}];
paulson@2074
   118
wenzelm@26288
   119
fun unsafe_solver prems = FIRST'[resolve_tac (triv_rls @ prems),
wenzelm@26288
   120
                                 atac, etac @{thm FalseE}];
oheimb@2633
   121
(*No premature instantiation of variables during simplification*)
wenzelm@26288
   122
fun   safe_solver prems = FIRST'[match_tac (triv_rls @ prems),
wenzelm@26288
   123
                                 eq_assume_tac, ematch_tac [@{thm FalseE}]];
oheimb@2633
   124
paulson@3910
   125
(*No simprules, but basic infastructure for simplification*)
wenzelm@17892
   126
val FOL_basic_ss =
wenzelm@35232
   127
  Simplifier.global_context @{theory} empty_ss
wenzelm@10431
   128
  setsubgoaler asm_simp_tac
wenzelm@10431
   129
  setSSolver (mk_solver "FOL safe" safe_solver)
wenzelm@10431
   130
  setSolver (mk_solver "FOL unsafe" unsafe_solver)
wenzelm@10431
   131
  setmksimps (mksimps mksimps_pairs)
wenzelm@10431
   132
  setmkcong mk_meta_cong;
oheimb@5304
   133
wenzelm@18324
   134
fun unfold_tac ths =
wenzelm@18324
   135
  let val ss0 = Simplifier.clear_ss FOL_basic_ss addsimps ths
wenzelm@18324
   136
  in fn ss => ALLGOALS (full_simp_tac (Simplifier.inherit_context ss ss0)) end;
wenzelm@17002
   137
oheimb@2633
   138
paulson@3910
   139
(*intuitionistic simprules only*)
wenzelm@21539
   140
val IFOL_ss =
wenzelm@21539
   141
  FOL_basic_ss
wenzelm@26288
   142
  addsimps (@{thms meta_simps} @ @{thms IFOL_simps} @ @{thms int_ex_simps} @ @{thms int_all_simps})
wenzelm@10431
   143
  addsimprocs [defALL_regroup, defEX_regroup]    
wenzelm@26288
   144
  addcongs [@{thm imp_cong}];
paulson@2074
   145
paulson@3910
   146
(*classical simprules too*)
wenzelm@26288
   147
val FOL_ss = IFOL_ss addsimps (@{thms cla_simps} @ @{thms cla_ex_simps} @ @{thms cla_all_simps});
paulson@2074
   148
wenzelm@26496
   149
val simpsetup = Simplifier.map_simpset (K FOL_ss);
oheimb@2633
   150
oheimb@2633
   151
wenzelm@5219
   152
(*** integration of simplifier with classical reasoner ***)
oheimb@2633
   153
wenzelm@5219
   154
structure Clasimp = ClasimpFun
wenzelm@8472
   155
 (structure Simplifier = Simplifier and Splitter = Splitter
wenzelm@9851
   156
  and Classical  = Cla and Blast = Blast
wenzelm@26288
   157
  val iffD1 = @{thm iffD1} val iffD2 = @{thm iffD2} val notE = @{thm notE});
oheimb@4652
   158
open Clasimp;
oheimb@2633
   159
wenzelm@27338
   160
ML_Antiquote.value "clasimpset"
wenzelm@32149
   161
  (Scan.succeed "Clasimp.clasimpset_of (ML_Context.the_local_context ())");
wenzelm@22128
   162
oheimb@2633
   163
val FOL_css = (FOL_cs, FOL_ss);