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