Algorithm Search⌘K

Proofs: Dixon's random squares algorithm

These are the human proofs of Dixon's random squares algorithm, at full length.

Correctness of Dixon's random squares algorithm full

This proof shows: correctness, termination.

Write UU for the group of units modulo NN, that is, the residues in [1,N−1][1, N - 1] prime to NN, and v(z)v(z) for the exponent vector of z2 mod Nz^2 \bmod N over FF when it exists.

Lemma 1 (the elimination). Let v1,…,vmv_1, \dots, v_m be the exponent vectors mod 2, as bit masks. When row jj reduces to 00, the subset hh it carries is nonempty and ⨁l∈hvl=0\bigoplus_{l \in h} v_l = 0, where ⊕\oplus is the sum mod 2. If m>Km > K, at least m−Km - K subsets are found.

Proof. Row jj starts with u=vju = v_j and h={j}h = \{j\}. Each reduction adds a stored pivot pair (u′,h′)(u', h') with u′=⨁l∈h′vlu' = \bigoplus_{l \in h'} v_l to (u,h)(u, h) by ⊕\oplus in both parts, so u=⨁l∈hvlu = \bigoplus_{l \in h} v_l stays true. The stored pairs come from rows l<jl < j, so j∉h′j \notin h' and jj stays in hh; thus h≠∅h \ne \emptyset. Each reduction clears the leading bit of uu and changes only lower bits, so a row either reduces to 00 or becomes a pivot with a leading bit that no other pivot has. There are KK bit positions, so at most KK pivots, and at least m−Km - K rows reduce to 00. □\square

Lemma 2 (the congruence). For every subset TT tried at line L7, X2≡Y2(modN)X^2 \equiv Y^2 \pmod N.

Proof. Each relation (z,v)(z, v) has z2≡∏p∈Fpvp(modN)z^2 \equiv \prod_{p \in F} p^{v_p} \pmod N by line L5. Let e=∑(z,v)∈Tve = \sum_{(z, v) \in T} v. By Lemma 1 every epe_p is even, so X2≡∏(z,v)∈Tz2≡∏p∈Fpep=(∏p∈Fpep/2)2≡Y2(modN)X^2 \equiv \prod_{(z, v) \in T} z^2 \equiv \prod_{p \in F} p^{e_p} = \big(\prod_{p \in F} p^{e_p/2}\big)^2 \equiv Y^2 \pmod N. □\square

Lemma 3 (square roots). Let NN be odd with exactly rr distinct prime factors, and let ϕ:U→U\phi: U \to U be z↦z2 mod Nz \mapsto z^2 \bmod N. Each nonempty fiber ϕ−1(s)\phi^{-1}(s) is a coset wHwH of the kernel H={h∈U:h2≡1}H = \{h \in U : h^2 \equiv 1\}, and ∣H∣=2r|H| = 2^r. For units X,YX, Y with X2≡Y2X^2 \equiv Y^2, gcd⁡(X−Y,N)\gcd(X - Y, N) is a proper factor of NN if and only if X≢±Y(modN)X \not\equiv \pm Y \pmod N.

Proof. ϕ\phi is a homomorphism of the abelian group UU, so its fibers are the cosets of its kernel HH. By the Chinese remainder theorem, HH is the product of the groups {h mod pj:h2≡1}\{h \bmod p^j : h^2 \equiv 1\} over the prime powers pj∥Np^j \parallel N. For odd pp, the group of units modulo pjp^j is cyclic of even order, so it has exactly two elements with square 11, namely ±1\pm 1. Hence ∣H∣=2r|H| = 2^r.

For the second claim, N∣(X−Y)(X+Y)N \mid (X - Y)(X + Y). If X≡YX \equiv Y, the gcd is NN. If X≡−YX \equiv -Y, then X−Y≡−2YX - Y \equiv -2Y is a unit because NN is odd, so the gcd is 11. Conversely, if the gcd is NN then X≡YX \equiv Y. If the gcd is 11, then N∣X+YN \mid X + Y, so X≡−YX \equiv -Y. In all other cases 1<gcd⁡(X−Y,N)<N1 < \gcd(X - Y, N) < N. □\square

Theorem. The algorithm stops and returns 11 or a proper factor of NN. Suppose NN is odd with r≥2r \ge 2 distinct prime factors. Then, conditioned on the event that the run reaches line L6, each subset TT that line L6 produces gives a proper factor at line L8 with probability at least 1−21−r≥1/21 - 2^{1-r} \ge 1/2.

Proof. Termination. The loop of lines L2 to L5 makes at most II draws. Each smoothness test divides a positive integer by primes, so it stops. Line L6 runs Lemma 1 on finitely many rows, and lines L7 and L8 run once per subset.

Correctness. At line L4, 1≤z≤N−11 \le z \le N - 1, so g=gcd⁡(z,N)≤z<Ng = \gcd(z, N) \le z < N, and g>1g > 1 is tested; so gg is a proper factor. Line L8 returns g=gcd⁡(X−Y,N)g = \gcd(X - Y, N) only if 1<g<N1 < g < N. Otherwise line L9 returns 11. So the output is always 11 or a proper factor. A prime NN has no proper factor, so the output is 11.

Probability. The run reaches line L6 exactly when no draw had gcd⁡(z,N)>1\gcd(z, N) > 1. Conditioned on this, the draws z1,z2,…z_1, z_2, \dots are independent and uniform on UU. Condition further on the values st=zt2 mod Ns_t = z_t^2 \bmod N. By Lemma 3, each ztz_t is then uniform on the coset ϕ−1(st)=wtH\phi^{-1}(s_t) = w_t H, and the ztz_t stay independent, because the fibers of ϕ\phi all have size 2r2^r and the draws were independent. Every choice of the algorithm before line L8 depends only on the values sts_t: the number of draws, the smoothness test, the vectors, the subsets of Lemma 1 and the value YY. So, given the sts_t, the subset TT and YY are fixed. Also YY is a unit: if a prime p∈Fp \in F divides NN, it does not divide sts_t, because st≡zt2(modp)s_t \equiv z_t^2 \pmod p with p∤ztp \nmid z_t, so ep=0e_p = 0.

Pick one relation j0∈Tj_0 \in T and write X=zj0CX = z_{j_0} C, where CC is the product of the other zz in TT modulo NN and is independent of zj0z_{j_0}. Given CC, XX is uniform on the coset wj0CHw_{j_0} C H, which has 2r2^r elements. By Lemma 2, X2≡Y2X^2 \equiv Y^2, so ±Y\pm Y lie in this coset too, and they are two distinct elements since NN is odd and YY is a unit. So X≡±YX \equiv \pm Y has probability 2/2r=21−r2/2^r = 2^{1-r}. By Lemma 3, line L8 finds a proper factor in every other case. Since this holds for every value of the conditions, it holds after removing them. ■\blacksquare

Back to Dixon's random squares algorithm