Exercise 4.1.35* (Lucas's Theorem)

Suppose that a = αp + a 0 and that 0 a 0 < p . Show that a ! ( α ! p α ) ( 1 ) α a 0 ! ( mod p ) . Suppose also that b = βp + b 0 with 0 b 0 < p . Show that ( a + b a ) ( α + β β ) ( a 0 + b 0 a 0 ) ( mod p ) . Deduce that if a = i a i p i and b = i b i p i in base p , then

( a + b a ) i ( a i + b i a i ) ( mod p ) .

Answers

First proof. (Following the steps of Problem 35.)

Proof.

(a)
Suppose that a = αp + a 0 , where 0 a 0 < p . Then [ [ 1 , a ] ] = ] ] 0 , αp + a 0 ] ] = ] ] αp , αp + a 0 ] ] 1 k α ] ] ( α k ) p , ( α k + 1 ) p ] ] .

Therefore

a ! α ! p α = a ! ( αp ) ( ( α 1 ) p ) ( 1 p ) = i = 1 a 0 ( αp + i ) k = 1 α i = 1 p 1 [ ( α k ) p + i ] .

Moreover

i = 1 a 0 ( αp + i ) i = 1 a 0 i = a 0 ! ( mod p ) ,

and, by Wilson’s Theorem,

i = 1 p 1 [ ( α k ) p + i ] ( p 1 ) ! 1 ( mod p ) ,

thus

a ! α ! p α ( 1 ) α a 0 ! ( mod p ) .

(b)
Now a = αp + a 0 , 0 a 0 < p , b = βp + b 0 , 0 b 0 < p ,

so that a 0 , b 0 are respectively the last digits of a , b in base p .

  • Suppose first that 0 a 0 + b 0 < p , so that there is no carry when we add a 0 and b 0 in base p . Put

    γ = α + β , c 0 = a 0 + b 0 .

    Then

    ( a + b a ) = ( γp + c 0 ) ! ( αp + a 0 ) ! ( βp + b 0 ) ! = γ ! α ! β ! ( γp + c 0 ) ! γ ! p γ α ! p α ( αp + a 0 ) ! β ! p β ( βp + b 0 ) ! ,

    so

    ( a + b a ) = ( α + β α ) C A B , (1)

    where, by part (a), since 0 c 0 = a 0 + b 0 < p ,

    A = ( αp + a 0 ) ! α ! p α ( 1 ) α a 0 ! ( mod p ) , B = ( βp + b 0 ) ! β ! p β ( 1 ) β b 0 ! ( mod p ) , C = ( γp + c 0 ) ! γ ! p γ ( 1 ) γ c 0 ! ( mod p ) .

    We prove

    C A B c 0 ! a 0 ! b 0 ! ( mod p ) , (2)

    since both members are integers, a 0 ! 0 ( mod p ) , b 0 ! 0 ( mod p ) , so a 0 ! , b 0 ! are invertible modulo p , so are A , B , and

    a 0 ! b 0 ! AB ( C A B ) = a 0 b 0 C ( 1 ) γ a 0 ! b 0 ! c 0 ! = ( ( 1 ) α a 0 ! ) ( 1 ) β b 0 ! ) c 0 ! AB c 0 ! = a 0 ! b 0 ! AB ( c 0 ! a 0 ! b 0 ! ) ( mod p ) .

    After simplification by a 0 ! b 0 ! AB , which is invertible modulo p , we obtain the congruence (2). Then the congruence (1) becomes

    ( a + b a ) ( α + β α ) ( a 0 + b 0 a 0 ) ( mod p ) .

  • Suppose now that a 0 + b 0 p , so that there is a carry when we add a 0 and b 0 in base p . Then there is at least a carry when we add a , b in base p . By Problem 34 (Kummer’s Theorem), ( a + b b ) 0 and ( a 0 + b 0 a 0 ) 0 ( mod p ) , so

    ( a + b b ) 0 ( α + β α ) ( a 0 + b 0 a 0 ) ( mod p ) .

In both cases,

( a + b a ) ( α + β α ) ( a 0 + b 0 a 0 ) ( mod p ) . (3)
(c)
We write a = i = 0 k a i p i , b = i = 0 k b i p i , with the same k be introducing possibly some digits 0 at the left of the writing of a or b in base p . Then 0 a < p k + 1 , 0 b < p k + 1 .

