src/FOL/simpdata.ML
author paulson
Fri Sep 18 14:34:06 1998 +0200 (1998-09-18 ago)
changeset 5496 42d13691be86
parent 5307 6a699d5cdef4
child 5555 4b9386224084
permissions -rw-r--r--
Pruning of parameters and True assumptions
     1 (*  Title:      FOL/simpdata
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1994  University of Cambridge
     5 
     6 Simplification data for FOL
     7 *)
     8 
     9 (* Elimination of True from asumptions: *)
    10 
    11 val True_implies_equals = prove_goal IFOL.thy
    12  "(True ==> PROP P) == PROP P"
    13 (K [rtac equal_intr_rule 1, atac 2,
    14           METAHYPS (fn prems => resolve_tac prems 1) 1,
    15           rtac TrueI 1]);
    16 
    17 
    18 (*** Rewrite rules ***)
    19 
    20 fun int_prove_fun s = 
    21  (writeln s;  
    22   prove_goal IFOL.thy s
    23    (fn prems => [ (cut_facts_tac prems 1), 
    24                   (IntPr.fast_tac 1) ]));
    25 
    26 val conj_simps = map int_prove_fun
    27  ["P & True <-> P",      "True & P <-> P",
    28   "P & False <-> False", "False & P <-> False",
    29   "P & P <-> P", "P & P & Q <-> P & Q",
    30   "P & ~P <-> False",    "~P & P <-> False",
    31   "(P & Q) & R <-> P & (Q & R)"];
    32 
    33 val disj_simps = map int_prove_fun
    34  ["P | True <-> True",  "True | P <-> True",
    35   "P | False <-> P",    "False | P <-> P",
    36   "P | P <-> P", "P | P | Q <-> P | Q",
    37   "(P | Q) | R <-> P | (Q | R)"];
    38 
    39 val not_simps = map int_prove_fun
    40  ["~(P|Q)  <-> ~P & ~Q",
    41   "~ False <-> True",   "~ True <-> False"];
    42 
    43 val imp_simps = map int_prove_fun
    44  ["(P --> False) <-> ~P",       "(P --> True) <-> True",
    45   "(False --> P) <-> True",     "(True --> P) <-> P", 
    46   "(P --> P) <-> True",         "(P --> ~P) <-> ~P"];
    47 
    48 val iff_simps = map int_prove_fun
    49  ["(True <-> P) <-> P",         "(P <-> True) <-> P",
    50   "(P <-> P) <-> True",
    51   "(False <-> P) <-> ~P",       "(P <-> False) <-> ~P"];
    52 
    53 (*The x=t versions are needed for the simplification procedures*)
    54 val quant_simps = map int_prove_fun
    55  ["(ALL x. P) <-> P",   
    56   "(ALL x. x=t --> P(x)) <-> P(t)",
    57   "(ALL x. t=x --> P(x)) <-> P(t)",
    58   "(EX x. P) <-> P",
    59   "(EX x. x=t & P(x)) <-> P(t)", 
    60   "(EX x. t=x & P(x)) <-> P(t)"];
    61 
    62 (*These are NOT supplied by default!*)
    63 val distrib_simps  = map int_prove_fun
    64  ["P & (Q | R) <-> P&Q | P&R", 
    65   "(Q | R) & P <-> Q&P | R&P",
    66   "(P | Q --> R) <-> (P --> R) & (Q --> R)"];
    67 
    68 (** Conversion into rewrite rules **)
    69 
    70 fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th;
    71 
    72 val P_iff_F = int_prove_fun "~P ==> (P <-> False)";
    73 val iff_reflection_F = P_iff_F RS iff_reflection;
    74 
    75 val P_iff_T = int_prove_fun "P ==> (P <-> True)";
    76 val iff_reflection_T = P_iff_T RS iff_reflection;
    77 
    78 (*Make meta-equalities.  The operator below is Trueprop*)
    79 fun mk_meta_eq th = case concl_of th of
    80     Const("==",_)$_$_           => th
    81   | _ $ (Const("op =",_)$_$_)   => th RS eq_reflection
    82   | _ $ (Const("op <->",_)$_$_) => th RS iff_reflection
    83   | _ $ (Const("Not",_)$_)      => th RS iff_reflection_F
    84   | _                           => th RS iff_reflection_T;
    85 
    86 val mksimps_pairs =
    87   [("op -->", [mp]), ("op &", [conjunct1,conjunct2]),
    88    ("All", [spec]), ("True", []), ("False", [])];
    89 
    90 (* FIXME: move to Provers/simplifier.ML
    91 val mk_atomize:      (string * thm list) list -> thm -> thm list
    92 *)
    93 (* FIXME: move to Provers/simplifier.ML*)
    94 fun mk_atomize pairs =
    95   let fun atoms th =
    96         (case concl_of th of
    97            Const("Trueprop",_) $ p =>
    98              (case head_of p of
    99                 Const(a,_) =>
   100                   (case assoc(pairs,a) of
   101                      Some(rls) => flat (map atoms ([th] RL rls))
   102                    | None => [th])
   103               | _ => [th])
   104          | _ => [th])
   105   in atoms end;
   106 
   107 fun mksimps pairs = (map mk_meta_eq o mk_atomize pairs o gen_all);
   108 
   109 (*** Classical laws ***)
   110 
   111 fun prove_fun s = 
   112  (writeln s;  
   113   prove_goal FOL.thy s
   114    (fn prems => [ (cut_facts_tac prems 1), 
   115                   (Cla.fast_tac FOL_cs 1) ]));
   116 
   117 (*Avoids duplication of subgoals after expand_if, when the true and false 
   118   cases boil down to the same thing.*) 
   119 val cases_simp = prove_fun "(P --> Q) & (~P --> Q) <-> Q";
   120 
   121 
   122 (*** Miniscoping: pushing quantifiers in
   123      We do NOT distribute of ALL over &, or dually that of EX over |
   124      Baaz and Leitsch, On Skolemization and Proof Complexity (1994) 
   125      show that this step can increase proof length!
   126 ***)
   127 
   128 (*existential miniscoping*)
   129 val int_ex_simps = map int_prove_fun 
   130 		     ["(EX x. P(x) & Q) <-> (EX x. P(x)) & Q",
   131 		      "(EX x. P & Q(x)) <-> P & (EX x. Q(x))",
   132 		      "(EX x. P(x) | Q) <-> (EX x. P(x)) | Q",
   133 		      "(EX x. P | Q(x)) <-> P | (EX x. Q(x))"];
   134 
   135 (*classical rules*)
   136 val cla_ex_simps = map prove_fun 
   137                      ["(EX x. P(x) --> Q) <-> (ALL x. P(x)) --> Q",
   138 		      "(EX x. P --> Q(x)) <-> P --> (EX x. Q(x))"];
   139 
   140 val ex_simps = int_ex_simps @ cla_ex_simps;
   141 
   142 (*universal miniscoping*)
   143 val int_all_simps = map int_prove_fun
   144 		      ["(ALL x. P(x) & Q) <-> (ALL x. P(x)) & Q",
   145 		       "(ALL x. P & Q(x)) <-> P & (ALL x. Q(x))",
   146 		       "(ALL x. P(x) --> Q) <-> (EX x. P(x)) --> Q",
   147 		       "(ALL x. P --> Q(x)) <-> P --> (ALL x. Q(x))"];
   148 
   149 (*classical rules*)
   150 val cla_all_simps = map prove_fun
   151                       ["(ALL x. P(x) | Q) <-> (ALL x. P(x)) | Q",
   152 		       "(ALL x. P | Q(x)) <-> P | (ALL x. Q(x))"];
   153 
   154 val all_simps = int_all_simps @ cla_all_simps;
   155 
   156 
   157 (*** Named rewrite rules proved for IFOL ***)
   158 
   159 fun int_prove nm thm  = qed_goal nm IFOL.thy thm
   160     (fn prems => [ (cut_facts_tac prems 1), 
   161                    (IntPr.fast_tac 1) ]);
   162 
   163 fun prove nm thm  = qed_goal nm FOL.thy thm (fn _ => [Blast_tac 1]);
   164 
   165 int_prove "conj_commute" "P&Q <-> Q&P";
   166 int_prove "conj_left_commute" "P&(Q&R) <-> Q&(P&R)";
   167 val conj_comms = [conj_commute, conj_left_commute];
   168 
   169 int_prove "disj_commute" "P|Q <-> Q|P";
   170 int_prove "disj_left_commute" "P|(Q|R) <-> Q|(P|R)";
   171 val disj_comms = [disj_commute, disj_left_commute];
   172 
   173 int_prove "conj_disj_distribL" "P&(Q|R) <-> (P&Q | P&R)";
   174 int_prove "conj_disj_distribR" "(P|Q)&R <-> (P&R | Q&R)";
   175 
   176 int_prove "disj_conj_distribL" "P|(Q&R) <-> (P|Q) & (P|R)";
   177 int_prove "disj_conj_distribR" "(P&Q)|R <-> (P|R) & (Q|R)";
   178 
   179 int_prove "imp_conj_distrib" "(P --> (Q&R)) <-> (P-->Q) & (P-->R)";
   180 int_prove "imp_conj"         "((P&Q)-->R)   <-> (P --> (Q --> R))";
   181 int_prove "imp_disj"         "(P|Q --> R)   <-> (P-->R) & (Q-->R)";
   182 
   183 prove "imp_disj1" "(P-->Q) | R <-> (P-->Q | R)";
   184 prove "imp_disj2" "Q | (P-->R) <-> (P-->Q | R)";
   185 
   186 int_prove "de_Morgan_disj" "(~(P | Q)) <-> (~P & ~Q)";
   187 prove     "de_Morgan_conj" "(~(P & Q)) <-> (~P | ~Q)";
   188 
   189 prove     "not_iff" "~(P <-> Q) <-> (P <-> ~Q)";
   190 
   191 prove     "not_all" "(~ (ALL x. P(x))) <-> (EX x.~P(x))";
   192 prove     "imp_all" "((ALL x. P(x)) --> Q) <-> (EX x. P(x) --> Q)";
   193 int_prove "not_ex"  "(~ (EX x. P(x))) <-> (ALL x.~P(x))";
   194 int_prove "imp_ex" "((EX x. P(x)) --> Q) <-> (ALL x. P(x) --> Q)";
   195 
   196 int_prove "ex_disj_distrib"
   197     "(EX x. P(x) | Q(x)) <-> ((EX x. P(x)) | (EX x. Q(x)))";
   198 int_prove "all_conj_distrib"
   199     "(ALL x. P(x) & Q(x)) <-> ((ALL x. P(x)) & (ALL x. Q(x)))";
   200 
   201 
   202 (*Used in ZF, perhaps elsewhere?*)
   203 val meta_eq_to_obj_eq = prove_goal IFOL.thy "x==y ==> x=y"
   204   (fn [prem] => [rewtac prem, rtac refl 1]);
   205 
   206 
   207 (** make simplification procedures for quantifier elimination **)
   208 structure Quantifier1 = Quantifier1Fun(
   209 struct
   210   (*abstract syntax*)
   211   fun dest_eq((c as Const("op =",_)) $ s $ t) = Some(c,s,t)
   212     | dest_eq _ = None;
   213   fun dest_conj((c as Const("op &",_)) $ s $ t) = Some(c,s,t)
   214     | dest_conj _ = None;
   215   val conj = FOLogic.conj
   216   val imp  = FOLogic.imp
   217   (*rules*)
   218   val iff_reflection = iff_reflection
   219   val iffI = iffI
   220   val sym  = sym
   221   val conjI= conjI
   222   val conjE= conjE
   223   val impI = impI
   224   val impE = impE
   225   val mp   = mp
   226   val exI  = exI
   227   val exE  = exE
   228   val allI = allI
   229   val allE = allE
   230 end);
   231 
   232 local
   233 val ex_pattern =
   234   read_cterm (sign_of FOL.thy) ("EX x. P(x) & Q(x)", FOLogic.oT)
   235 
   236 val all_pattern =
   237   read_cterm (sign_of FOL.thy) ("ALL x. P(x) & P'(x) --> Q(x)", FOLogic.oT)
   238 
   239 in
   240 val defEX_regroup =
   241   mk_simproc "defined EX" [ex_pattern] Quantifier1.rearrange_ex;
   242 val defALL_regroup =
   243   mk_simproc "defined ALL" [all_pattern] Quantifier1.rearrange_all;
   244 end;
   245 
   246 
   247 (*** Case splitting ***)
   248 
   249 val meta_eq_to_iff = prove_goal IFOL.thy "x==y ==> x<->y"
   250   (fn [prem] => [rewtac prem, rtac iffI 1, atac 1, atac 1]);
   251 
   252 structure SplitterData =
   253   struct
   254   structure Simplifier = Simplifier
   255   val mk_meta_eq     = mk_meta_eq
   256   val meta_eq_to_iff = meta_eq_to_iff
   257   val iffD           = iffD2
   258   val disjE          = disjE
   259   val conjE          = conjE
   260   val exE            = exE
   261   val contrapos      = contrapos
   262   val contrapos2     = contrapos2
   263   val notnotD        = notnotD
   264   end;
   265 
   266 structure Splitter = SplitterFun(SplitterData);
   267 
   268 val split_tac        = Splitter.split_tac;
   269 val split_inside_tac = Splitter.split_inside_tac;
   270 val split_asm_tac    = Splitter.split_asm_tac;
   271 val op addsplits     = Splitter.addsplits;
   272 val op delsplits     = Splitter.delsplits;
   273 val Addsplits        = Splitter.Addsplits;
   274 val Delsplits        = Splitter.Delsplits;
   275 
   276 
   277 (*** Standard simpsets ***)
   278 
   279 structure Induction = InductionFun(struct val spec=IFOL.spec end);
   280 
   281 open Induction;
   282 
   283 (*Add congruence rules for = or <-> (instead of ==) *)
   284 infix 4 addcongs delcongs;
   285 fun ss addcongs congs =
   286         ss addeqcongs (map standard (congs RL [eq_reflection,iff_reflection]));
   287 fun ss delcongs congs =
   288         ss deleqcongs (map standard (congs RL [eq_reflection,iff_reflection]));
   289 
   290 fun Addcongs congs = (simpset_ref() := simpset() addcongs congs);
   291 fun Delcongs congs = (simpset_ref() := simpset() delcongs congs);
   292 
   293 
   294 val meta_simps =
   295    [triv_forall_equality,  (* prunes params *)
   296     True_implies_equals];  (* prune asms `True' *)
   297 
   298 val IFOL_simps =
   299    [refl RS P_iff_T] @ conj_simps @ disj_simps @ not_simps @ 
   300     imp_simps @ iff_simps @ quant_simps;
   301 
   302 val notFalseI = int_prove_fun "~False";
   303 val triv_rls = [TrueI,refl,iff_refl,notFalseI];
   304 
   305 fun unsafe_solver prems = FIRST'[resolve_tac (triv_rls@prems),
   306 				 atac, etac FalseE];
   307 (*No premature instantiation of variables during simplification*)
   308 fun   safe_solver prems = FIRST'[match_tac (triv_rls@prems),
   309 				 eq_assume_tac, ematch_tac [FalseE]];
   310 
   311 (*No simprules, but basic infastructure for simplification*)
   312 val FOL_basic_ss = empty_ss setsubgoaler asm_simp_tac
   313                             addsimprocs [defALL_regroup,defEX_regroup]
   314 			    setSSolver   safe_solver
   315 			    setSolver  unsafe_solver
   316 			    setmksimps (mksimps mksimps_pairs);
   317 
   318 
   319 
   320 (*intuitionistic simprules only*)
   321 val IFOL_ss = 
   322     FOL_basic_ss addsimps (meta_simps @ IFOL_simps @ 
   323 			   int_ex_simps @ int_all_simps)
   324                  addcongs [imp_cong];
   325 
   326 val cla_simps = 
   327     [de_Morgan_conj, de_Morgan_disj, imp_disj1, imp_disj2,
   328      not_all, not_ex, cases_simp] @
   329     map prove_fun
   330      ["~(P&Q)  <-> ~P | ~Q",
   331       "P | ~P",             "~P | P",
   332       "~ ~ P <-> P",        "(~P --> P) <-> P",
   333       "(~P <-> ~Q) <-> (P<->Q)"];
   334 
   335 (*classical simprules too*)
   336 val FOL_ss = IFOL_ss addsimps (cla_simps @ cla_ex_simps @ cla_all_simps);
   337 
   338 simpset_ref() := FOL_ss;
   339 
   340 
   341 
   342 (*** integration of simplifier with classical reasoner ***)
   343 
   344 structure Clasimp = ClasimpFun
   345  (structure Simplifier = Simplifier and Classical = Cla and Blast = Blast
   346   val op addcongs = op addcongs and op delcongs = op delcongs
   347   and op addSaltern = op addSaltern and op addbefore = op addbefore);
   348 
   349 open Clasimp;
   350 
   351 val FOL_css = (FOL_cs, FOL_ss);