src/FOL/simpdata.ML
author wenzelm
Thu Jul 23 18:44:09 2009 +0200 (2009-07-23)
changeset 32149 ef59550a55d3
parent 32010 cb1a1c94b4cd
child 32155 e2bf2f73b0c8
permissions -rw-r--r--
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
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@26288
    11
    _ $ (Const("op =",_)$_$_)   => th RS @{thm eq_reflection}
wenzelm@26288
    12
  | _ $ (Const("op <->",_)$_$_) => 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
oheimb@5555
    18
  | _ $ (Const("op =",_)$_$_)   => mk_meta_eq th
oheimb@5555
    19
  | _ $ (Const("op <->",_)$_$_) => mk_meta_eq th
wenzelm@26288
    20
  | _ $ (Const("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@10431
    24
val mk_meta_prems =
wenzelm@10431
    25
    rule_by_tactic
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 ==)*)
paulson@6114
    29
fun mk_meta_cong rl =
paulson@6114
    30
  standard(mk_meta_eq (mk_meta_prems rl))
paulson@6114
    31
  handle THM _ =>
paulson@6114
    32
  error("Premises and conclusion of congruence rules must use =-equality or <->");
oheimb@5555
    33
oheimb@5304
    34
val mksimps_pairs =
wenzelm@26288
    35
  [("op -->", [@{thm mp}]), ("op &", [@{thm conjunct1}, @{thm conjunct2}]),
wenzelm@26288
    36
   ("All", [@{thm spec}]), ("True", []), ("False", [])];
oheimb@5304
    37
wenzelm@16019
    38
(* ###FIXME: move to simplifier.ML
oheimb@5304
    39
val mk_atomize:      (string * thm list) list -> thm -> thm list
oheimb@5304
    40
*)
wenzelm@16019
    41
(* ###FIXME: move to simplifier.ML *)
oheimb@5304
    42
fun mk_atomize pairs =
oheimb@5304
    43
  let fun atoms th =
oheimb@5304
    44
        (case concl_of th of
oheimb@5304
    45
           Const("Trueprop",_) $ p =>
oheimb@5304
    46
             (case head_of p of
oheimb@5304
    47
                Const(a,_) =>
haftmann@17325
    48
                  (case AList.lookup (op =) pairs a of
skalberg@15570
    49
                     SOME(rls) => List.concat (map atoms ([th] RL rls))
skalberg@15531
    50
                   | NONE => [th])
oheimb@5304
    51
              | _ => [th])
oheimb@5304
    52
         | _ => [th])
oheimb@5304
    53
  in atoms end;
oheimb@5304
    54
wenzelm@12725
    55
fun mksimps pairs = (map mk_eq o mk_atomize pairs o gen_all);
lcp@981
    56
paulson@1914
    57
paulson@4349
    58
(** make simplification procedures for quantifier elimination **)
paulson@4349
    59
structure Quantifier1 = Quantifier1Fun(
paulson@4349
    60
struct
paulson@4349
    61
  (*abstract syntax*)
skalberg@15531
    62
  fun dest_eq((c as Const("op =",_)) $ s $ t) = SOME(c,s,t)
skalberg@15531
    63
    | dest_eq _ = NONE;
skalberg@15531
    64
  fun dest_conj((c as Const("op &",_)) $ s $ t) = SOME(c,s,t)
skalberg@15531
    65
    | dest_conj _ = NONE;
skalberg@15531
    66
  fun dest_imp((c as Const("op -->",_)) $ s $ t) = SOME(c,s,t)
skalberg@15531
    67
    | dest_imp _ = NONE;
paulson@4349
    68
  val conj = FOLogic.conj
paulson@4349
    69
  val imp  = FOLogic.imp
paulson@4349
    70
  (*rules*)
wenzelm@26288
    71
  val iff_reflection = @{thm iff_reflection}
wenzelm@26288
    72
  val iffI = @{thm iffI}
wenzelm@26288
    73
  val iff_trans = @{thm iff_trans}
wenzelm@26288
    74
  val conjI= @{thm conjI}
wenzelm@26288
    75
  val conjE= @{thm conjE}
wenzelm@26288
    76
  val impI = @{thm impI}
wenzelm@26288
    77
  val mp   = @{thm mp}
wenzelm@26288
    78
  val uncurry = @{thm uncurry}
wenzelm@26288
    79
  val exI  = @{thm exI}
wenzelm@26288
    80
  val exE  = @{thm exE}
wenzelm@26288
    81
  val iff_allI = @{thm iff_allI}
wenzelm@26288
    82
  val iff_exI = @{thm iff_exI}
wenzelm@26288
    83
  val all_comm = @{thm all_comm}
wenzelm@26288
    84
  val ex_comm = @{thm ex_comm}
paulson@4349
    85
end);
paulson@4349
    86
wenzelm@13462
    87
val defEX_regroup =
wenzelm@32010
    88
  Simplifier.simproc @{theory}
wenzelm@13462
    89
    "defined EX" ["EX x. P(x)"] Quantifier1.rearrange_ex;
paulson@4349
    90
paulson@4349
    91
val defALL_regroup =
wenzelm@32010
    92
  Simplifier.simproc @{theory}
wenzelm@13462
    93
    "defined ALL" ["ALL x. P(x)"] Quantifier1.rearrange_all;
paulson@4349
    94
paulson@4349
    95
paulson@4349
    96
(*** Case splitting ***)
clasohm@0
    97
oheimb@5304
    98
structure SplitterData =
oheimb@5304
    99
  struct
oheimb@5304
   100
  structure Simplifier = Simplifier
oheimb@5555
   101
  val mk_eq          = mk_eq
wenzelm@26288
   102
  val meta_eq_to_iff = @{thm meta_eq_to_iff}
wenzelm@26288
   103
  val iffD           = @{thm iffD2}
wenzelm@26288
   104
  val disjE          = @{thm disjE}
wenzelm@26288
   105
  val conjE          = @{thm conjE}
wenzelm@26288
   106
  val exE            = @{thm exE}
wenzelm@26288
   107
  val contrapos      = @{thm contrapos}
wenzelm@26288
   108
  val contrapos2     = @{thm contrapos2}
wenzelm@26288
   109
  val notnotD        = @{thm notnotD}
oheimb@5304
   110
  end;
berghofe@1722
   111
oheimb@5304
   112
structure Splitter = SplitterFun(SplitterData);
berghofe@1722
   113
oheimb@5304
   114
val split_tac        = Splitter.split_tac;
oheimb@5304
   115
val split_inside_tac = Splitter.split_inside_tac;
oheimb@5304
   116
val split_asm_tac    = Splitter.split_asm_tac;
oheimb@5307
   117
val op addsplits     = Splitter.addsplits;
oheimb@5307
   118
val op delsplits     = Splitter.delsplits;
paulson@4325
   119
paulson@4325
   120
paulson@2074
   121
(*** Standard simpsets ***)
paulson@2074
   122
wenzelm@26288
   123
val triv_rls = [@{thm TrueI}, @{thm refl}, reflexive_thm, @{thm iff_refl}, @{thm notFalseI}];
paulson@2074
   124
wenzelm@26288
   125
fun unsafe_solver prems = FIRST'[resolve_tac (triv_rls @ prems),
wenzelm@26288
   126
                                 atac, etac @{thm FalseE}];
