src/HOL/simpdata.ML
changeset 1922 ce495557ac33
parent 1892 23765bc3e8e2
child 1948 78e5bfcbc1e9
     1.1 --- a/src/HOL/simpdata.ML	Mon Aug 19 13:03:17 1996 +0200
     1.2 +++ b/src/HOL/simpdata.ML	Mon Aug 19 13:06:30 1996 +0200
     1.3 @@ -8,59 +8,71 @@
     1.4  
     1.5  open Simplifier;
     1.6  
     1.7 +(*** Integration of simplifier with classical reasoner ***)
     1.8 +
     1.9 +(*Add a simpset to a classical set!*)
    1.10 +infix 4 addss;
    1.11 +fun cs addss ss = cs addbefore asm_full_simp_tac ss 1;
    1.12 +
    1.13 +fun Addss ss = (claset := !claset addbefore asm_full_simp_tac ss 1);
    1.14 +
    1.15 +(*Maybe swap the safe_tac and simp_tac lines?**)
    1.16 +fun auto_tac (cs,ss) = 
    1.17 +    TRY (safe_tac cs) THEN 
    1.18 +    ALLGOALS (asm_full_simp_tac ss) THEN
    1.19 +    REPEAT (FIRSTGOAL (best_tac (cs addss ss)));
    1.20 +
    1.21 +fun Auto_tac() = auto_tac (!claset, !simpset);
    1.22 +
    1.23 +fun auto() = by (Auto_tac());
    1.24 +
    1.25 +
    1.26  local
    1.27  
    1.28 -fun prover s = prove_goal HOL.thy s (fn _ => [fast_tac HOL_cs 1]);
    1.29 +  fun prover s = prove_goal HOL.thy s (fn _ => [fast_tac HOL_cs 1]);
    1.30  
    1.31 -val P_imp_P_iff_True = prover "P --> (P = True)" RS mp;
    1.32 -val P_imp_P_eq_True = P_imp_P_iff_True RS eq_reflection;
    1.33 +  val P_imp_P_iff_True = prover "P --> (P = True)" RS mp;
    1.34 +  val P_imp_P_eq_True = P_imp_P_iff_True RS eq_reflection;
    1.35  
    1.36 -val not_P_imp_P_iff_F = prover "~P --> (P = False)" RS mp;
    1.37 -val not_P_imp_P_eq_False = not_P_imp_P_iff_F RS eq_reflection;
    1.38 +  val not_P_imp_P_iff_F = prover "~P --> (P = False)" RS mp;
    1.39 +  val not_P_imp_P_eq_False = not_P_imp_P_iff_F RS eq_reflection;
    1.40  
    1.41 -fun atomize pairs =
    1.42 -  let fun atoms th =
    1.43 -        (case concl_of th of
    1.44 -           Const("Trueprop",_) $ p =>
    1.45 -             (case head_of p of
    1.46 -                Const(a,_) =>
    1.47 -                  (case assoc(pairs,a) of
    1.48 -                     Some(rls) => flat (map atoms ([th] RL rls))
    1.49 -                   | None => [th])
    1.50 -              | _ => [th])
    1.51 -         | _ => [th])
    1.52 -  in atoms end;
    1.53 +  fun atomize pairs =
    1.54 +    let fun atoms th =
    1.55 +	  (case concl_of th of
    1.56 +	     Const("Trueprop",_) $ p =>
    1.57 +	       (case head_of p of
    1.58 +		  Const(a,_) =>
    1.59 +		    (case assoc(pairs,a) of
    1.60 +		       Some(rls) => flat (map atoms ([th] RL rls))
    1.61 +		     | None => [th])
    1.62 +		| _ => [th])
    1.63 +	   | _ => [th])
    1.64 +    in atoms end;
    1.65  
    1.66 -fun mk_meta_eq r = case concl_of r of
    1.67 -        Const("==",_)$_$_ => r
    1.68 -    |   _$(Const("op =",_)$_$_) => r RS eq_reflection
    1.69 -    |   _$(Const("not",_)$_) => r RS not_P_imp_P_eq_False
    1.70 -    |   _ => r RS P_imp_P_eq_True;
    1.71 -(* last 2 lines requires all formulae to be of the from Trueprop(.) *)
    1.72 +  fun mk_meta_eq r = case concl_of r of
    1.73 +	  Const("==",_)$_$_ => r
    1.74 +      |   _$(Const("op =",_)$_$_) => r RS eq_reflection
    1.75 +      |   _$(Const("not",_)$_) => r RS not_P_imp_P_eq_False
    1.76 +      |   _ => r RS P_imp_P_eq_True;
    1.77 +  (* last 2 lines requires all formulae to be of the from Trueprop(.) *)
    1.78  
    1.79 -fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th;
    1.80 -
    1.81 -val imp_cong = impI RSN
    1.82 -    (2, prove_goal HOL.thy "(P=P')--> (P'--> (Q=Q'))--> ((P-->Q) = (P'-->Q'))"
    1.83 -        (fn _=> [fast_tac HOL_cs 1]) RS mp RS mp);
    1.84 +  fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th;
    1.85  
    1.86 -val o_apply = prove_goalw HOL.thy [o_def] "(f o g)(x) = f(g(x))"
    1.87 - (fn _ => [rtac refl 1]);
    1.88 -
    1.89 -val simp_thms = map prover
    1.90 - [ "(x=x) = True",
    1.91 -   "(~True) = False", "(~False) = True", "(~ ~ P) = P",
    1.92 -   "(~P) ~= P", "P ~= (~P)", "(P ~= Q) = (P = (~Q))",
    1.93 -   "(True=P) = P", "(P=True) = P",
    1.94 -   "(True --> P) = P", "(False --> P) = True", 
    1.95 -   "(P --> True) = True", "(P --> P) = True",
    1.96 -   "(P --> False) = (~P)", "(P --> ~P) = (~P)",
    1.97 -   "(P & True) = P", "(True & P) = P", 
    1.98 -   "(P & False) = False", "(False & P) = False", "(P & P) = P",
    1.99 -   "(P | True) = True", "(True | P) = True", 
   1.100 -   "(P | False) = P", "(False | P) = P", "(P | P) = P",
   1.101 -   "(!x.P) = P", "(? x.P) = P", "? x. x=t", "(? x. x=t & P(x)) = P(t)",
   1.102 -   "(P|Q --> R) = ((P-->R)&(Q-->R))" ];
   1.103 +  val simp_thms = map prover
   1.104 +   [ "(x=x) = True",
   1.105 +     "(~True) = False", "(~False) = True", "(~ ~ P) = P",
   1.106 +     "(~P) ~= P", "P ~= (~P)", "(P ~= Q) = (P = (~Q))",
   1.107 +     "(True=P) = P", "(P=True) = P",
   1.108 +     "(True --> P) = P", "(False --> P) = True", 
   1.109 +     "(P --> True) = True", "(P --> P) = True",
   1.110 +     "(P --> False) = (~P)", "(P --> ~P) = (~P)",
   1.111 +     "(P & True) = P", "(True & P) = P", 
   1.112 +     "(P & False) = False", "(False & P) = False", "(P & P) = P",
   1.113 +     "(P | True) = True", "(True | P) = True", 
   1.114 +     "(P | False) = P", "(False | P) = P", "(P | P) = P",
   1.115 +     "(!x.P) = P", "(? x.P) = P", "? x. x=t", 
   1.116 +     "(? x. x=t & P(x)) = P(t)", "(! x. x=t --> P(x)) = P(t)" ];
   1.117  
   1.118  in
   1.119  
   1.120 @@ -71,6 +83,11 @@
   1.121  
   1.122  val conj_assoc = prover "((P&Q)&R) = (P&(Q&R))";
   1.123  
   1.124 +val disj_assoc = prover "((P|Q)|R) = (P|(Q|R))";
   1.125 +
   1.126 +val imp_disj   = prover "(P|Q --> R) = ((P-->R)&(Q-->R))";
   1.127 +
   1.128 +
   1.129  val if_True = prove_goalw HOL.thy [if_def] "(if True then x else y) = x"
   1.130   (fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]);
   1.131  
   1.132 @@ -100,12 +117,6 @@
   1.133  
   1.134  fun Addcongs congs = (simpset := !simpset addcongs congs);
   1.135  
   1.136 -(*Add a simpset to a classical set!*)
   1.137 -infix 4 addss;
   1.138 -fun cs addss ss = cs addbefore asm_full_simp_tac ss 1;
   1.139 -
   1.140 -fun Addss ss = (claset := !claset addbefore asm_full_simp_tac ss 1);
   1.141 -
   1.142  val mksimps_pairs =
   1.143    [("op -->", [mp]), ("op &", [conjunct1,conjunct2]),
   1.144     ("All", [spec]), ("True", []), ("False", []),
   1.145 @@ -113,14 +124,30 @@
   1.146  
   1.147  fun mksimps pairs = map mk_meta_eq o atomize pairs o gen_all;
   1.148  
   1.149 +val imp_cong = impI RSN
   1.150 +    (2, prove_goal HOL.thy "(P=P')--> (P'--> (Q=Q'))--> ((P-->Q) = (P'-->Q'))"
   1.151 +        (fn _=> [fast_tac HOL_cs 1]) RS mp RS mp);
   1.152 +
   1.153 +val o_apply = prove_goalw HOL.thy [o_def] "(f o g)(x) = f(g(x))"
   1.154 + (fn _ => [rtac refl 1]);
   1.155 +
   1.156  val HOL_ss = empty_ss
   1.157        setmksimps (mksimps mksimps_pairs)
   1.158        setsolver (fn prems => resolve_tac (TrueI::refl::prems) ORELSE' atac
   1.159                               ORELSE' etac FalseE)
   1.160        setsubgoaler asm_simp_tac
   1.161 -      addsimps ([if_True, if_False, o_apply, conj_assoc] @ simp_thms)
   1.162 +      addsimps ([if_True, if_False, o_apply, imp_disj, conj_assoc, disj_assoc]
   1.163 +        @ simp_thms)
   1.164        addcongs [imp_cong];
   1.165  
   1.166 +
   1.167 +(*In general it seems wrong to add distributive laws by default: they
   1.168 +  might cause exponential blow-up.  This one has been added for a while
   1.169 +  and cannot be removed without affecting existing proofs.  Moreover, 
   1.170 +  rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the
   1.171 +  grounds that it allows simplification of R in the two cases.*)
   1.172 +
   1.173 +
   1.174  local val mktac = mk_case_split_tac (meta_eq_to_obj_eq RS iffD2)
   1.175  in
   1.176  fun split_tac splits = mktac (map mk_meta_eq splits)
   1.177 @@ -182,6 +209,10 @@
   1.178  prove "conj_left_commute" "(P&(Q&R)) = (Q&(P&R))";
   1.179  val conj_comms = [conj_commute, conj_left_commute];
   1.180  
   1.181 +prove "disj_commute" "(P|Q) = (Q|P)";
   1.182 +prove "disj_left_commute" "(P|(Q|R)) = (Q|(P|R))";
   1.183 +val disj_comms = [disj_commute, disj_left_commute];
   1.184 +
   1.185  prove "conj_disj_distribL" "(P&(Q|R)) = (P&Q | P&R)";
   1.186  prove "conj_disj_distribR" "((P|Q)&R) = (P&R | Q&R)";
   1.187  
   1.188 @@ -189,18 +220,20 @@
   1.189  prove "disj_conj_distribR" "((P&Q)|R) = ((P|R) & (Q|R))";
   1.190  
   1.191  prove "imp_conj_distrib" "(P --> (Q&R)) = ((P-->Q) & (P-->R))";
   1.192 -prove "imp_conj_assoc"   "((P&Q)-->R)   = (P --> (Q --> R))";
   1.193 +prove "imp_conj"         "((P&Q)-->R)   = (P --> (Q --> R))";
   1.194  
   1.195  prove "de_Morgan_disj" "(~(P | Q)) = (~P & ~Q)";
   1.196  prove "de_Morgan_conj" "(~(P & Q)) = (~P | ~Q)";
   1.197 +prove "not_iff" "(P~=Q) = (P = (~Q))";
   1.198  
   1.199  prove "not_all" "(~ (! x.P(x))) = (? x.~P(x))";
   1.200 +prove "imp_all" "((! x. P x) --> Q) = (? x. P x --> Q)";
   1.201  prove "not_ex"  "(~ (? x.P(x))) = (! x.~P(x))";
   1.202 +prove "imp_ex" "((? x. P x) --> Q) = (! x. P x --> Q)";
   1.203  
   1.204  prove "ex_disj_distrib" "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))";
   1.205  prove "all_conj_distrib" "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))";
   1.206  
   1.207 -prove "ex_imp" "((? x. P x) --> Q) = (!x. P x --> Q)";
   1.208  
   1.209  qed_goal "if_cancel" HOL.thy "(if c then x else x) = x"
   1.210    (fn _ => [simp_tac (HOL_ss setloop (split_tac [expand_if])) 1]);