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