src/HOL/simpdata.ML
changeset 2935 998cb95fdd43
parent 2805 6e5b2d6503eb
child 2948 f18035b1d531
equal deleted inserted replaced
2934:bd922fc9001b 2935:998cb95fdd43
    53 end;
    53 end;
    54 
    54 
    55 
    55 
    56 local
    56 local
    57 
    57 
    58   fun prover s = prove_goal HOL.thy s (fn _ => [fast_tac HOL_cs 1]);
    58   fun prover s = prove_goal HOL.thy s (fn _ => [blast_tac HOL_cs 1]);
    59 
    59 
    60   val P_imp_P_iff_True = prover "P --> (P = True)" RS mp;
    60   val P_imp_P_iff_True = prover "P --> (P = True)" RS mp;
    61   val P_imp_P_eq_True = P_imp_P_iff_True RS eq_reflection;
    61   val P_imp_P_eq_True = P_imp_P_iff_True RS eq_reflection;
    62 
    62 
    63   val not_P_imp_P_iff_F = prover "~P --> (P = False)" RS mp;
    63   val not_P_imp_P_iff_F = prover "~P --> (P = False)" RS mp;
   116 
   116 
   117 fun mksimps pairs = map mk_meta_eq o atomize pairs o gen_all;
   117 fun mksimps pairs = map mk_meta_eq o atomize pairs o gen_all;
   118 
   118 
   119 val imp_cong = impI RSN
   119 val imp_cong = impI RSN
   120     (2, prove_goal HOL.thy "(P=P')--> (P'--> (Q=Q'))--> ((P-->Q) = (P'-->Q'))"
   120     (2, prove_goal HOL.thy "(P=P')--> (P'--> (Q=Q'))--> ((P-->Q) = (P'-->Q'))"
   121         (fn _=> [fast_tac HOL_cs 1]) RS mp RS mp);
   121         (fn _=> [blast_tac HOL_cs 1]) RS mp RS mp);
   122 
   122 
   123 (*Miniscoping: pushing in existential quantifiers*)
   123 (*Miniscoping: pushing in existential quantifiers*)
   124 val ex_simps = map prover 
   124 val ex_simps = map prover 
   125                 ["(EX x. P x & Q)   = ((EX x.P x) & Q)",
   125                 ["(EX x. P x & Q)   = ((EX x.P x) & Q)",
   126                  "(EX x. P & Q x)   = (P & (EX x.Q x))",
   126                  "(EX x. P & Q x)   = (P & (EX x.Q x))",
   151         (fn prems => [REPEAT(resolve_tac prems 1)])
   151         (fn prems => [REPEAT(resolve_tac prems 1)])
   152   in equal_intr lemma1 lemma2 end;
   152   in equal_intr lemma1 lemma2 end;
   153 
   153 
   154 end;
   154 end;
   155 
   155 
   156 fun prove nm thm  = qed_goal nm HOL.thy thm (fn _ => [fast_tac HOL_cs 1]);
   156 fun prove nm thm  = qed_goal nm HOL.thy thm (fn _ => [blast_tac HOL_cs 1]);
   157 
   157 
   158 prove "conj_commute" "(P&Q) = (Q&P)";
   158 prove "conj_commute" "(P&Q) = (Q&P)";
   159 prove "conj_left_commute" "(P&(Q&R)) = (Q&(P&R))";
   159 prove "conj_left_commute" "(P&(Q&R)) = (Q&(P&R))";
   160 val conj_comms = [conj_commute, conj_left_commute];
   160 val conj_comms = [conj_commute, conj_left_commute];
   161 prove "conj_assoc" "((P&Q)&R) = (P&(Q&R))";
   161 prove "conj_assoc" "((P&Q)&R) = (P&(Q&R))";
   194 (* '&' congruence rule: not included by default!
   194 (* '&' congruence rule: not included by default!
   195    May slow rewrite proofs down by as much as 50% *)
   195    May slow rewrite proofs down by as much as 50% *)
   196 
   196 
   197 let val th = prove_goal HOL.thy 
   197 let val th = prove_goal HOL.thy 
   198                 "(P=P')--> (P'--> (Q=Q'))--> ((P&Q) = (P'&Q'))"
   198                 "(P=P')--> (P'--> (Q=Q'))--> ((P&Q) = (P'&Q'))"
   199                 (fn _=> [fast_tac HOL_cs 1])
   199                 (fn _=> [blast_tac HOL_cs 1])
   200 in  bind_thm("conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
   200 in  bind_thm("conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
   201 
   201 
   202 let val th = prove_goal HOL.thy 
   202 let val th = prove_goal HOL.thy 
   203                 "(Q=Q')--> (Q'--> (P=P'))--> ((P&Q) = (P'&Q'))"
   203                 "(Q=Q')--> (Q'--> (P=P'))--> ((P&Q) = (P'&Q'))"
   204                 (fn _=> [fast_tac HOL_cs 1])
   204                 (fn _=> [blast_tac HOL_cs 1])
   205 in  bind_thm("rev_conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
   205 in  bind_thm("rev_conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
   206 
   206 
   207 (* '|' congruence rule: not included by default! *)
   207 (* '|' congruence rule: not included by default! *)
   208 
   208 
   209 let val th = prove_goal HOL.thy 
   209 let val th = prove_goal HOL.thy 
   210                 "(P=P')--> (~P'--> (Q=Q'))--> ((P|Q) = (P'|Q'))"
   210                 "(P=P')--> (~P'--> (Q=Q'))--> ((P|Q) = (P'|Q'))"
   211                 (fn _=> [fast_tac HOL_cs 1])
   211                 (fn _=> [blast_tac HOL_cs 1])
   212 in  bind_thm("disj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
   212 in  bind_thm("disj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
   213 
   213 
   214 prove "eq_sym_conv" "(x=y) = (y=x)";
   214 prove "eq_sym_conv" "(x=y) = (y=x)";
   215 
   215 
   216 qed_goalw "o_apply" HOL.thy [o_def] "(f o g) x = f (g x)"
   216 qed_goalw "o_apply" HOL.thy [o_def] "(f o g) x = f (g x)"
   218 
   218 
   219 qed_goal "meta_eq_to_obj_eq" HOL.thy "x==y ==> x=y"
   219 qed_goal "meta_eq_to_obj_eq" HOL.thy "x==y ==> x=y"
   220   (fn [prem] => [rewtac prem, rtac refl 1]);
   220   (fn [prem] => [rewtac prem, rtac refl 1]);
   221 
   221 
   222 qed_goalw "if_True" HOL.thy [if_def] "(if True then x else y) = x"
   222 qed_goalw "if_True" HOL.thy [if_def] "(if True then x else y) = x"
   223  (fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]);
   223  (fn _=>[blast_tac (HOL_cs addIs [select_equality]) 1]);
   224 
   224 
   225 qed_goalw "if_False" HOL.thy [if_def] "(if False then x else y) = y"
   225 qed_goalw "if_False" HOL.thy [if_def] "(if False then x else y) = y"
   226  (fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]);
   226  (fn _=>[blast_tac (HOL_cs addIs [select_equality]) 1]);
   227 
   227 
   228 qed_goal "if_P" HOL.thy "P ==> (if P then x else y) = x"
   228 qed_goal "if_P" HOL.thy "P ==> (if P then x else y) = x"
   229  (fn [prem] => [ stac (prem RS eqTrueI) 1, rtac if_True 1 ]);
   229  (fn [prem] => [ stac (prem RS eqTrueI) 1, rtac if_True 1 ]);
   230 (*
   230 (*
   231 qed_goal "if_not_P" HOL.thy "~P ==> (if P then x else y) = y"
   231 qed_goal "if_not_P" HOL.thy "~P ==> (if P then x else y) = y"
   232  (fn [prem] => [ stac (prem RS not_P_imp_P_iff_F) 1, rtac if_False 1 ]);
   232  (fn [prem] => [ stac (prem RS not_P_imp_P_iff_F) 1, rtac if_False 1 ]);
   233 *)
   233 *)
   234 qed_goalw "if_not_P" HOL.thy [if_def] "!!P. ~P ==> (if P then x else y) = y"
   234 qed_goalw "if_not_P" HOL.thy [if_def] "!!P. ~P ==> (if P then x else y) = y"
   235  (fn _ => [fast_tac (HOL_cs addIs [select_equality]) 1]);
   235  (fn _ => [blast_tac (HOL_cs addIs [select_equality]) 1]);
   236 
   236 
   237 qed_goal "expand_if" HOL.thy
   237 qed_goal "expand_if" HOL.thy
   238     "P(if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
   238     "P(if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
   239  (fn _=> [ (res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1),
   239  (fn _=> [ (res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1),
   240          stac if_P 2,
   240          stac if_P 2,
   241          stac if_not_P 1,
   241          stac if_not_P 1,
   242          REPEAT(fast_tac HOL_cs 1) ]);
   242          REPEAT(blast_tac HOL_cs 1) ]);
   243 
   243 
   244 qed_goal "if_bool_eq" HOL.thy
   244 qed_goal "if_bool_eq" HOL.thy
   245                    "(if P then Q else R) = ((P-->Q) & (~P-->R))"
   245                    "(if P then Q else R) = ((P-->Q) & (~P-->R))"
   246                    (fn _ => [rtac expand_if 1]);
   246                    (fn _ => [rtac expand_if 1]);
   247 
   247 
   255 fun split_inside_tac splits = mktac (map mk_meta_eq splits)
   255 fun split_inside_tac splits = mktac (map mk_meta_eq splits)
   256 end;
   256 end;
   257 
   257 
   258 
   258 
   259 qed_goal "if_cancel" HOL.thy "(if c then x else x) = x"
   259 qed_goal "if_cancel" HOL.thy "(if c then x else x) = x"
   260   (fn _ => [split_tac [expand_if] 1, fast_tac HOL_cs 1]);
   260   (fn _ => [split_tac [expand_if] 1, blast_tac HOL_cs 1]);
   261 
   261 
   262 (** 'if' congruence rules: neither included by default! *)
   262 (** 'if' congruence rules: neither included by default! *)
   263 
   263 
   264 (*Simplifies x assuming c and y assuming ~c*)
   264 (*Simplifies x assuming c and y assuming ~c*)
   265 qed_goal "if_cong" HOL.thy
   265 qed_goal "if_cong" HOL.thy
   266   "[| b=c; c ==> x=u; ~c ==> y=v |] ==>\
   266   "[| b=c; c ==> x=u; ~c ==> y=v |] ==>\
   267 \  (if b then x else y) = (if c then u else v)"
   267 \  (if b then x else y) = (if c then u else v)"
   268   (fn rew::prems =>
   268   (fn rew::prems =>
   269    [stac rew 1, stac expand_if 1, stac expand_if 1,
   269    [stac rew 1, stac expand_if 1, stac expand_if 1,
   270     fast_tac (HOL_cs addDs prems) 1]);
   270     blast_tac (HOL_cs addDs prems) 1]);
   271 
   271 
   272 (*Prevents simplification of x and y: much faster*)
   272 (*Prevents simplification of x and y: much faster*)
   273 qed_goal "if_weak_cong" HOL.thy
   273 qed_goal "if_weak_cong" HOL.thy
   274   "b=c ==> (if b then x else y) = (if c then x else y)"
   274   "b=c ==> (if b then x else y) = (if c then x else y)"
   275   (fn [prem] => [rtac (prem RS arg_cong) 1]);
   275   (fn [prem] => [rtac (prem RS arg_cong) 1]);