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