--- a/src/HOL/Library/Primes.thy Fri Mar 25 14:14:01 2005 +0100
+++ b/src/HOL/Library/Primes.thy Fri Mar 25 16:20:57 2005 +0100
@@ -210,11 +210,13 @@
done
lemma gcd_add2 [simp]: "gcd (m, m + n) = gcd (m, n)"
- apply (rule gcd_commute [THEN trans])
- apply (subst add_commute)
- apply (simp add: gcd_add1)
- apply (rule gcd_commute)
- done
+proof -
+ have "gcd (m, m + n) = gcd (m + n, m)" by (rule gcd_commute)
+ also have "... = gcd (n + m, m)" by (simp add: add_commute)
+ also have "... = gcd (n, m)" by simp
+ also have "... = gcd (m, n)" by (rule gcd_commute)
+ finally show ?thesis .
+qed
lemma gcd_add2' [simp]: "gcd (m, n + m) = gcd (m, n)"
apply (subst add_commute)
@@ -223,7 +225,7 @@
lemma gcd_add_mult: "gcd (m, k * m + n) = gcd (m, n)"
apply (induct k)
- apply (simp_all add: gcd_add2 add_assoc)
+ apply (simp_all add: add_assoc)
done
@@ -235,8 +237,8 @@
apply (rule_tac n = k in relprime_dvd_mult)
apply (simp add: gcd_assoc)
apply (simp add: gcd_commute)
- apply (simp_all add: mult_commute gcd_dvd1 gcd_dvd2)
- apply (blast intro: gcd_dvd1 dvd_trans)
+ apply (simp_all add: mult_commute)
+ apply (blast intro: dvd_trans)
done
end
--- a/src/HOL/NumberTheory/Fib.thy Fri Mar 25 14:14:01 2005 +0100
+++ b/src/HOL/NumberTheory/Fib.thy Fri Mar 25 16:20:57 2005 +0100
@@ -1,5 +1,4 @@
-(* Title: HOL/NumberTheory/Fib.thy
- ID: $Id$
+(* ID: $Id$
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
Copyright 1997 University of Cambridge
*)
@@ -17,10 +16,10 @@
*}
consts fib :: "nat => nat"
-recdef fib less_than
- zero: "fib 0 = 0"
- one: "fib (Suc 0) = Suc 0"
- Suc_Suc: "fib (Suc (Suc x)) = fib x + fib (Suc x)"
+recdef fib "measure (\<lambda>x. x)"
+ zero: "fib 0 = 0"
+ one: "fib (Suc 0) = Suc 0"
+ Suc_Suc: "fib (Suc (Suc x)) = fib x + fib (Suc x)"
text {*
\medskip The difficulty in these proofs is to ensure that the
@@ -29,11 +28,12 @@
to the Simplifier and are applied very selectively at first.
*}
+text{*We disable @{text fib.Suc_Suc} for simplification ...*}
declare fib.Suc_Suc [simp del]
+text{*...then prove a version that has a more restrictive pattern.*}
lemma fib_Suc3: "fib (Suc (Suc (Suc n))) = fib (Suc n) + fib (Suc (Suc n))"
- apply (rule fib.Suc_Suc)
- done
+ by (rule fib.Suc_Suc)
text {* \medskip Concrete Mathematics, page 280 *}
@@ -42,45 +42,53 @@
apply (induct n rule: fib.induct)
prefer 3
txt {* simplify the LHS just enough to apply the induction hypotheses *}
- apply (simp add: fib.Suc_Suc [of "Suc (m + n)", standard])
- apply (simp_all (no_asm_simp) add: fib.Suc_Suc add_mult_distrib add_mult_distrib2)
+ apply (simp add: fib_Suc3)
+ apply (simp_all add: fib.Suc_Suc add_mult_distrib2)
done
-lemma fib_Suc_neq_0 [simp]: "fib (Suc n) \<noteq> 0"
+lemma fib_Suc_neq_0: "fib (Suc n) \<noteq> 0"
apply (induct n rule: fib.induct)
apply (simp_all add: fib.Suc_Suc)
done
-lemma [simp]: "0 < fib (Suc n)"
- apply (simp add: neq0_conv [symmetric])
- done
+lemma fib_Suc_gr_0: "0 < fib (Suc n)"
+ by (insert fib_Suc_neq_0 [of n], simp)
lemma fib_gr_0: "0 < n ==> 0 < fib n"
- apply (rule not0_implies_Suc [THEN exE])
- apply auto
- done
+ by (case_tac n, auto simp add: fib_Suc_gr_0)
text {*
- \medskip Concrete Mathematics, page 278: Cassini's identity. It is
- much easier to prove using integers!
+ \medskip Concrete Mathematics, page 278: Cassini's identity. The proof is
+ much easier using integers, not natural numbers!
*}
-lemma fib_Cassini:
+lemma fib_Cassini_int:
"int (fib (Suc (Suc n)) * fib n) =
(if n mod 2 = 0 then int (fib (Suc n) * fib (Suc n)) - 1
else int (fib (Suc n) * fib (Suc n)) + 1)"
apply (induct n rule: fib.induct)
apply (simp add: fib.Suc_Suc)
apply (simp add: fib.Suc_Suc mod_Suc)
- apply (simp add: fib.Suc_Suc
- add_mult_distrib add_mult_distrib2 mod_Suc zmult_int [symmetric] zmult_ac)
- apply (subgoal_tac "x mod 2 < 2", arith)
- apply simp
+ apply (simp add: fib.Suc_Suc add_mult_distrib add_mult_distrib2
+ mod_Suc zmult_int [symmetric])
+ apply presburger
+ done
+
+text{*We now obtain a version for the natural numbers via the coercion
+ function @{term int}.*}
+theorem fib_Cassini:
+ "fib (Suc (Suc n)) * fib n =
+ (if n mod 2 = 0 then fib (Suc n) * fib (Suc n) - 1
+ else fib (Suc n) * fib (Suc n) + 1)"
+ apply (rule int_int_eq [THEN iffD1])
+ apply (simp add: fib_Cassini_int)
+ apply (subst zdiff_int [symmetric])
+ apply (insert fib_Suc_gr_0 [of n], simp_all)
done
-text {* \medskip Towards Law 6.111 of Concrete Mathematics *}
+text {* \medskip Toward Law 6.111 of Concrete Mathematics *}
lemma gcd_fib_Suc_eq_1: "gcd (fib n, fib (Suc n)) = Suc 0"
apply (induct n rule: fib.induct)
@@ -90,35 +98,29 @@
done
lemma gcd_fib_add: "gcd (fib m, fib (n + m)) = gcd (fib m, fib n)"
- apply (simp (no_asm) add: gcd_commute [of "fib m"])
- apply (case_tac "m = 0")
- apply simp
- apply (clarify dest!: not0_implies_Suc)
+ apply (simp add: gcd_commute [of "fib m"])
+ apply (case_tac m)
+ apply simp
apply (simp add: fib_add)
- apply (simp add: add_commute gcd_non_0)
- apply (simp add: gcd_non_0 [symmetric])
+ apply (simp add: add_commute gcd_non_0 [OF fib_Suc_gr_0])
+ apply (simp add: gcd_non_0 [OF fib_Suc_gr_0, symmetric])
apply (simp add: gcd_fib_Suc_eq_1 gcd_mult_cancel)
done
lemma gcd_fib_diff: "m \<le> n ==> gcd (fib m, fib (n - m)) = gcd (fib m, fib n)"
- apply (rule gcd_fib_add [symmetric, THEN trans])
- apply simp
- done
+ by (simp add: gcd_fib_add [symmetric, of _ "n-m"])
lemma gcd_fib_mod: "0 < m ==> gcd (fib m, fib (n mod m)) = gcd (fib m, fib n)"
apply (induct n rule: nat_less_induct)
- apply (subst mod_if)
- apply (simp add: gcd_fib_diff mod_geq not_less_iff_le)
+ apply (simp add: mod_if gcd_fib_diff mod_geq)
done
lemma fib_gcd: "fib (gcd (m, n)) = gcd (fib m, fib n)" -- {* Law 6.111 *}
apply (induct m n rule: gcd_induct)
- apply simp
- apply (simp add: gcd_non_0)
- apply (simp add: gcd_commute gcd_fib_mod)
+ apply (simp_all add: gcd_non_0 gcd_commute gcd_fib_mod)
done
-lemma fib_mult_eq_setsum:
+theorem fib_mult_eq_setsum:
"fib (Suc n) * fib n = (\<Sum>k \<in> {..n}. fib k * fib k)"
apply (induct n rule: fib.induct)
apply (auto simp add: atMost_Suc fib.Suc_Suc)