Algorithm Search⌘K

Proofs: Continued fraction factorization (CFRAC)

These are the human proofs of Continued fraction factorization (CFRAC), at full length.

Correctness of continued fraction factorization full

This proof shows: correctness, termination.

Let D=kND = kN, not a perfect square, so D\sqrt D is irrational, and let a=⌊D⌋a = \lfloor \sqrt D \rfloor. For integers PP and Q≠0Q \ne 0, the number x=(P+D)/Qx = (P + \sqrt D)/Q has conjugate xˉ=(P−D)/Q\bar x = (P - \sqrt D)/Q. Call xx reduced if x>1x > 1 and −1<xˉ<0-1 < \bar x < 0. Since 11 and D\sqrt D are linearly independent over Q\mathbb Q, the map u+vD↦u−vDu + v\sqrt D \mapsto u - v\sqrt D for rational u,vu, v is a field automorphism of Q(D)\mathbb Q(\sqrt D); it fixes the rationals.

Lemma 1 (the step). Let x=(P+D)/Qx = (P + \sqrt D)/Q be reduced, with integers PP, Q>0Q > 0 and an integer Q′Q' such that QQ′=D−P2QQ' = D - P^2. Let b=⌊(a+P)/Q⌋b = \lfloor (a + P)/Q \rfloor, P+=bQ−PP^+ = bQ - P and Q+=Q′+b(P−P+)Q^+ = Q' + b(P - P^+). Then 0<P<D0 < P < \sqrt D, 0<Q<2D0 < Q < 2\sqrt D, b=⌊x⌋≥1b = \lfloor x \rfloor \ge 1, QQ+=D−(P+)2QQ^+ = D - (P^+)^2, and x+=(P++D)/Q+x^+ = (P^+ + \sqrt D)/Q^+ is reduced with x+=1/(x−b)x^+ = 1/(x - b).

Proof. From x>1>−xˉx > 1 > -\bar x we get x+xˉ=2P/Q>0x + \bar x = 2P/Q > 0, so P>0P > 0; from xˉ<0\bar x < 0, P<DP < \sqrt D. From x>1x > 1, Q<P+D<2DQ < P + \sqrt D < 2\sqrt D. For a real yy and a positive integer QQ, ⌊y/Q⌋=⌊⌊y⌋/Q⌋\lfloor y/Q \rfloor = \lfloor \lfloor y \rfloor / Q \rfloor, and ⌊P+D⌋=P+a\lfloor P + \sqrt D \rfloor = P + a, so ⌊x⌋=⌊(P+a)/Q⌋=b\lfloor x \rfloor = \lfloor (P + a)/Q \rfloor = b. As x>1x > 1, b≥1b \ge 1.

Next, (P+)2−P2=(P+−P)(P++P)=(P+−P)bQ(P^+)^2 - P^2 = (P^+ - P)(P^+ + P) = (P^+ - P) bQ, so D−(P+)2=QQ′−bQ(P+−P)=Q(Q′+b(P−P+))=QQ+D - (P^+)^2 = QQ' - bQ(P^+ - P) = Q(Q' + b(P - P^+)) = QQ^+.

Now x−b=(D−P+)/Qx - b = (\sqrt D - P^+)/Q, and 0<x−b<10 < x - b < 1 since xx is irrational. As DD is not a square, QQ+=D−(P+)2≠0QQ^+ = D - (P^+)^2 \ne 0, so Q+≠0Q^+ \ne 0 and x+=1/(x−b)=Q(D+P+)/(D−(P+)2)=(P++D)/Q+x^+ = 1/(x - b) = Q(\sqrt D + P^+)/(D - (P^+)^2) = (P^+ + \sqrt D)/Q^+. From 0<x−b<10 < x - b < 1, x+>1x^+ > 1. The conjugate gives xˉ+=1/(xˉ−b)\bar x^+ = 1/(\bar x - b), and xˉ−b<−1\bar x - b < -1 because xˉ<0\bar x < 0 and b≥1b \ge 1, so −1<xˉ+<0-1 < \bar x^+ < 0. Then x+−xˉ+=2D/Q+>0x^+ - \bar x^+ = 2\sqrt D/Q^+ > 0, so Q+>0Q^+ > 0. Hence x+x^+ is reduced. □\square

Lemma 2 (the expansion). Let P1=aP_1 = a, Q0=1Q_0 = 1, Q1=D−a2Q_1 = D - a^2, and define bib_i, Pi+1P_{i+1}, Qi+1Q_{i+1} by the recurrence of line L5. Let xi=(Pi+D)/Qix_i = (P_i + \sqrt D)/Q_i. Then for every i≥1i \ge 1, xix_i is reduced, Qi−1Qi=D−Pi2Q_{i-1}Q_i = D - P_i^2, 0<Qi<2D0 < Q_i < 2\sqrt D, bi=⌊xi⌋b_i = \lfloor x_i \rfloor and xi+1=1/(xi−bi)x_{i+1} = 1/(x_i - b_i). Also D=a+1/x1\sqrt D = a + 1/x_1.

