src/HOL/Algebra/Exponent.thy
author ballarin
Thu Aug 03 14:57:26 2006 +0200 (2006-08-03)
changeset 20318 0e0ea63fe768
parent 20282 49c312eaaa11
child 20432 07ec57376051
permissions -rw-r--r--
Restructured algebra library, added ideals and quotient rings.
     1 (*  Title:      HOL/Algebra/Exponent.thy
     2     ID:         $Id$
     3     Author:     Florian Kammueller, with new proofs by L C Paulson
     4 
     5     exponent p s   yields the greatest power of p that divides s.
     6 *)
     7 
     8 theory Exponent imports Main Primes begin
     9 
    10 
    11 section {*The Combinatorial Argument Underlying the First Sylow Theorem*}
    12 constdefs
    13   exponent      :: "[nat, nat] => nat"
    14   "exponent p s == if prime p then (GREATEST r. p^r dvd s) else 0"
    15 
    16 
    17 subsection{*Prime Theorems*}
    18 
    19 lemma prime_imp_one_less: "prime p ==> Suc 0 < p"
    20 by (unfold prime_def, force)
    21 
    22 lemma prime_iff:
    23      "(prime p) = (Suc 0 < p & (\<forall>a b. p dvd a*b --> (p dvd a) | (p dvd b)))"
    24 apply (auto simp add: prime_imp_one_less)
    25 apply (blast dest!: prime_dvd_mult)
    26 apply (auto simp add: prime_def)
    27 apply (erule dvdE)
    28 apply (case_tac "k=0", simp)
    29 apply (drule_tac x = m in spec)
    30 apply (drule_tac x = k in spec)
    31 apply (simp add: dvd_mult_cancel1 dvd_mult_cancel2)
    32 done
    33 
    34 lemma zero_less_prime_power: "prime p ==> 0 < p^a"
    35 by (force simp add: prime_iff)
    36 
    37 
    38 lemma zero_less_card_empty: "[| finite S; S \<noteq> {} |] ==> 0 < card(S)"
    39 by (rule ccontr, simp)
    40 
    41 
    42 lemma prime_dvd_cases:
    43      "[| p*k dvd m*n;  prime p |]  
    44       ==> (\<exists>x. k dvd x*n & m = p*x) | (\<exists>y. k dvd m*y & n = p*y)"
    45 apply (simp add: prime_iff)
    46 apply (frule dvd_mult_left)
    47 apply (subgoal_tac "p dvd m | p dvd n")
    48  prefer 2 apply blast
    49 apply (erule disjE)
    50 apply (rule disjI1)
    51 apply (rule_tac [2] disjI2)
    52 apply (erule_tac n = m in dvdE)
    53 apply (erule_tac [2] n = n in dvdE, auto)
    54 apply (rule_tac [2] k = p in dvd_mult_cancel)
    55 apply (rule_tac k = p in dvd_mult_cancel)
    56 apply (simp_all add: mult_ac)
    57 done
    58 
    59 
    60 lemma prime_power_dvd_cases [rule_format (no_asm)]: "prime p
    61       ==> \<forall>m n. p^c dvd m*n -->  
    62           (\<forall>a b. a+b = Suc c --> p^a dvd m | p^b dvd n)"
    63 apply (induct_tac "c")
    64  apply clarify
    65  apply (case_tac "a")
    66   apply simp
    67  apply simp
    68 (*inductive step*)
    69 apply simp
    70 apply clarify
    71 apply (erule prime_dvd_cases [THEN disjE], assumption, auto)
    72 (*case 1: p dvd m*)
    73  apply (case_tac "a")
    74   apply simp
    75  apply clarify
    76  apply (drule spec, drule spec, erule (1) notE impE)
    77  apply (drule_tac x = nat in spec)
    78  apply (drule_tac x = b in spec)
    79  apply simp
    80  apply (blast intro: dvd_refl mult_dvd_mono)
    81 (*case 2: p dvd n*)
    82 apply (case_tac "b")
    83  apply simp
    84 apply clarify
    85 apply (drule spec, drule spec, erule (1) notE impE)
    86 apply (drule_tac x = a in spec)
    87 apply (drule_tac x = nat in spec, simp)
    88 apply (blast intro: dvd_refl mult_dvd_mono)
    89 done
    90 
    91 (*needed in this form in Sylow.ML*)
    92 lemma div_combine:
    93      "[| prime p; ~ (p ^ (Suc r) dvd n);  p^(a+r) dvd n*k |]  
    94       ==> p ^ a dvd k"
    95 by (drule_tac a = "Suc r" and b = a in prime_power_dvd_cases, assumption, auto)
    96 
    97 (*Lemma for power_dvd_bound*)
    98 lemma Suc_le_power: "Suc 0 < p ==> Suc n <= p^n"
    99 apply (induct_tac "n")
   100 apply (simp (no_asm_simp))
   101 apply simp
   102 apply (subgoal_tac "2 * n + 2 <= p * p^n", simp)
   103 apply (subgoal_tac "2 * p^n <= p * p^n")
   104 (*?arith_tac should handle all of this!*)
   105 apply (rule order_trans)
   106 prefer 2 apply assumption
   107 apply (drule_tac k = 2 in mult_le_mono2, simp)
   108 apply (rule mult_le_mono1, simp)
   109 done
   110 
   111 (*An upper bound for the n such that p^n dvd a: needed for GREATEST to exist*)
   112 lemma power_dvd_bound: "[|p^n dvd a;  Suc 0 < p;  0 < a|] ==> n < a"
   113 apply (drule dvd_imp_le)
   114 apply (drule_tac [2] n = n in Suc_le_power, auto)
   115 done
   116 
   117 
   118 subsection{*Exponent Theorems*}
   119 
   120 lemma exponent_ge [rule_format]:
   121      "[|p^k dvd n;  prime p;  0<n|] ==> k <= exponent p n"
   122 apply (simp add: exponent_def)
   123 apply (erule Greatest_le)
   124 apply (blast dest: prime_imp_one_less power_dvd_bound)
   125 done
   126 
   127 lemma power_exponent_dvd: "0<s ==> (p ^ exponent p s) dvd s"
   128 apply (simp add: exponent_def)
   129 apply clarify
   130 apply (rule_tac k = 0 in GreatestI)
   131 prefer 2 apply (blast dest: prime_imp_one_less power_dvd_bound, simp)
   132 done
   133 
   134 lemma power_Suc_exponent_Not_dvd:
   135      "[|(p * p ^ exponent p s) dvd s;  prime p |] ==> s=0"
   136 apply (subgoal_tac "p ^ Suc (exponent p s) dvd s")
   137  prefer 2 apply simp 
   138 apply (rule ccontr)
   139 apply (drule exponent_ge, auto)
   140 done
   141 
   142 lemma exponent_power_eq [simp]: "prime p ==> exponent p (p^a) = a"
   143 apply (simp (no_asm_simp) add: exponent_def)
   144 apply (rule Greatest_equality, simp)
   145 apply (simp (no_asm_simp) add: prime_imp_one_less power_dvd_imp_le)
   146 done
   147 
   148 lemma exponent_equalityI:
   149      "!r::nat. (p^r dvd a) = (p^r dvd b) ==> exponent p a = exponent p b"
   150 by (simp (no_asm_simp) add: exponent_def)
   151 
   152 lemma exponent_eq_0 [simp]: "\<not> prime p ==> exponent p s = 0"
   153 by (simp (no_asm_simp) add: exponent_def)
   154 
   155 
   156 (* exponent_mult_add, easy inclusion.  Could weaken p \<in> prime to Suc 0 < p *)
   157 lemma exponent_mult_add1:
   158      "[| 0 < a; 0 < b |]   
   159       ==> (exponent p a) + (exponent p b) <= exponent p (a * b)"
   160 apply (case_tac "prime p")
   161 apply (rule exponent_ge)
   162 apply (auto simp add: power_add)
   163 apply (blast intro: prime_imp_one_less power_exponent_dvd mult_dvd_mono)
   164 done
   165 
   166 (* exponent_mult_add, opposite inclusion *)
   167 lemma exponent_mult_add2: "[| 0 < a; 0 < b |]  
   168       ==> exponent p (a * b) <= (exponent p a) + (exponent p b)"
   169 apply (case_tac "prime p")
   170 apply (rule leI, clarify)
   171 apply (cut_tac p = p and s = "a*b" in power_exponent_dvd, auto)
   172 apply (subgoal_tac "p ^ (Suc (exponent p a + exponent p b)) dvd a * b")
   173 apply (rule_tac [2] le_imp_power_dvd [THEN dvd_trans])
   174   prefer 3 apply assumption
   175  prefer 2 apply simp 
   176 apply (frule_tac a = "Suc (exponent p a) " and b = "Suc (exponent p b) " in prime_power_dvd_cases)
   177  apply (assumption, force, simp)
   178 apply (blast dest: power_Suc_exponent_Not_dvd)
   179 done
   180 
   181 lemma exponent_mult_add:
   182      "[| 0 < a; 0 < b |]  
   183       ==> exponent p (a * b) = (exponent p a) + (exponent p b)"
   184 by (blast intro: exponent_mult_add1 exponent_mult_add2 order_antisym)
   185 
   186 
   187 lemma not_divides_exponent_0: "~ (p dvd n) ==> exponent p n = 0"
   188 apply (case_tac "exponent p n", simp)
   189 apply (case_tac "n", simp)
   190 apply (cut_tac s = n and p = p in power_exponent_dvd)
   191 apply (auto dest: dvd_mult_left)
   192 done
   193 
   194 lemma exponent_1_eq_0 [simp]: "exponent p (Suc 0) = 0"
   195 apply (case_tac "prime p")
   196 apply (auto simp add: prime_iff not_divides_exponent_0)
   197 done
   198 
   199 
   200 subsection{*Main Combinatorial Argument*}
   201 
   202 lemma le_extend_mult: "[| 0 < c; a <= b |] ==> a <= b * (c::nat)"
   203 apply (rule_tac P = "%x. x <= b * c" in subst)
   204 apply (rule mult_1_right)
   205 apply (rule mult_le_mono, auto)
   206 done
   207 
   208 lemma p_fac_forw_lemma:
   209      "[| 0 < (m::nat); 0<k; k < p^a; (p^r) dvd (p^a)* m - k |] ==> r <= a"
   210 apply (rule notnotD)
   211 apply (rule notI)
   212 apply (drule contrapos_nn [OF _ leI, THEN notnotD], assumption)
   213 apply (drule_tac m = a in less_imp_le)
   214 apply (drule le_imp_power_dvd)
   215 apply (drule_tac n = "p ^ r" in dvd_trans, assumption)
   216 apply (frule_tac m = k in less_imp_le)
   217 apply (drule_tac c = m in le_extend_mult, assumption)
   218 apply (drule_tac k = "p ^ a" and m = " (p ^ a) * m" in dvd_diffD1)
   219 prefer 2 apply assumption
   220 apply (rule dvd_refl [THEN dvd_mult2])
   221 apply (drule_tac n = k in dvd_imp_le, auto)
   222 done
   223 
   224 lemma p_fac_forw: "[| 0 < (m::nat); 0<k; k < p^a; (p^r) dvd (p^a)* m - k |]  
   225       ==> (p^r) dvd (p^a) - k"
   226 apply (frule_tac k1 = k and i = p in p_fac_forw_lemma [THEN le_imp_power_dvd], auto)
   227 apply (subgoal_tac "p^r dvd p^a*m")
   228  prefer 2 apply (blast intro: dvd_mult2)
   229 apply (drule dvd_diffD1)
   230   apply assumption
   231  prefer 2 apply (blast intro: dvd_diff)
   232 apply (drule less_imp_Suc_add, auto)
   233 done
   234 
   235 
   236 lemma r_le_a_forw: "[| 0 < (k::nat); k < p^a; 0 < p; (p^r) dvd (p^a) - k |] ==> r <= a"
   237 by (rule_tac m = "Suc 0" in p_fac_forw_lemma, auto)
   238 
   239 lemma p_fac_backw: "[| 0<m; 0<k; 0 < (p::nat);  k < p^a;  (p^r) dvd p^a - k |]  
   240       ==> (p^r) dvd (p^a)*m - k"
   241 apply (frule_tac k1 = k and i = p in r_le_a_forw [THEN le_imp_power_dvd], auto)
   242 apply (subgoal_tac "p^r dvd p^a*m")
   243  prefer 2 apply (blast intro: dvd_mult2)
   244 apply (drule dvd_diffD1)
   245   apply assumption
   246  prefer 2 apply (blast intro: dvd_diff)
   247 apply (drule less_imp_Suc_add, auto)
   248 done
   249 
   250 lemma exponent_p_a_m_k_equation: "[| 0<m; 0<k; 0 < (p::nat);  k < p^a |]  
   251       ==> exponent p (p^a * m - k) = exponent p (p^a - k)"
   252 apply (blast intro: exponent_equalityI p_fac_forw p_fac_backw)
   253 done
   254 
   255 text{*Suc rules that we have to delete from the simpset*}
   256 lemmas bad_Sucs = binomial_Suc_Suc mult_Suc mult_Suc_right
   257 
   258 (*The bound K is needed; otherwise it's too weak to be used.*)
   259 lemma p_not_div_choose_lemma [rule_format]:
   260      "[| \<forall>i. Suc i < K --> exponent p (Suc i) = exponent p (Suc(j+i))|]  
   261       ==> k<K --> exponent p ((j+k) choose k) = 0"
   262 apply (case_tac "prime p")
   263  prefer 2 apply simp 
   264 apply (induct_tac "k")
   265 apply (simp (no_asm))
   266 (*induction step*)
   267 apply (subgoal_tac "0 < (Suc (j+n) choose Suc n) ")
   268  prefer 2 apply (simp add: zero_less_binomial_iff, clarify)
   269 apply (subgoal_tac "exponent p ((Suc (j+n) choose Suc n) * Suc n) = 
   270                     exponent p (Suc n)")
   271  txt{*First, use the assumed equation.  We simplify the LHS to
   272   @{term "exponent p (Suc (j + n) choose Suc n) + exponent p (Suc n)"}
   273   the common terms cancel, proving the conclusion.*}
   274  apply (simp del: bad_Sucs add: exponent_mult_add)
   275 txt{*Establishing the equation requires first applying 
   276    @{text Suc_times_binomial_eq} ...*}
   277 apply (simp del: bad_Sucs add: Suc_times_binomial_eq [symmetric])
   278 txt{*...then @{text exponent_mult_add} and the quantified premise.*}
   279 apply (simp del: bad_Sucs add: zero_less_binomial_iff exponent_mult_add)
   280 done
   281 
   282 (*The lemma above, with two changes of variables*)
   283 lemma p_not_div_choose:
   284      "[| k<K;  k<=n;   
   285        \<forall>j. 0<j & j<K --> exponent p (n - k + (K - j)) = exponent p (K - j)|]  
   286       ==> exponent p (n choose k) = 0"
   287 apply (cut_tac j = "n-k" and k = k and p = p in p_not_div_choose_lemma)
   288   prefer 3 apply simp
   289  prefer 2 apply assumption
   290 apply (drule_tac x = "K - Suc i" in spec)
   291 apply (simp add: Suc_diff_le)
   292 done
   293 
   294 
   295 lemma const_p_fac_right:
   296      "0 < m ==> exponent p ((p^a * m - Suc 0) choose (p^a - Suc 0)) = 0"
   297 apply (case_tac "prime p")
   298  prefer 2 apply simp 
   299 apply (frule_tac a = a in zero_less_prime_power)
   300 apply (rule_tac K = "p^a" in p_not_div_choose)
   301    apply simp
   302   apply simp
   303  apply (case_tac "m")
   304   apply (case_tac [2] "p^a")
   305    apply auto
   306 (*now the hard case, simplified to
   307     exponent p (Suc (p ^ a * m + i - p ^ a)) = exponent p (Suc i) *)
   308 apply (subgoal_tac "0<p")
   309  prefer 2 apply (force dest!: prime_imp_one_less)
   310 apply (subst exponent_p_a_m_k_equation, auto)
   311 done
   312 
   313 lemma const_p_fac:
   314      "0 < m ==> exponent p (((p^a) * m) choose p^a) = exponent p m"
   315 apply (case_tac "prime p")
   316  prefer 2 apply simp 
   317 apply (subgoal_tac "0 < p^a * m & p^a <= p^a * m")
   318  prefer 2 apply (force simp add: prime_iff)
   319 txt{*A similar trick to the one used in @{text p_not_div_choose_lemma}:
   320   insert an equation; use @{text exponent_mult_add} on the LHS; on the RHS,
   321   first
   322   transform the binomial coefficient, then use @{text exponent_mult_add}.*}
   323 apply (subgoal_tac "exponent p ((( (p^a) * m) choose p^a) * p^a) = 
   324                     a + exponent p m")
   325  apply (simp del: bad_Sucs add: zero_less_binomial_iff exponent_mult_add prime_iff)
   326 txt{*one subgoal left!*}
   327 apply (subst times_binomial_minus1_eq, simp, simp)
   328 apply (subst exponent_mult_add, simp)
   329 apply (simp (no_asm_simp) add: zero_less_binomial_iff)
   330 apply (simp del: bad_Sucs add: exponent_mult_add const_p_fac_right)
   331 done
   332 
   333 
   334 end