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