Proof. Q1=D−a2≥1Q_1 = D - a^2 \ge 1 since DD is not a square, and Q0Q1=D−P12Q_0 Q_1 = D - P_1^2. Since 0<D−a<10 < \sqrt D - a < 1, x1=(a+D)/(D−a2)=1/(D−a)>1x_1 = (a + \sqrt D)/(D - a^2) = 1/(\sqrt D - a) > 1, which also gives D=a+1/x1\sqrt D = a + 1/x_1. And xˉ1=1/(−D−a)\bar x_1 = 1/(-\sqrt D - a) lies in (−1,0)(-1, 0) because D+a>1\sqrt D + a > 1. So x1x_1 is reduced. Lemma 1 with (P,Q′,Q)=(Pi,Qi−1,Qi)(P, Q', Q) = (P_i, Q_{i-1}, Q_i) gives all the claims for ii and passes the hypotheses on to i+1i + 1. Induction on ii completes the proof. □\square

Lemma 3 (convergents). Let A−1=1A_{-1} = 1, A0=aA_0 = a, B−1=0B_{-1} = 0, B0=1B_0 = 1, and Ai=biAi−1+Ai−2A_i = b_i A_{i-1} + A_{i-2}, Bi=biBi−1+Bi−2B_i = b_i B_{i-1} + B_{i-2} for i≥1i \ge 1. Then for every i≥1i \ge 1:

  1. D=(Ai−1xi+Ai−2)/(Bi−1xi+Bi−2)\sqrt D = (A_{i-1} x_i + A_{i-2})/(B_{i-1} x_i + B_{i-2}),
  2. Ai−1Bi−2−Ai−2Bi−1=(−1)iA_{i-1} B_{i-2} - A_{i-2} B_{i-1} = (-1)^i,
  3. Ai−12−DBi−12=(−1)iQiA_{i-1}^2 - D B_{i-1}^2 = (-1)^i Q_i.

Proof. (1) For i=1i = 1 the right side is (ax1+1)/x1=a+1/x1=D(a x_1 + 1)/x_1 = a + 1/x_1 = \sqrt D by Lemma 2. If (1) holds for ii, substitute xi=bi+1/xi+1x_i = b_i + 1/x_{i+1} from Lemma 2. The numerator becomes Ai−1bi+Ai−2+Ai−1/xi+1=(Aixi+1+Ai−1)/xi+1A_{i-1} b_i + A_{i-2} + A_{i-1}/x_{i+1} = (A_i x_{i+1} + A_{i-1})/x_{i+1}, and in the same way the denominator becomes (Bixi+1+Bi−1)/xi+1(B_i x_{i+1} + B_{i-1})/x_{i+1}; so (1) holds for i+1i + 1. The denominators are positive, since all Bj≥0B_j \ge 0, Bi−1≥1B_{i-1} \ge 1 for i≥1i \ge 1, and xi>0x_i > 0.

(2) For i=1i = 1: A0B−1−A−1B0=0−1=−1A_0 B_{-1} - A_{-1} B_0 = 0 - 1 = -1. And AiBi−1−Ai−1Bi=(biAi−1+Ai−2)Bi−1−Ai−1(biBi−1+Bi−2)=−(Ai−1Bi−2−Ai−2Bi−1)A_i B_{i-1} - A_{i-1} B_i = (b_i A_{i-1} + A_{i-2}) B_{i-1} - A_{i-1}(b_i B_{i-1} + B_{i-2}) = -(A_{i-1} B_{i-2} - A_{i-2} B_{i-1}), so the sign alternates.

(3) Multiply (1) out: xi(DBi−1−Ai−1)=Ai−2−DBi−2x_i(\sqrt D B_{i-1} - A_{i-1}) = A_{i-2} - \sqrt D B_{i-2}. Let M=Ai−12−DBi−12M = A_{i-1}^2 - D B_{i-1}^2, a nonzero integer since D\sqrt D is irrational. Multiplying both sides by DBi−1+Ai−1\sqrt D B_{i-1} + A_{i-1} gives −Mxi=(Ai−2−DBi−2)(DBi−1+Ai−1)=U+D(Ai−2Bi−1−Ai−1Bi−2)-M x_i = (A_{i-2} - \sqrt D B_{i-2})(\sqrt D B_{i-1} + A_{i-1}) = U + \sqrt D (A_{i-2} B_{i-1} - A_{i-1} B_{i-2}) with the integer U=Ai−1Ai−2−DBi−1Bi−2U = A_{i-1} A_{i-2} - D B_{i-1} B_{i-2}. By (2) this is U−(−1)iDU - (-1)^i \sqrt D. So xi=((−1)iD−U)/Mx_i = ((-1)^i \sqrt D - U)/M. We also have xi=Pi/Qi+D/Qix_i = P_i/Q_i + \sqrt D/Q_i. Since 11 and D\sqrt D are linearly independent over Q\mathbb Q, the coefficients of D\sqrt D agree: 1/Qi=(−1)i/M1/Q_i = (-1)^i/M, so M=(−1)iQiM = (-1)^i Q_i. □\square

Lemma 4 (the loop of lines L3 to L5). At each test of line L4, with step counter ii, the variables hold P=PiP = P_i, Q=QiQ = Q_i, Q′=Qi−1Q' = Q_{i-1} and A=Ai−1 mod NA = A_{i-1} \bmod N, A′=Ai−2 mod NA' = A_{i-2} \bmod N. Every relation (A,v)(A, v) in RR satisfies A2≡∏p∈Fpvp(modN)A^2 \equiv \prod_{p \in F} p^{v_p} \pmod N, where vv is the exponent vector and p=−1p = -1 is included.

Proof. Line L2 sets P=a=P1P = a = P_1, Q′=1=Q0Q' = 1 = Q_0, Q=Q1Q = Q_1, A′=1=A−1A' = 1 = A_{-1}, A=A0 mod NA = A_0 \bmod N and i=1i = 1. Line L5 is the recurrence of Lemma 2 for PP and QQ, and it replaces (A′,A)(A', A) by (A,(bA+A′) mod N)(A, (bA + A') \bmod N) with b=bib = b_i, which is (Ai−1,Ai)(A_{i-1}, A_i) modulo NN because reduction modulo NN commutes with sums and products. Then ii grows by one, so the invariant holds at the next test. Line L4 appends (A,v)(A, v) only if (−1)iQi=∏p∈Fpvp(-1)^i Q_i = \prod_{p \in F} p^{v_p}. By Lemma 3, Ai−12=DBi−12+(−1)iQiA_{i-1}^2 = D B_{i-1}^2 + (-1)^i Q_i, and N∣DN \mid D, so A2≡Ai−12≡(−1)iQi(modN)A^2 \equiv A_{i-1}^2 \equiv (-1)^i Q_i \pmod N. □\square