We prove by induction on k that, for all a , b such that 0 a < p k + 1 , 0 b < p k + 1 , where a = i = 0 k a i p i and b = i = 0 k b i p i are the writings of a , b in base p ,

( a + b a ) i = 0 k ( a i + b i a i ) ( mod p ) .

  • If k = 1 then a = a 0 , b = b 0 , so ( a + b a ) = ( a 0 + b 0 a 0 ) = i = 0 0 ( a i + b i a i ) .
  • Suppose that the property is true for all integers less that p k , and take a , b such that 0 a < p k + 1 , 0 b < p k + 1 . We write a , b in base p in the form a = i = 0 k a i p i , b = i = 0 k b i p i . Then a = αp + a 0 , b = βp + b 0 , where

    α = i = 1 k a i p i 1 = j = 0 k 1 a j p j < p k , β = i = 1 k b i p i 1 = j = 0 p 1 b j p j < p k ,

    where a j = a j + 1 , b j = b j + 1 for j = 1 , 2 , , k 1 are the digits of α , β in base p .

    The induction hypothesis applied to α , β gives

    ( α + β α ) j = 0 k 1 ( a j + b j a j ) = i = 1 k ( a i 1 + b i 1 a i 1 ) ( i = j + 1 ) = i = 1 k ( a i + b i a i ) ( mod p ) .

    Then, by part (b),

    ( a + b b ) ( α + β α ) ( a 0 + b 0 a 0 ) ( i = 1 k ( a i + b i a i ) ) ( a 0 + b 0 a 0 ) = i = 0 k ( a i + b i a i ) .
  • The induction is done, thus the property is true for all a , b .

In conclusion, if a = i = 0 k a i p i , b = i = 0 k b i p i , where 0 a i < p , 0 b i < p for all i ,

( a + b a ) i = 0 k ( a i + b i a i ) ( mod p ) .

Second proof (From a paper of N.J.Fine, 1947)

Proof. We show first the Lucas’s Theorem:

Theorem.If n = i = 0 k n i p i and a = i = 0 k a i p i are the writings of n and a in base p , then

( n a ) = i = 0 k ( n i a i ) .

We expand f ( x ) = ( 1 + x ) n in 𝔽 p [ x ] , where 𝔽 p is the field with p elements.

First

( 1 + x ) n = k = 0 n ( n i ) x i ,

and the coefficient of x a is ( n a ) .

Next, since the characteristic of 𝔽 p is p , ( 1 + x ) p i = 1 + x p i for all i , therefore

( 1 + x ) n = ( 1 + x ) i = 0 k n i p i = i = 0 k ( 1 + x ) n i p i = i = 0 k [ ( 1 + x ) p i ] n i = i = 0 k ( 1 + x p i ) n i = i = 0 k j = 0 n i ( n i j ) x j p i = ( j 0 , j 1 , , j k ) [ [ 0 , n 0 ] ] × × [ [ 0 , n k ] ] ( n 0 j 0 ) ( n 1 j 1 ) ( n k j k ) x j 0 + j 1 p + j k p k .
  • If a i n i for all indices i [ [ 0 , k ] ] , then there is at least a k + 1 -tuple ( j 0 , j 1 , , j k ) [ [ 0 , n 0 ] ] × [ [ 0 , n k ] ] such that a = j 0 + j 1 p + j k p k , which is

    ( j 0 , j 1 , , j k ) = ( a 0 , a 1 , , a k ) .

    The unicity of the writing of a in base p shows that there is exactly one such ( j 0 , j 1 , , j k ) .

    This prove that the coefficient of x a in f ( x ) is

    ( n a ) ( n 0 a 0 ) ( n 1 a 1 ) ( n k a k ) ( mod p ) .

  • If there is some index i for which a i > n i , then there is no ( j 0 , j 1 , , j k ) [ [ 0 , n 0 ] ] × × [ [ 0 , n k ] ] such that a = j 0 + j 1 p + j k p k , so the coefficient ( n a ) of x a is zero modulo p . Moreover ( n i a i ) = 0 , so

    ( n a ) 0 ( n 0 a 0 ) ( n 1 a 1 ) ( n k a k ) ( mod p ) .

