tidied up
authorpaulson
Fri Mar 25 16:20:57 2005 +0100 (2005-03-25)
changeset 156289f912f8fd2df
parent 15627 7a108ae4c798
child 15629 4066f01f1beb
tidied up
src/HOL/Library/Primes.thy
src/HOL/NumberTheory/Fib.thy
     1.1 --- a/src/HOL/Library/Primes.thy	Fri Mar 25 14:14:01 2005 +0100
     1.2 +++ b/src/HOL/Library/Primes.thy	Fri Mar 25 16:20:57 2005 +0100
     1.3 @@ -210,11 +210,13 @@
     1.4    done
     1.5  
     1.6  lemma gcd_add2 [simp]: "gcd (m, m + n) = gcd (m, n)"
     1.7 -  apply (rule gcd_commute [THEN trans])
     1.8 -  apply (subst add_commute)
     1.9 -  apply (simp add: gcd_add1)
    1.10 -  apply (rule gcd_commute)
    1.11 -  done
    1.12 +proof -
    1.13 +  have "gcd (m, m + n) = gcd (m + n, m)" by (rule gcd_commute) 
    1.14 +  also have "... = gcd (n + m, m)" by (simp add: add_commute)
    1.15 +  also have "... = gcd (n, m)" by simp
    1.16 +  also have  "... = gcd (m, n)" by (rule gcd_commute) 
    1.17 +  finally show ?thesis .
    1.18 +qed
    1.19  
    1.20  lemma gcd_add2' [simp]: "gcd (m, n + m) = gcd (m, n)"
    1.21    apply (subst add_commute)
    1.22 @@ -223,7 +225,7 @@
    1.23  
    1.24  lemma gcd_add_mult: "gcd (m, k * m + n) = gcd (m, n)"
    1.25    apply (induct k)
    1.26 -   apply (simp_all add: gcd_add2 add_assoc)
    1.27 +   apply (simp_all add: add_assoc)
    1.28    done
    1.29  
    1.30  
    1.31 @@ -235,8 +237,8 @@
    1.32      apply (rule_tac n = k in relprime_dvd_mult)
    1.33       apply (simp add: gcd_assoc)
    1.34       apply (simp add: gcd_commute)
    1.35 -    apply (simp_all add: mult_commute gcd_dvd1 gcd_dvd2)
    1.36 -  apply (blast intro: gcd_dvd1 dvd_trans)
    1.37 +    apply (simp_all add: mult_commute)
    1.38 +  apply (blast intro: dvd_trans)
    1.39    done
    1.40  
    1.41  end
     2.1 --- a/src/HOL/NumberTheory/Fib.thy	Fri Mar 25 14:14:01 2005 +0100
     2.2 +++ b/src/HOL/NumberTheory/Fib.thy	Fri Mar 25 16:20:57 2005 +0100
     2.3 @@ -1,5 +1,4 @@
     2.4 -(*  Title:      HOL/NumberTheory/Fib.thy
     2.5 -    ID:         $Id$
     2.6 +(*  ID:         $Id$
     2.7      Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     2.8      Copyright   1997  University of Cambridge
     2.9  *)
    2.10 @@ -17,10 +16,10 @@
    2.11  *}
    2.12  
    2.13  consts fib :: "nat => nat"
    2.14 -recdef fib  less_than
    2.15 -  zero: "fib 0  = 0"
    2.16 -  one:  "fib (Suc 0) = Suc 0"
    2.17 -  Suc_Suc: "fib (Suc (Suc x)) = fib x + fib (Suc x)"
    2.18 +recdef fib  "measure (\<lambda>x. x)"
    2.19 +   zero:    "fib 0  = 0"
    2.20 +   one:     "fib (Suc 0) = Suc 0"
    2.21 +   Suc_Suc: "fib (Suc (Suc x)) = fib x + fib (Suc x)"
    2.22  
    2.23  text {*
    2.24    \medskip The difficulty in these proofs is to ensure that the
    2.25 @@ -29,11 +28,12 @@
    2.26    to the Simplifier and are applied very selectively at first.
    2.27  *}
    2.28  
    2.29 +text{*We disable @{text fib.Suc_Suc} for simplification ...*}
    2.30  declare fib.Suc_Suc [simp del]
    2.31  
    2.32 +text{*...then prove a version that has a more restrictive pattern.*}
    2.33  lemma fib_Suc3: "fib (Suc (Suc (Suc n))) = fib (Suc n) + fib (Suc (Suc n))"
    2.34 -  apply (rule fib.Suc_Suc)
    2.35 -  done
    2.36 +  by (rule fib.Suc_Suc)
    2.37  
    2.38  
    2.39  text {* \medskip Concrete Mathematics, page 280 *}
    2.40 @@ -42,45 +42,53 @@
    2.41    apply (induct n rule: fib.induct)
    2.42      prefer 3
    2.43      txt {* simplify the LHS just enough to apply the induction hypotheses *}
    2.44 -    apply (simp add: fib.Suc_Suc [of "Suc (m + n)", standard])
    2.45 -    apply (simp_all (no_asm_simp) add: fib.Suc_Suc add_mult_distrib add_mult_distrib2)
    2.46 +    apply (simp add: fib_Suc3)
    2.47 +    apply (simp_all add: fib.Suc_Suc add_mult_distrib2)
    2.48      done
    2.49  
    2.50 -lemma fib_Suc_neq_0 [simp]: "fib (Suc n) \<noteq> 0"
    2.51 +lemma fib_Suc_neq_0: "fib (Suc n) \<noteq> 0"
    2.52    apply (induct n rule: fib.induct)
    2.53      apply (simp_all add: fib.Suc_Suc)
    2.54    done
    2.55  
    2.56 -lemma [simp]: "0 < fib (Suc n)"
    2.57 -  apply (simp add: neq0_conv [symmetric])
    2.58 -  done
    2.59 +lemma fib_Suc_gr_0: "0 < fib (Suc n)"
    2.60 +  by (insert fib_Suc_neq_0 [of n], simp)  
    2.61  
    2.62  lemma fib_gr_0: "0 < n ==> 0 < fib n"
    2.63 -  apply (rule not0_implies_Suc [THEN exE])
    2.64 -   apply auto
    2.65 -  done
    2.66 +  by (case_tac n, auto simp add: fib_Suc_gr_0) 
    2.67  
    2.68  
    2.69  text {*
    2.70 -  \medskip Concrete Mathematics, page 278: Cassini's identity.  It is
    2.71 -  much easier to prove using integers!
    2.72 +  \medskip Concrete Mathematics, page 278: Cassini's identity.  The proof is
    2.73 +  much easier using integers, not natural numbers!
    2.74  *}
    2.75  
    2.76 -lemma fib_Cassini:
    2.77 +lemma fib_Cassini_int:
    2.78   "int (fib (Suc (Suc n)) * fib n) =
    2.79    (if n mod 2 = 0 then int (fib (Suc n) * fib (Suc n)) - 1
    2.80     else int (fib (Suc n) * fib (Suc n)) + 1)"
    2.81    apply (induct n rule: fib.induct)
    2.82      apply (simp add: fib.Suc_Suc)
    2.83     apply (simp add: fib.Suc_Suc mod_Suc)
    2.84 -  apply (simp add: fib.Suc_Suc
    2.85 -    add_mult_distrib add_mult_distrib2 mod_Suc zmult_int [symmetric] zmult_ac)
    2.86 -  apply (subgoal_tac "x mod 2 < 2", arith)
    2.87 -  apply simp
    2.88 +  apply (simp add: fib.Suc_Suc add_mult_distrib add_mult_distrib2
    2.89 +                   mod_Suc zmult_int [symmetric])
    2.90 +  apply presburger
    2.91 +  done
    2.92 +
    2.93 +text{*We now obtain a version for the natural numbers via the coercion 
    2.94 +   function @{term int}.*}
    2.95 +theorem fib_Cassini:
    2.96 + "fib (Suc (Suc n)) * fib n =
    2.97 +  (if n mod 2 = 0 then fib (Suc n) * fib (Suc n) - 1
    2.98 +   else fib (Suc n) * fib (Suc n) + 1)"
    2.99 +  apply (rule int_int_eq [THEN iffD1]) 
   2.100 +  apply (simp add: fib_Cassini_int) 
   2.101 +  apply (subst zdiff_int [symmetric]) 
   2.102 +   apply (insert fib_Suc_gr_0 [of n], simp_all)
   2.103    done
   2.104  
   2.105  
   2.106 -text {* \medskip Towards Law 6.111 of Concrete Mathematics *}
   2.107 +text {* \medskip Toward Law 6.111 of Concrete Mathematics *}
   2.108  
   2.109  lemma gcd_fib_Suc_eq_1: "gcd (fib n, fib (Suc n)) = Suc 0"
   2.110    apply (induct n rule: fib.induct)
   2.111 @@ -90,35 +98,29 @@
   2.112    done
   2.113  
   2.114  lemma gcd_fib_add: "gcd (fib m, fib (n + m)) = gcd (fib m, fib n)"
   2.115 -  apply (simp (no_asm) add: gcd_commute [of "fib m"])
   2.116 -  apply (case_tac "m = 0")
   2.117 -   apply simp
   2.118 -  apply (clarify dest!: not0_implies_Suc)
   2.119 +  apply (simp add: gcd_commute [of "fib m"])
   2.120 +  apply (case_tac m)
   2.121 +   apply simp 
   2.122    apply (simp add: fib_add)
   2.123 -  apply (simp add: add_commute gcd_non_0)
   2.124 -  apply (simp add: gcd_non_0 [symmetric])
   2.125 +  apply (simp add: add_commute gcd_non_0 [OF fib_Suc_gr_0])
   2.126 +  apply (simp add: gcd_non_0 [OF fib_Suc_gr_0, symmetric])
   2.127    apply (simp add: gcd_fib_Suc_eq_1 gcd_mult_cancel)
   2.128    done
   2.129  
   2.130  lemma gcd_fib_diff: "m \<le> n ==> gcd (fib m, fib (n - m)) = gcd (fib m, fib n)"
   2.131 -  apply (rule gcd_fib_add [symmetric, THEN trans])
   2.132 -  apply simp
   2.133 -  done
   2.134 +  by (simp add: gcd_fib_add [symmetric, of _ "n-m"]) 
   2.135  
   2.136  lemma gcd_fib_mod: "0 < m ==> gcd (fib m, fib (n mod m)) = gcd (fib m, fib n)"
   2.137    apply (induct n rule: nat_less_induct)
   2.138 -  apply (subst mod_if)
   2.139 -  apply (simp add: gcd_fib_diff mod_geq not_less_iff_le)
   2.140 +  apply (simp add: mod_if gcd_fib_diff mod_geq)
   2.141    done
   2.142  
   2.143  lemma fib_gcd: "fib (gcd (m, n)) = gcd (fib m, fib n)"  -- {* Law 6.111 *}
   2.144    apply (induct m n rule: gcd_induct)
   2.145 -   apply simp
   2.146 -  apply (simp add: gcd_non_0)
   2.147 -  apply (simp add: gcd_commute gcd_fib_mod)
   2.148 +  apply (simp_all add: gcd_non_0 gcd_commute gcd_fib_mod)
   2.149    done
   2.150  
   2.151 -lemma fib_mult_eq_setsum:
   2.152 +theorem fib_mult_eq_setsum:
   2.153      "fib (Suc n) * fib n = (\<Sum>k \<in> {..n}. fib k * fib k)"
   2.154    apply (induct n rule: fib.induct)
   2.155      apply (auto simp add: atMost_Suc fib.Suc_Suc)