Lemma 5 (the elimination). Let v1,…,vmv_1, \dots, v_m be the exponent vectors mod 2, as bit masks. The elimination keeps for each pivot a pair (u,h)(u, h) with u=⨁j∈hvju = \bigoplus_{j \in h} v_j, where ⊕\oplus is the sum mod 2. When row jj reduces to 00, the subset hh it carries is nonempty and ⨁l∈hvl=0\bigoplus_{l \in h} v_l = 0. If m>∣F∣m > |F|, at least m−∣F∣m - |F| subsets are found.

Proof. Row jj starts with u=vju = v_j and h={j}h = \{j\}. Each reduction adds a pivot pair (u′,h′)(u', h') to (u,h)(u, h) by ⊕\oplus in both parts, which keeps u=⨁l∈hvlu = \bigoplus_{l \in h} v_l. The pivots stored before row jj come from rows l<jl < j, so their sets h′h' do not contain jj, and jj stays in hh; thus h≠∅h \ne \emptyset. A row either becomes a new pivot, with a leading bit that no other pivot has, or reduces to u=0u = 0. Each reduction step clears the leading bit of uu and changes only lower bits, so the process ends. The pivots have distinct leading bits among the ∣F∣|F| positions, so there are at most ∣F∣|F| pivots, and at least m−∣F∣m - |F| rows reduce to 00. □\square

Theorem. CFRAC stops, and it returns either 11 or a proper factor gg of NN with 1<g<N1 < g < N. Every subset TT tried at line L7 gives X2≡Y2(modN)X^2 \equiv Y^2 \pmod N. When the loop ends with ∣R∣=∣F∣+E|R| = |F| + E, at least EE subsets are tried.

Proof. Termination. Each pass of the loop increases ii, and the loop stops when i≥Ii \ge I, so it makes fewer than II passes. All divisions in line L5 are by Q=Qi>0Q = Q_i > 0 (Lemma 2). The smoothness test of line L4 divides a nonzero integer by primes and stops. Line L6 runs Lemma 5 on finitely many rows, and lines L7 and L8 run once per subset. So the algorithm stops.

Congruence of squares. Let TT be a subset with ⨁j∈Tvj=0\bigoplus_{j \in T} v_j = 0, and let e=∑j∈Tvje = \sum_{j \in T} v_j over the integers. Then every epe_p is even, including e−1e_{-1}. By Lemma 4, X2=∏j∈TAj2≡∏p∈Fpep=(−1)e−1∏p≠−1(pep/2)2=Y2(modN)X^2 = \prod_{j \in T} A_j^2 \equiv \prod_{p \in F} p^{e_p} = (-1)^{e_{-1}} \prod_{p \ne -1} \big(p^{e_p/2}\big)^2 = Y^2 \pmod N, since (−1)e−1=1(-1)^{e_{-1}} = 1. The count of subsets follows from Lemma 5 with m=∣F∣+Em = |F| + E.

Correctness. The only return other than line L9 is line L8, which returns g=gcd⁡(X−Y,N)g = \gcd(X - Y, N) only if 1<g<N1 < g < N. A gcd with NN divides NN, so gg is a proper factor. Otherwise line L9 returns 11. ■\blacksquare

Back to Continued fraction factorization (CFRAC)