oheimb@2633
   127
(*No premature instantiation of variables during simplification*)
wenzelm@26288
   128
fun   safe_solver prems = FIRST'[match_tac (triv_rls @ prems),
wenzelm@26288
   129
                                 eq_assume_tac, ematch_tac [@{thm FalseE}]];
oheimb@2633
   130
paulson@3910
   131
(*No simprules, but basic infastructure for simplification*)
wenzelm@17892
   132
val FOL_basic_ss =
wenzelm@28262
   133
  Simplifier.theory_context (the_context ()) empty_ss
wenzelm@10431
   134
  setsubgoaler asm_simp_tac
wenzelm@10431
   135
  setSSolver (mk_solver "FOL safe" safe_solver)
wenzelm@10431
   136
  setSolver (mk_solver "FOL unsafe" unsafe_solver)
wenzelm@10431
   137
  setmksimps (mksimps mksimps_pairs)
wenzelm@10431
   138
  setmkcong mk_meta_cong;
oheimb@5304
   139
wenzelm@18324
   140
fun unfold_tac ths =
wenzelm@18324
   141
  let val ss0 = Simplifier.clear_ss FOL_basic_ss addsimps ths
wenzelm@18324
   142
  in fn ss => ALLGOALS (full_simp_tac (Simplifier.inherit_context ss ss0)) end;
wenzelm@17002
   143
oheimb@2633
   144
paulson@3910
   145
(*intuitionistic simprules only*)
wenzelm@21539
   146
val IFOL_ss =
wenzelm@21539
   147
  FOL_basic_ss
wenzelm@26288
   148
  addsimps (@{thms meta_simps} @ @{thms IFOL_simps} @ @{thms int_ex_simps} @ @{thms int_all_simps})
wenzelm@10431
   149
  addsimprocs [defALL_regroup, defEX_regroup]    
wenzelm@26288
   150
  addcongs [@{thm imp_cong}];
paulson@2074
   151
paulson@3910
   152
(*classical simprules too*)
wenzelm@26288
   153
val FOL_ss = IFOL_ss addsimps (@{thms cla_simps} @ @{thms cla_ex_simps} @ @{thms cla_all_simps});
paulson@2074
   154
wenzelm@26496
   155
val simpsetup = Simplifier.map_simpset (K FOL_ss);
oheimb@2633
   156
oheimb@2633
   157
wenzelm@5219
   158
(*** integration of simplifier with classical reasoner ***)
oheimb@2633
   159
wenzelm@5219
   160
structure Clasimp = ClasimpFun
wenzelm@8472
   161
 (structure Simplifier = Simplifier and Splitter = Splitter
wenzelm@9851
   162
  and Classical  = Cla and Blast = Blast
wenzelm@26288
   163
  val iffD1 = @{thm iffD1} val iffD2 = @{thm iffD2} val notE = @{thm notE});
oheimb@4652
   164
open Clasimp;
oheimb@2633
   165
wenzelm@27338
   166
ML_Antiquote.value "clasimpset"
wenzelm@32149
   167
  (Scan.succeed "Clasimp.clasimpset_of (ML_Context.the_local_context ())");
wenzelm@22128
   168
oheimb@2633
   169
val FOL_css = (FOL_cs, FOL_ss);