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