Exercise 2.9.8* (Cubic roots modulo $p$)

Suppose that p 1 = m 3 k with k > 0 and 3 m . Show that if ( n , p ) = 1 then the order of n is a power of 3 if and only if the congruence x m n ( mod p ) has a solution. If m 2 ( mod 3 ) then put r a ( m + 1 ) 3 , n a m ( mod p ) . If m 1 ( mod 3 ) then put r = a ( 2 m + 1 ) 3 , n a 2 m ( mod p ) . Show that in either case, r 3 an ( mod p ) , and that the order of n is a power of 3 , say 3 k . Choose z so that z ( p 1 ) 3 1 ( mod p ) , and set c z m ( mod p ) . Show that c has order exactly 3 k , and that there is an integer u , 0 u < 3 k , such that n c u ( mod p ) . Show that one of the numbers n c 3 k k , n c 2 3 k k has order 3 k , and that the order of the other one is a smaller power of 3 , say 3 k . Let n denote this number with smaller order. Determine r so that r 3 a n ( mod p ) . Continuing in this manner, construct an algorithm for computing the solutions of the congruence x 3 a ( mod p ) .

Answers

Proof.

(a)
Suppose that p 1 = m 3 k with k > 0 and 3 m .

Let 𝔽 p be the field pℤ with p elements. Then 𝔽 p is an abelian group, and

