src/FOL/simpdata.ML
changeset 10431 bb67f704d631
parent 9889 8802b140334c
child 11232 558a4feebb04
equal deleted inserted replaced
10430:d3f780c3af0c 10431:bb67f704d631
    16           rtac TrueI 1]);
    16           rtac TrueI 1]);
    17 
    17 
    18 
    18 
    19 (*** Rewrite rules ***)
    19 (*** Rewrite rules ***)
    20 
    20 
    21 fun int_prove_fun s = 
    21 fun int_prove_fun s =
    22  (writeln s;  
    22  (writeln s;
    23   prove_goal IFOL.thy s
    23   prove_goal IFOL.thy s
    24    (fn prems => [ (cut_facts_tac prems 1), 
    24    (fn prems => [ (cut_facts_tac prems 1),
    25                   (IntPr.fast_tac 1) ]));
    25                   (IntPr.fast_tac 1) ]));
    26 
    26 
    27 val conj_simps = map int_prove_fun
    27 val conj_simps = map int_prove_fun
    28  ["P & True <-> P",      "True & P <-> P",
    28  ["P & True <-> P",      "True & P <-> P",
    29   "P & False <-> False", "False & P <-> False",
    29   "P & False <-> False", "False & P <-> False",
    41  ["~(P|Q)  <-> ~P & ~Q",
    41  ["~(P|Q)  <-> ~P & ~Q",
    42   "~ False <-> True",   "~ True <-> False"];
    42   "~ False <-> True",   "~ True <-> False"];
    43 
    43 
    44 val imp_simps = map int_prove_fun
    44 val imp_simps = map int_prove_fun
    45  ["(P --> False) <-> ~P",       "(P --> True) <-> True",
    45  ["(P --> False) <-> ~P",       "(P --> True) <-> True",
    46   "(False --> P) <-> True",     "(True --> P) <-> P", 
    46   "(False --> P) <-> True",     "(True --> P) <-> P",
    47   "(P --> P) <-> True",         "(P --> ~P) <-> ~P"];
    47   "(P --> P) <-> True",         "(P --> ~P) <-> ~P"];
    48 
    48 
    49 val iff_simps = map int_prove_fun
    49 val iff_simps = map int_prove_fun
    50  ["(True <-> P) <-> P",         "(P <-> True) <-> P",
    50  ["(True <-> P) <-> P",         "(P <-> True) <-> P",
    51   "(P <-> P) <-> True",
    51   "(P <-> P) <-> True",
    52   "(False <-> P) <-> ~P",       "(P <-> False) <-> ~P"];
    52   "(False <-> P) <-> ~P",       "(P <-> False) <-> ~P"];
    53 
    53 
    54 (*The x=t versions are needed for the simplification procedures*)
    54 (*The x=t versions are needed for the simplification procedures*)
    55 val quant_simps = map int_prove_fun
    55 val quant_simps = map int_prove_fun
    56  ["(ALL x. P) <-> P",   
    56  ["(ALL x. P) <-> P",
    57   "(ALL x. x=t --> P(x)) <-> P(t)",
    57   "(ALL x. x=t --> P(x)) <-> P(t)",
    58   "(ALL x. t=x --> P(x)) <-> P(t)",
    58   "(ALL x. t=x --> P(x)) <-> P(t)",
    59   "(EX x. P) <-> P",
    59   "(EX x. P) <-> P",
    60   "(EX x. x=t & P(x)) <-> P(t)", 
    60   "(EX x. x=t & P(x)) <-> P(t)",
    61   "(EX x. t=x & P(x)) <-> P(t)"];
    61   "(EX x. t=x & P(x)) <-> P(t)"];
    62 
    62 
    63 (*These are NOT supplied by default!*)
    63 (*These are NOT supplied by default!*)
    64 val distrib_simps  = map int_prove_fun
    64 val distrib_simps  = map int_prove_fun
    65  ["P & (Q | R) <-> P&Q | P&R", 
    65  ["P & (Q | R) <-> P&Q | P&R",
    66   "(Q | R) & P <-> Q&P | R&P",
    66   "(Q | R) & P <-> Q&P | R&P",
    67   "(P | Q --> R) <-> (P --> R) & (Q --> R)"];
    67   "(P | Q --> R) <-> (P --> R) & (Q --> R)"];
    68 
    68 
    69 (** Conversion into rewrite rules **)
    69 (** Conversion into rewrite rules **)
    70 
    70 
    79 (*Make meta-equalities.  The operator below is Trueprop*)
    79 (*Make meta-equalities.  The operator below is Trueprop*)
    80 
    80 
    81 fun mk_meta_eq th = case concl_of th of
    81 fun mk_meta_eq th = case concl_of th of
    82     _ $ (Const("op =",_)$_$_)   => th RS eq_reflection
    82     _ $ (Const("op =",_)$_$_)   => th RS eq_reflection
    83   | _ $ (Const("op <->",_)$_$_) => th RS iff_reflection
    83   | _ $ (Const("op <->",_)$_$_) => th RS iff_reflection
    84   | _                           => 
    84   | _                           =>
    85   error("conclusion must be a =-equality or <->");;
    85   error("conclusion must be a =-equality or <->");;
    86 
    86 
    87 fun mk_eq th = case concl_of th of
    87 fun mk_eq th = case concl_of th of
    88     Const("==",_)$_$_           => th
    88     Const("==",_)$_$_           => th
    89   | _ $ (Const("op =",_)$_$_)   => mk_meta_eq th
    89   | _ $ (Const("op =",_)$_$_)   => mk_meta_eq th
    90   | _ $ (Const("op <->",_)$_$_) => mk_meta_eq th
    90   | _ $ (Const("op <->",_)$_$_) => mk_meta_eq th
    91   | _ $ (Const("Not",_)$_)      => th RS iff_reflection_F
    91   | _ $ (Const("Not",_)$_)      => th RS iff_reflection_F
    92   | _                           => th RS iff_reflection_T;
    92   | _                           => th RS iff_reflection_T;
    93 
    93 
    94 (*Replace premises x=y, X<->Y by X==Y*)
    94 (*Replace premises x=y, X<->Y by X==Y*)
    95 val mk_meta_prems = 
    95 val mk_meta_prems =
    96     rule_by_tactic 
    96     rule_by_tactic
    97       (REPEAT_FIRST (resolve_tac [meta_eq_to_obj_eq, def_imp_iff]));
    97       (REPEAT_FIRST (resolve_tac [meta_eq_to_obj_eq, def_imp_iff]));
    98 
    98 
    99 (*Congruence rules for = or <-> (instead of ==)*)
    99 (*Congruence rules for = or <-> (instead of ==)*)
   100 fun mk_meta_cong rl =
   100 fun mk_meta_cong rl =
   101   standard(mk_meta_eq (mk_meta_prems rl))
   101   standard(mk_meta_eq (mk_meta_prems rl))
   125 
   125 
   126 fun mksimps pairs = (map mk_eq o mk_atomize pairs o gen_all);
   126 fun mksimps pairs = (map mk_eq o mk_atomize pairs o gen_all);
   127 
   127 
   128 (*** Classical laws ***)
   128 (*** Classical laws ***)
   129 
   129 
   130 fun prove_fun s = 
   130 fun prove_fun s =
   131  (writeln s;  
   131  (writeln s;
   132   prove_goal (the_context ()) s
   132   prove_goal (the_context ()) s
   133    (fn prems => [ (cut_facts_tac prems 1), 
   133    (fn prems => [ (cut_facts_tac prems 1),
   134                   (Cla.fast_tac FOL_cs 1) ]));
   134                   (Cla.fast_tac FOL_cs 1) ]));
   135 
   135 
   136 (*Avoids duplication of subgoals after expand_if, when the true and false 
   136 (*Avoids duplication of subgoals after expand_if, when the true and false
   137   cases boil down to the same thing.*) 
   137   cases boil down to the same thing.*)
   138 val cases_simp = prove_fun "(P --> Q) & (~P --> Q) <-> Q";
   138 val cases_simp = prove_fun "(P --> Q) & (~P --> Q) <-> Q";
   139 
   139 
   140 
   140 
   141 (*** Miniscoping: pushing quantifiers in
   141 (*** Miniscoping: pushing quantifiers in
   142      We do NOT distribute of ALL over &, or dually that of EX over |
   142      We do NOT distribute of ALL over &, or dually that of EX over |
   143      Baaz and Leitsch, On Skolemization and Proof Complexity (1994) 
   143      Baaz and Leitsch, On Skolemization and Proof Complexity (1994)
   144      show that this step can increase proof length!
   144      show that this step can increase proof length!
   145 ***)
   145 ***)
   146 
   146 
   147 (*existential miniscoping*)
   147 (*existential miniscoping*)
   148 val int_ex_simps = map int_prove_fun 
   148 val int_ex_simps = map int_prove_fun
   149                      ["(EX x. P(x) & Q) <-> (EX x. P(x)) & Q",
   149                      ["(EX x. P(x) & Q) <-> (EX x. P(x)) & Q",
   150                       "(EX x. P & Q(x)) <-> P & (EX x. Q(x))",
   150                       "(EX x. P & Q(x)) <-> P & (EX x. Q(x))",
   151                       "(EX x. P(x) | Q) <-> (EX x. P(x)) | Q",
   151                       "(EX x. P(x) | Q) <-> (EX x. P(x)) | Q",
   152                       "(EX x. P | Q(x)) <-> P | (EX x. Q(x))"];
   152                       "(EX x. P | Q(x)) <-> P | (EX x. Q(x))"];
   153 
   153 
   154 (*classical rules*)
   154 (*classical rules*)
   155 val cla_ex_simps = map prove_fun 
   155 val cla_ex_simps = map prove_fun
   156                      ["(EX x. P(x) --> Q) <-> (ALL x. P(x)) --> Q",
   156                      ["(EX x. P(x) --> Q) <-> (ALL x. P(x)) --> Q",
   157                       "(EX x. P --> Q(x)) <-> P --> (EX x. Q(x))"];
   157                       "(EX x. P --> Q(x)) <-> P --> (EX x. Q(x))"];
   158 
   158 
   159 val ex_simps = int_ex_simps @ cla_ex_simps;
   159 val ex_simps = int_ex_simps @ cla_ex_simps;
   160 
   160 
   174 
   174 
   175 
   175 
   176 (*** Named rewrite rules proved for IFOL ***)
   176 (*** Named rewrite rules proved for IFOL ***)
   177 
   177 
   178 fun int_prove nm thm  = qed_goal nm IFOL.thy thm
   178 fun int_prove nm thm  = qed_goal nm IFOL.thy thm
   179     (fn prems => [ (cut_facts_tac prems 1), 
   179     (fn prems => [ (cut_facts_tac prems 1),
   180                    (IntPr.fast_tac 1) ]);
   180                    (IntPr.fast_tac 1) ]);
   181 
   181 
   182 fun prove nm thm  = qed_goal nm (the_context ()) thm (fn _ => [Blast_tac 1]);
   182 fun prove nm thm  = qed_goal nm (the_context ()) thm (fn _ => [Blast_tac 1]);
   183 
   183 
   184 int_prove "conj_commute" "P&Q <-> Q&P";
   184 int_prove "conj_commute" "P&Q <-> Q&P";
   299 val meta_simps =
   299 val meta_simps =
   300    [triv_forall_equality,  (* prunes params *)
   300    [triv_forall_equality,  (* prunes params *)
   301     True_implies_equals];  (* prune asms `True' *)
   301     True_implies_equals];  (* prune asms `True' *)
   302 
   302 
   303 val IFOL_simps =
   303 val IFOL_simps =
   304     [refl RS P_iff_T] @ conj_simps @ disj_simps @ not_simps @ 
   304     [refl RS P_iff_T] @ conj_simps @ disj_simps @ not_simps @
   305     imp_simps @ iff_simps @ quant_simps;
   305     imp_simps @ iff_simps @ quant_simps;
   306 
   306 
   307 val notFalseI = int_prove_fun "~False";
   307 val notFalseI = int_prove_fun "~False";
   308 val triv_rls = [TrueI,refl,reflexive_thm,iff_refl,notFalseI];
   308 val triv_rls = [TrueI,refl,reflexive_thm,iff_refl,notFalseI];
   309 
   309 
   312 (*No premature instantiation of variables during simplification*)
   312 (*No premature instantiation of variables during simplification*)
   313 fun   safe_solver prems = FIRST'[match_tac (triv_rls@prems),
   313 fun   safe_solver prems = FIRST'[match_tac (triv_rls@prems),
   314                                  eq_assume_tac, ematch_tac [FalseE]];
   314                                  eq_assume_tac, ematch_tac [FalseE]];
   315 
   315 
   316 (*No simprules, but basic infastructure for simplification*)
   316 (*No simprules, but basic infastructure for simplification*)
   317 val FOL_basic_ss =
   317 val FOL_basic_ss = empty_ss
   318   empty_ss setsubgoaler asm_simp_tac
   318   setsubgoaler asm_simp_tac
   319     addsimprocs [defALL_regroup, defEX_regroup]
   319   setSSolver (mk_solver "FOL safe" safe_solver)
   320     setSSolver (mk_solver "FOL safe" safe_solver)
   320   setSolver (mk_solver "FOL unsafe" unsafe_solver)
   321     setSolver (mk_solver "FOL unsafe" unsafe_solver)
   321   setmksimps (mksimps mksimps_pairs)
   322     setmksimps (mksimps mksimps_pairs)
   322   setmkcong mk_meta_cong;
   323     setmkcong mk_meta_cong;
       
   324 
   323 
   325 
   324 
   326 (*intuitionistic simprules only*)
   325 (*intuitionistic simprules only*)
   327 val IFOL_ss =
   326 val IFOL_ss = FOL_basic_ss
   328     FOL_basic_ss addsimps (meta_simps @ IFOL_simps @
   327   addsimps (meta_simps @ IFOL_simps @ int_ex_simps @ int_all_simps)
   329                            int_ex_simps @ int_all_simps)
   328   addsimprocs [defALL_regroup, defEX_regroup]    
   330                  addcongs [imp_cong];
   329   addcongs [imp_cong];
   331 
   330 
   332 val cla_simps =
   331 val cla_simps =
   333     [de_Morgan_conj, de_Morgan_disj, imp_disj1, imp_disj2,
   332     [de_Morgan_conj, de_Morgan_disj, imp_disj1, imp_disj2,
   334      not_all, not_ex, cases_simp] @
   333      not_all, not_ex, cases_simp] @
   335     map prove_fun
   334     map prove_fun