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