φ { 𝔽 p 𝔽 p x x 3 k , ψ { 𝔽 p 𝔽 p x x m ,

are group homomorphisms. We show first that im ψ = ker φ .

We estimate the orders of the subgroups ker ψ and ker φ . Let γ a generator of 𝔽 p . For any x 𝔽 p , x = γ t for some integer t , where 0 t < m 3 k , and

x ker ψ γ tm = 1 p 1 tm 3 k t .

Since the order of γ is m 3 k ,

ker ψ = { 1 , γ 3 k , γ 2 3 k , , γ ( m 1 ) 3 k } ,

where the elements γ j 3 k ( 0 j m 1 ) are distinct, thus | ker ψ | = m .

Similarly,

x ker ψ γ t 3 k = 1 p 1 t 3 k m t .

Therefore

ker ( φ ) = { 1 , γ m , γ 2 m , , γ ( 3 k 1 ) m } ,

and | ker ( φ ) | = 3 k .

By the first isomorphism theorem, im ψ 𝔽 p ker ψ , thus

| im ψ | = ( p 1 ) m = 3 k = | ker φ | .

Moreover, if y im ψ , then y = x m for some x 𝔽 p . Therefore

y 3 k = x m 3 k = x p 1 = 1 ,

thus y ker φ . This shows that

im ψ ker φ ,

where | im ψ | = | ker φ | , hence

im ψ = ker φ .

So, for every y 𝔽 p ,

x 𝔽 p , y = x m y 3 k = 1 . (1)

We write o ( y ) the order of y in the group 𝔽 p . It remains to shows the equivalence

y 3 k = 1 j , o ( y ) = 3 j . (2)
  • If y 3 k = 1 , then o ( y ) 3 k , thus o ( y ) = 3 j for some j .
  • Conversely, if o ( y ) = 3 j , since y m 3 k = 1 , then 3 j m 3 k , where m 3 = 1 , hence 3 j 3 k , thus j k , and y 3 k = ( y 3 j ) 3 k j = 1 .

Combining (1) and (2), we obtain for every y 𝔽 p ,

x 𝔽 p , y = x m j , o ( y ) = 3 j . (3)

If we translate (3) in , we obtain, for every integer n such that n p = 1 (using y = [ n ] p 𝔽 p ):

The congruence x m n ( mod p ) has a solution if and only if the order of n modulo p is a power of 3 .

Note that those integers n are the integers such that [ n ] = [ n ] p ker ( φ ) . Write G the subgroup G = ker φ = im ψ . By part (a),

[ n ] G = { 1 , γ m , γ 2 m , , γ ( 3 k 1 ) m } .

(b)
We want to solve the congruence x 3 a ( mod p ) , where p a . This congruence has a solution if and only if a ( p 1 ) 3 1 ( mod p ) . Indeed, if x 3 a ( mod p ) , then a ( p 1 ) 3 x p 1 1 ( mod p ) . Conversely, suppose that a ( p 1 ) 3 1 ( mod 3 ) . Let g be a primitive root modulo p . Then a g s ( mod p ) for some positive integer s , so that g s p 1 3 1 ( mod p ) . The order of g is p 1 , therefore p 1 s p 1 3 , thus 3 s , so s = 3 u for some positive integer u , and a ( g u ) 3 = x 3 , with x = g u .

We assume now that the condition

a ( p 1 ) 3 1 ( mod p ) , (4)

so that we know that the congruence x 3 a ( mod p ) has a solution.

  • If m 2 ( mod 3 ) , then ( m + 1 ) 3 is an integer. Put

    r a ( m + 1 ) 3 , n a m ( mod p ) .

    Then

    r 3 a m + 1 = a a m an ( mod n ) .

    Moreover n a m ( mod p ) implies by part (a) that the order of n modulo p is a power of 3 .

    The condition (4) is equivalent to n 3 k 1 1 .

  • If m 1 ( mod 3 ) , then ( 2 m + 1 ) 3 is an integer. Put

    r a ( 2 m + 1 ) 3 , n a 2 m ( mod p ) .

    Then

    r 3 a 2 m + 1 = a a 2 m an ( mod p ) .

    Moreover, n ( a 2 ) m implies by part (a) that the order of n modulo p is a power of 3 .

    The condition (4) gives n 3 k 1 a 2 p 1 3 1 ( mod p ) . Conversely, if n 3 k 1 1 ( mod p ) , then a 2 p 1 3 1 ( mod p ) , and a p 1 3 = a p 1 2 p 1 3 1 ( mod p ) .

In both cases, r 3 an ( mod p ) , and n 3 k 1 1 ( mod p ) , so the order of n is a power of 3 , say 3 k , where k < k . The condition n 3 k 1 1 ( mod p ) is a necessary and sufficient condition to the existence of a solution of the congruence x 3 a ( mod p ) .

(c)
Choose z so that z ( p 1 ) 3 1 ( mod p ) . Such an element z exists: let g be a primitive root modulo p ( γ = [ g ] is a generator of 𝔽 p ). Thus z g t ( mod p ) for some integer t . Then z ( p 1 ) 3 1 ( mod p ) g k p 1 3 p 1 k p 1 3 3 k

Take z g k ( mod p ) , where 3 k (for instance z = g ). Then z ( p 1 ) 3 1 ( mod p ) .

(To find such a z , we can use a probabilistic algorithm. If we take a random z [ [ 1 , p 1 ] ] , the probability that z ( p 1 ) 3 1 ( mod p ) is 2 3 , so we find quickly such a z , the average of the waiting time being 3 2 . )

Now set c z m ( mod p ) . Then [ c ] im ψ , thus [ c ] G = ker φ , where the order of G is 3 k . We show that the order of c is 3 k .

Since

c 3 k z m 3 k = z p 1 1 ( mod p ) ,

and

c 3 k 1 z m 3 k 1 z ( p 1 ) 3 1 ( mod p ) ,

the order of c modulo p is 3 k . Since [ c ] G , and the order is c is 3 k = | G | , [ c ] is a generator of the subgroup G .

Since [ n ] G , [ n ] = [ c ] u for some u , 0 u < 3 k , thus

n c u ( mod p ) , 0 u < 3 k .

(d)
Suppose that k 0 . Since the order of c is 3 k , the order of b = c 3 k k is 3 k ( b 3 k = c 3 k 1 ( mod p ) , and b 3 k 1 = c 3 k 1 1 ( mod p ) ). Since the order 3 k > 1 of b is equal to the order of n , by Problem 6, one of the numbers nb = n c 3 k k , n b 2 = n c 2 3 k k has order 3 k , and the order of the other one is a smaller power of 3 , say 3 k .

From r 3 an ( mod p ) , we deduce

( r c 3 k k 1 ) 3 a ( n c 3 k k ) = a ( nb ) , ( r c 2 3 k k 1 ) 3 a ( n c 2 3 k k ) = a ( n b 2 ) .

Put

n nb , r = r c 3 k k 1 , if  o ( nb ) < o ( n ) , n n b 2 , r = r c 2 3 k k 1 , if  o ( n b 2 ) < o ( n ) ,

so that in both cases r 3 a n , where o ( n ) < o ( n ) .

We continue until one of the number n 0 = n , n 1 = n , n 2 = n , is congruent to 1 modulo p , say n d . Then r d 3 a n d a ( mod p ) , so that r d is a solution x 0 of the congruence x 3 a ( mod p ) .

To obtain the other roots, we note that x 3 a ( mod p ) is equivalent to ( x x 0 ) 3 1 ( mod p ) , where x 0 is a particular solution. Therefore the solutions are x 0 ω , where ω is a solution of x 3 1 ( mod p ) .

To solve x 3 = 1 in 𝔽 p , we use x 3 1 = ( x 1 ) ( x 2 + x + 1 ) . Moreover, for all x 𝔽 p ,

x 2 + x + 1 = 0 4 x 2 + 4 x + 4 0 ( mod p ) ( 2 x + 1 ) 2 = 3 .

If ξ is a square root of 3 in 𝔽 p , obtained with the RESSOL algorithm (if such a root exists, that is if p 1 ( mod 3 ) ), we obtain

2 x + 1 = ± ξ .

The inverse of [ 2 ] 𝔽 p is [ 2 ] 1 = p + 1 2 , thus a root of x 2 + x + 1 if p 1 ( mod 3 ) is

ω = ( p + 1 2 ) ( ξ 1 ) .

Since x 3 1 = ( x 1 ) ( x ω ) ( x ω 2 ) , the roots are 1 , ω , ω 2 . So, for all x 𝔽 p ,

if  p 2 ( mod 3 ) , x 3 = 1 ( mod p ) x = 1 , if  p 1 ( mod 3 ) , x 3 = 1 ( mod p ) x { 1 , ω , ω 2 } , where  ω = ( p + 1 2 ) ( ξ 1 ) , ξ 2 = 3 , ξ 𝔽 p .

(See the algorith below.)

Here is our (non optimized) code in Python on jupyter-lab to obtain the list of cubic roots. The function “ressol” used here is written in the solution of Problem 4.

def cubic_roots_of_unity(p):
    """input  : prime p>3
       output : list of the roots of x^3 = 1 mod p
    """
    if p % 3 == 2:
        return [1]
    omega = (((p+1) // 2) * (ressol(-3,p) - 1)) % p
    return [1,omega , omega ** 2 % p]

def cubic_roots(a,p):
    """input  : prime p>3, integer a
       output : list of the roots of x^3 = 1 mod p
    """
    def exponent_order(x):
        " output: k such that o(x) = 3^k"
        i = 0
        npower = x
        while npower != 1:
            npower = (npower ** 3) % p
            i = i + 1
        return i

    if a == 0: return [0]
    if p % 3 == 2:
        return [pow(a, (2*p - 1) // 3, p)]
    # (p % 3 = 1)

    if pow(a, (p-1) // 3, p) != 1:
        return []

    m, k = p - 1, 0
    while m % 3 == 0:
        m //= 3
        k += 1

    found = False
    while not found:
        z = randint(1, p - 1)
        if pow(z,(p-1) // 3, p) != 1:
            found = True
    c = pow(z, m , p)
                                                                  

                                                                  

    if  m % 3 == 2:
        r = pow(a, (m + 1) // 3, p)
        n = pow(a, m, p)
    else:
        r = pow(a, (2 * m + 1) // 3, p)
        n = pow(a, 2 * m, p)

    while n != 1:
        i = exponent_order(n)
        b = pow(c, 3 ** (k - i), p)
        u, v = (n * b) % p, (n * b ** 2) % p
        if exponent_order(u) < exponent_order(v):
            n = u
            r = (r * pow(c, 3 ** (k-i-1), p)) % p
        else:
            n = v
            r = (r * pow(c, 2 * 3 ** (k-i-1), p))  % p
    return [(r * omega)  % p for omega in cubic_roots_of_unity(p)]

p = 1234567891
print(cubic_roots(15, p))

[915966894, 170527222, 148073775]

print((148073775 ** 3) % p, (915966894 ** 3) % p, (170527222 ** 3) % p))

(15, 15, 15)

% timeit cubic_roots(15, p)

69 . 2 μs ± 2.41 μs per loop (mean std. dev. of 7 runs, 10 , 000 loops each)

User profile picture
2024-10-16 08:21
Comments