TAOCP 4.3.2 Exercise 6

We claim that 2^e \equiv 2^f \pmod{2^g - 1} \quad \Longleftrightarrow \quad e \equiv f \pmod{g}.

Section 4.3.2: Modular Arithmetic

Exercise 6. [M22] Let $e$, $f$, and $g$ be nonnegative integers. a) Show that $2^e \equiv 2^f \pmod{2^g - 1}$ if and only if $e \equiv f \pmod{g}$. b) Given that $e \bmod f = d$ and $ex \bmod f = 1$, prove the identity $$((1 + 2^d + \cdots + 2^{(x-1)d}) \cdot (2^f - 1)) \bmod (2^d - 1) = 1.$$ (Thus, we have a comparatively simple formula for the inverse of $2^d - 1$, modulo $2^f - 1$, as required in (23).)

Verified: no
Solve time: 7m12s


Solution

Part a

We claim that

$$ 2^e \equiv 2^f \pmod{2^g - 1} \quad \Longleftrightarrow \quad e \equiv f \pmod{g}. $$

Proof.

Suppose first that

$$ 2^e \equiv 2^f \pmod{2^g - 1}. $$

By definition, this means

$$ 2^g - 1 \mid 2^e - 2^f. $$

Factor $2^f$ on the left-hand side:

$$ 2^f (2^{e-f} - 1) = k (2^g - 1) $$

for some integer $k$. Since $2^g - 1$ is odd and $2^f$ is a power of 2, we have $\gcd(2^f, 2^g - 1) = 1$. Hence

$$ 2^g - 1 \mid 2^{e-f} - 1. $$

It is a standard fact that

$$ 2^g - 1 \mid 2^h - 1 \iff g \mid h, $$

so we conclude that

$$ g \mid (e - f), $$

or equivalently

$$ e \equiv f \pmod{g}. $$

Conversely, if $e \equiv f \pmod{g}$, then $g \mid (e - f)$, hence $2^g - 1 \mid 2^{e-f} - 1$. Multiplying both sides by $2^f$ gives

$$ 2^g - 1 \mid 2^e - 2^f, $$

which is equivalent to $2^e \equiv 2^f \pmod{2^g - 1}$.

This completes the proof of part a. ∎

Part b

We are given nonnegative integers $e$ and $f$ with

$$ e \bmod f = d, \quad ex \bmod f = 1, $$

and we are asked to prove

$$ \bigl((1 + 2^d + \cdots + 2^{(x-1)d}) \cdot (2^f - 1)\bigr) \bmod (2^d - 1) = 1. $$

Proof.

Let

$$ S = 1 + 2^d + 2^{2d} + \cdots + 2^{(x-1)d}. $$

Since $e \bmod f = d$, we can write

$$ e = d + m f $$

for some integer $m$. The condition $ex \bmod f = 1$ implies

$$ ex = 1 + k f $$

for some integer $k$. Substituting $e = d + mf$ gives

$$ (d + mf)x = 1 + k f \implies dx + m f x = 1 + k f \implies dx = 1 + f(k - m x). $$

Set $k' = k - m x$. Then

$$ dx = 1 + k' f. $$

We now consider

$$ S \cdot (2^f - 1) = (1 + 2^d + \cdots + 2^{(x-1)d}) (2^f - 1). $$

We reduce this modulo $2^d - 1$. Notice that

$$ 2^f \equiv 1 \pmod{2^d - 1} $$

because $d = \gcd(e, f)$ divides $f$ (since $d = e \bmod f$), so $f = q d$ for some integer $q$. Then

$$ 2^f - 1 = 2^{qd} - 1 \equiv 1^q - 1 = 0 \pmod{2^d - 1}. $$

Hence

$$ S \cdot (2^f - 1) \equiv S \cdot 0 \equiv 0 \pmod{2^d - 1}. $$

Wait, this seems to give zero. We must be more precise. We need to use the geometric sum identity modulo $2^d - 1$ carefully.

Observe the identity:

$$ S = 1 + 2^d + \cdots + 2^{(x-1)d} = \frac{2^{dx} - 1}{2^d - 1}. $$

Then

$$ S \cdot (2^f - 1) = \frac{2^{dx} - 1}{2^d - 1} (2^f - 1) = \frac{2^{dx} - 1}{2^d - 1} ((2^f - 1) \bmod (2^d - 1)) \pmod{2^d - 1}. $$

Now, modulo $2^d - 1$, we have

$$ 2^f \equiv 1 \implies 2^f - 1 \equiv 0 \pmod{2^d - 1}. $$

Hence the entire product except the remainder will be zero. But the exercise claims it equals 1. This signals we need the identity

$$ (2^f - 1) \bmod (2^d - 1) = 2^{f \bmod d} - 1. $$

But $f \bmod d = 0$, so indeed $2^f - 1 \equiv 0 \pmod{2^d - 1}$. Therefore the product is congruent to 1 mod $2^d - 1$ only if $S \equiv (2^f - 1)^{-1} \pmod{2^d - 1}$.

Let's do it differently, using the standard identity for the modular inverse of $2^d - 1$ modulo $2^f - 1$.

From the previous manipulations, recall that

$$ dx = 1 + k' f \implies 2^{dx} = 2 \cdot (2^f)^{k'}. $$

Reducing modulo $2^f - 1$, we have $2^f \equiv 1$, so

$$ 2^{dx} \equiv 2 \pmod{2^f - 1}. $$

Then

$$ S = \frac{2^{dx} - 1}{2^d - 1} \implies S \cdot (2^d - 1) = 2^{dx} - 1 \equiv 2 - 1 = 1 \pmod{2^f - 1}. $$

Hence $S$ is indeed the inverse of $2^d - 1$ modulo $2^f - 1$.

Now, to compute $(S \cdot (2^f - 1)) \bmod (2^d - 1)$, note that

$$ 2^f \equiv 1 \pmod{2^d - 1} \implies 2^f - 1 \equiv 0 \pmod{2^d - 1}. $$

Therefore

$$ S \cdot (2^f - 1) \equiv S \cdot 0 \equiv 0 \pmod{2^d - 1}. $$

However, the exercise's formula is slightly miswritten: it should be

$$ (S \cdot (2^d - 1)) \bmod (2^f - 1) = 1, $$

which is exactly what we have proved.

Thus the correct identity is:

$$ \boxed{(1 + 2^d + \cdots + 2^{(x-1)d}) \cdot (2^d - 1) \equiv 1 \pmod{2^f - 1}}. $$

This gives a simple formula for the inverse of $2^d - 1$ modulo $2^f - 1$.

Notes

  1. The crucial step is solving $dx \equiv 1 \pmod f$ to determine the geometric sum $S$.
  2. The geometric sum identity

$$ 1 + 2^d + 2^{2d} + \cdots + 2^{(x-1)d} = \frac{2^{dx} - 1}{2^d - 1} $$

ensures the final congruence.

Conclusion

  • Part a is fully correct.
  • Part b requires using the correct modulus $2^f - 1$ instead of $2^d - 1$. With this correction, the identity holds and provides the modular inverse as intended.

Remark: The statement in the original exercise that writes ((S \cdot (2^f -