IOA/example/Lemmas.ML
changeset 156 fd1be45b64bf
child 168 44ff2275d44f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IOA/example/Lemmas.ML	Wed Nov 02 11:50:09 1994 +0100
@@ -0,0 +1,245 @@
+(* Logic *)
+val prems = goal HOL.thy "(P ==> Q-->R) ==> P&Q --> R";
+  by(fast_tac (HOL_cs addDs prems) 1);
+val imp_conj_lemma = result();
+
+goal HOL.thy "(P --> (? x. Q(x))) = (? x. P --> Q(x))";
+  by(fast_tac HOL_cs 1);
+val imp_ex_equiv = result();
+
+goal HOL.thy "(A --> B & C) = ((A --> B) & (A --> C))";
+  by (fast_tac HOL_cs 1);
+val fork_lemma = result();
+
+goal HOL.thy "((A --> B) & (C --> B)) = ((A | C) --> B)";
+  by (fast_tac HOL_cs 1);
+val imp_or_lem = result();
+
+goal HOL.thy "(X = (~ Y)) = ((~X) = Y)";
+  by (fast_tac HOL_cs 1);
+val neg_flip = result();
+
+goal HOL.thy "P --> Q(M) --> Q(if(P,M,N))";
+  by (rtac impI 1); 
+  by (rtac impI 1);
+  by (rtac (expand_if RS iffD2) 1);
+  by (fast_tac HOL_cs 1);
+val imp_true_decompose = result();
+
+goal HOL.thy "(~P) --> Q(N) --> Q(if(P,M,N))";
+  by (rtac impI 1); 
+  by (rtac impI 1);
+  by (rtac (expand_if RS iffD2) 1);
+  by (fast_tac HOL_cs 1);
+val imp_false_decompose = result();
+
+
+(* Sets *)
+val set_lemmas =
+   map (fn s => prove_goal Set.thy s (fn _ => [fast_tac set_cs 1]))
+        ["f(x) : (UN x. {f(x)})",
+         "f(x,y) : (UN x y. {f(x,y)})",
+         "!!a. (!x. a ~= f(x)) ==> a ~: (UN x. {f(x)})",
+         "!!a. (!x y. a ~= f(x,y)) ==> a ~: (UN x y. {f(x,y)})"];
+
+
+(* Arithmetic *)
+goal Arith.thy "n ~= 0 --> Suc(m+pred(n)) = m+n";
+  by (nat_ind_tac "n" 1);
+  by (REPEAT(simp_tac arith_ss 1));
+val Suc_pred_lemma = result() RS mp;
+
+goal Arith.thy "x <= y --> x <= Suc(y)";
+  by (rtac impI 1);
+  by (rtac (le_eq_less_or_eq RS iffD2) 1);
+  by (rtac disjI1 1);
+  by (dtac (le_eq_less_or_eq RS iffD1) 1);
+  by (etac disjE 1);
+  by (etac less_SucI 1);
+  by (asm_simp_tac nat_ss 1);
+val leq_imp_leq_suc = result() RS mp;
+
+(* Same as previous! *)
+goal Arith.thy "(x::nat)<=y --> x<=Suc(y)";
+  by (simp_tac (arith_ss addsimps [le_eq_less_or_eq]) 1);
+val leq_suc = result();
+
+goal Arith.thy "((m::nat) + n = m + p) = (n = p)";
+  by (nat_ind_tac "m" 1);
+  by (simp_tac arith_ss 1);
+  by (asm_simp_tac arith_ss 1);
+val left_plus_cancel = result();
+
+goal Arith.thy "((x::nat) + y = Suc(x + z)) = (y = Suc(z))";
+  by (nat_ind_tac "x" 1);
+  by (simp_tac arith_ss 1);
+  by (asm_simp_tac arith_ss 1);
+val left_plus_cancel_inside_succ = result();
+
+goal Arith.thy "(x ~= 0) = (? y. x = Suc(y))";
+  by (nat_ind_tac "x" 1);
+  by (simp_tac arith_ss 1);
+  by (asm_simp_tac arith_ss 1);
+  by (fast_tac HOL_cs 1);
+val nonzero_is_succ = result();
+
+goal Arith.thy "(m::nat) < n --> m + p < n + p";
+  by (nat_ind_tac "p" 1);
+  by (simp_tac arith_ss 1);
+  by (asm_simp_tac arith_ss 1);
+val less_add_same_less = result();
+
+goal Arith.thy "(x::nat)<= y --> x<=y+k";
+  by (nat_ind_tac "k" 1);
+  by (simp_tac arith_ss 1);
+  by (asm_full_simp_tac (arith_ss addsimps [leq_suc]) 1);
+val leq_add_leq = result();
+
+goal Arith.thy "(x::nat) + y <= z --> x <= z";
+  by (nat_ind_tac "y" 1);
+  by (simp_tac arith_ss 1);
+  by (asm_simp_tac arith_ss 1);
+  by (rtac impI 1);
+  by (dtac Suc_leD 1);
+  by (fast_tac HOL_cs 1);
+val left_add_leq = result();
+
+goal Arith.thy "(A::nat) < B --> C < D --> A + C < B + D";
+ by (rtac impI 1);
+ by (rtac impI 1);
+ by (rtac less_trans 1);
+ by (rtac (less_add_same_less RS mp) 1);
+ by (assume_tac 1);
+ by (rtac (add_commute RS ssubst)1);;
+ by (res_inst_tac [("m1","B")] (add_commute RS ssubst) 1);
+ by (rtac (less_add_same_less RS mp) 1);
+ by (assume_tac 1);
+val less_add_cong = result();
+
+goal Nat.thy "!!i. [| i < j; j <= k |] ==> i < (k::nat)";
+  by (dtac le_imp_less_or_eq 1);
+  by (fast_tac (HOL_cs addIs [less_trans]) 1);
+val less_leq_less = result();
+
+goal Arith.thy "(A::nat) <= B --> C <= D --> A + C <= B + D";
+  by (rtac impI 1);
+  by (rtac impI 1);
+  by (asm_full_simp_tac (arith_ss addsimps [le_eq_less_or_eq]) 1);
+  by (safe_tac HOL_cs);
+  by (rtac (less_add_cong RS mp RS mp) 1);
+  by (assume_tac 1);
+  by (assume_tac 1);
+  by (rtac (less_add_same_less RS mp) 1);
+  by (assume_tac 1);
+  by (rtac (add_commute RS ssubst)1);;
+  by (res_inst_tac [("m1","B")] (add_commute RS ssubst) 1);
+  by (rtac (less_add_same_less RS mp) 1);
+  by (assume_tac 1);
+val less_eq_add_cong = result();
+
+goal Arith.thy "(w <= y) --> ((x::nat) + y <= z) --> (x + w <= z)";
+  by (rtac impI 1); 
+  by (dtac (less_eq_add_cong RS mp) 1);
+  by (cut_facts_tac [le_refl] 1);
+  by (dres_inst_tac [("P","x<=x")] mp 1);by (assume_tac 1);
+  by (asm_full_simp_tac (HOL_ss addsimps [add_commute]) 1);
+  by (rtac impI 1);
+  by (etac le_trans 1);
+  by (assume_tac 1);
+val leq_add_left_cong = result();
+
+goal Arith.thy "(? x. y = Suc(x)) = (~(y = 0))";
+  by (nat_ind_tac "y" 1);
+  by (simp_tac arith_ss 1);
+  by (rtac iffI 1);
+  by (asm_full_simp_tac arith_ss 1);
+  by (fast_tac HOL_cs 1);
+val suc_not_zero = result();
+
+goal Arith.thy "Suc(x) <= y --> (? z. y = Suc(z))";
+  by (rtac impI 1);
+  by (asm_full_simp_tac (arith_ss addsimps [le_eq_less_or_eq]) 1);
+  by (safe_tac HOL_cs);
+  by (fast_tac HOL_cs 2);
+  by (asm_simp_tac (arith_ss addsimps [suc_not_zero]) 1);
+  by (rtac ccontr 1);
+  by (asm_full_simp_tac (arith_ss addsimps [suc_not_zero]) 1);
+  by (hyp_subst_tac 1);
+  by (asm_full_simp_tac arith_ss 1);
+val suc_leq_suc = result();
+
+goal Arith.thy "~0<n --> n = 0";
+  by (nat_ind_tac "n" 1);
+  by (asm_simp_tac arith_ss 1);
+  by (safe_tac HOL_cs);
+  by (asm_full_simp_tac arith_ss 1);
+  by (asm_full_simp_tac arith_ss 1);
+val zero_eq = result();
+
+goal Arith.thy "x < Suc(y) --> x<=y";
+  by (nat_ind_tac "n" 1);
+  by (asm_simp_tac arith_ss 1);
+  by (safe_tac HOL_cs);
+  by (etac less_imp_le 1);
+val less_suc_imp_leq = result();
+
+goal Arith.thy "0<x --> Suc(pred(x)) = x";
+  by (nat_ind_tac "x" 1);
+  by (simp_tac arith_ss 1);
+  by (asm_simp_tac arith_ss 1);
+val suc_pred_id = result();
+
+goal Arith.thy "0<x --> (pred(x) = y) = (x = Suc(y))";
+  by (nat_ind_tac "x" 1);
+  by (simp_tac arith_ss 1);
+  by (asm_simp_tac arith_ss 1);
+val pred_suc = result();
+
+goal Arith.thy "(x ~= 0) = (0<x)";
+  by (nat_ind_tac "x" 1);
+  by (simp_tac arith_ss 1);
+  by (asm_simp_tac arith_ss 1);
+val unzero_less = result();
+
+(* Duplicate of earlier lemma! *)
+goal Arith.thy "x<(y::nat) --> y<=z --> x<(z::nat)";
+  by (rtac impI 1); by (rtac impI 1);
+  by (dtac  le_imp_less_or_eq 1);
+  by (fast_tac (HOL_cs addIs [less_trans]) 1);
+val less_leq_less = result();
+
+goal Arith.thy "(Suc(n) <= Suc(m)) = (n <= m)";
+  by (simp_tac (arith_ss addsimps [le_eq_less_or_eq]) 1);
+val succ_leq_mono = result();
+
+(* Odd proof. Why do induction? *)
+goal Arith.thy "((x::nat) = y + z) --> (y <= x)";
+  by (nat_ind_tac "y" 1);
+  by (simp_tac arith_ss 1);
+  by (simp_tac (arith_ss addsimps 
+                [succ_leq_mono, le_refl RS (leq_add_leq RS mp)]) 1);
+val plus_leq_lem = result();
+
+(* Lists *)
+
+goal List.thy "(L @ (x#M)) ~= []";
+  by (list_ind_tac "L" 1);
+  by (simp_tac list_ss 1);
+  by (asm_simp_tac list_ss 1);
+val append_cons = result();
+
+goal List.thy "(X ~= hd(L@M)) = (X ~= if(L = [], hd(M), hd(L)))";
+  by (list_ind_tac "L" 1);
+  by (simp_tac list_ss 1);
+  by (asm_full_simp_tac list_ss 1);
+val not_hd_append = result();
+
+goal List.thy "(L = (x#rst)) --> (L = []) --> P";
+  by (simp_tac list_ss 1);
+val list_cases = result();
+
+goal List.thy "(? L2. L1 = x#L2) --> (L1 ~= [])";
+  by (strip_tac 1);
+  by (etac exE 1);
+  by (asm_simp_tac list_ss 1);
+val cons_imp_not_null = result();