In both cases,

( n a ) ( n 0 a 0 ) ( n 1 a 1 ) ( n k a k ) ( mod p ) .

Now we can prove the result of Problem 35. Here a = i = 0 k a i p i and b = i = 0 k b i p i are given.

If there is some index i such that a i + b i p , then there is at least a carry in the addition of a and b in base p . By Kummer’s Theorem (Problem 34), ( a + b a ) 0 ( mod p ) . Moreover, for the same reason ( a i + b i a i ) 0 ( mod p ) . So

( a + b a ) 0 i = 0 k ( a i + b i a i ) ( mod p ) .

Otherwise 0 a i + b i < p for all i , so n i = a i + b i is the i -th digit of n = a + b in base p . Therefore, the Lucas’s Theorem gives

( a + b a ) = ( n a ) i = 0 k n i p i = ( a i + b i a i ) ( mod p ) .

Note 1: Conversely, if we know the result of Problem 35 by the first proof, we can prove the Lucas’s Theorem. We write ( n a ) = ( a + b a ) , where b = n a .

If there is no carry when we add a , b in base p , then n i = a i + b i for all i , so

( n a ) = ( a + b a ) i = 0 k ( a i + b i a i ) = i = 0 k ( n i a i ) .

Otherwise, if there is a carry, then

( n a ) = ( a + b a ) 0 ( mod p ) .

Moreover, if there is a carry at the index i , a i + b i = p + n i , thus n i = a i ( p b i ) < a i , so ( n i a i ) = 0 , and then

( n a ) 0 i = 0 k ( n i a i ) ( mod p ) .

This proves Lucas’s Theorem with the result of Problem 35.

The equivalence between Problem 35 and Lucas’s Theorem is not obvious without the Kummer’s Theorem (Problem 34).

Note 2: We can compare with Sage the results of Problem 35 and Lucas Theorem to compute ( n a ) modulo p . For instance, for n = 17 , a = 12 , p = 7 , we obtain in base 7

12 + 5 = 1 5 7 + 0 5 7 = 2 3 7 = 17 ,

so a 0 = 5 , a 1 = 1 , b 0 = 5 , b 1 = 0 , n 0 = 3 , n 1 = 7 .

With Lucas’s Theorem,

( 17 12 ) = ( 2 3 7 1 5 7 ) ( 2 1 ) ( 3 5 ) 0 ( mod 7 ) ,

and with the result of Problem 35,

( 17 12 ) = ( 12 + 5 12 ) ( 1 5 7 + 0 5 7 1 5 7 ) = ( 1 1 ) ( 10 5 ) = 252 = 36 7 0 ( mod 7 ) .

def decomposition(n, p):
    l = []
    while n != 0:
        q, r = n // p, n % p
        n = q
        l.append(r)
    return l

def lucas(n, a, p):
    la = decomposition(a, p)
    ln = decomposition(n, p)
    k = max(len(la), len(ln))
    for i in range(len(la), k):
        la.append(0)
    for i in range(len(ln), k):
        ln.append(0)
    res = 1
    for i in range(k):
        res *= binomial(ln[i], la[i])
    return res % p

def niven(a, b, p):
    la = decomposition(a, p)
    lb = decomposition(b, p)
    k = max(len(la), len(lb))
    for i in range(len(la), k):
        la.append(0)
    for i in range(len(lb), k):
        lb.append(0)
    res = 1
    for i in range(k):
        res *= binomial(la[i]+ lb[i], la[i])
    return res % p

n = 17
p = 7
b1, b2, b3 = [], [], []
for a in range(n + 1):
    b1.append(binomial(n, a) % p)
    b2.append(lucas(n, a, p))
    b3.append(niven(a, n - a ,p))
                                                                  

                                                                  
print(b1)
print(b2)
print(b3)
      
[1, 3, 3, 1, 0, 0, 0, 2, 6, 6, 2, 0, 0, 0, 1, 3, 3, 1]
[1, 3, 3, 1, 0, 0, 0, 2, 6, 6, 2, 0, 0, 0, 1, 3, 3, 1]
[1, 3, 3, 1, 0, 0, 0, 2, 6, 6, 2, 0, 0, 0, 1, 3, 3, 1]

User profile picture
2025-01-09 09:23
Comments