Algorithm Search⌘K

Proofs: Fast Hartley transform

These are the human proofs of Fast Hartley transform, at full length.

The radix-2 fast Hartley transform computes the DHT, is its own inverse up to 1/n, and has a first-order error bound linear in lg n full

This proof shows: correctness, complexity, error-bound.

Let n=2tn = 2^t, let x∈Rnx \in \mathbb{R}^n be the input and x′x' the array as the algorithm changes it. For a vector yy of length NN, write DHTN(y)k=∑mym cas(2πmk/N)\mathrm{DHT}_N(y)_k = \sum_{m} y_m \, \mathrm{cas}(2\pi mk/N), with indices of DHTN(y)\mathrm{DHT}_N(y) taken modulo NN. As in the proof for the FFT, for h=2qh = 2^q and h∣sh \mid s let c(s,h)=revt−q(s/h)c(s, h) = \mathrm{rev}_{t-q}(s/h) and let x(s,h)x^{(s,h)} be the subsequence xm(s,h)=xc(s,h)+mn/hx^{(s,h)}_m = x_{c(s,h) + m n/h}, 0≤m<h0 \le m < h.

Lemma 1 (cas of a sum). cas(a+b)=cos⁡b cas a+sin⁡b cas(−a)\mathrm{cas}(a + b) = \cos b \, \mathrm{cas}\,a + \sin b \, \mathrm{cas}(-a).

Proof. cos⁡(a+b)+sin⁡(a+b)=cos⁡acos⁡b−sin⁡asin⁡b+sin⁡acos⁡b+cos⁡asin⁡b=cos⁡b(cos⁡a+sin⁡a)+sin⁡b(cos⁡a−sin⁡a)\cos(a + b) + \sin(a + b) = \cos a \cos b - \sin a \sin b + \sin a \cos b + \cos a \sin b = \cos b (\cos a + \sin a) + \sin b (\cos a - \sin a), and cos⁡a−sin⁡a=cas(−a)\cos a - \sin a = \mathrm{cas}(-a). □\square

Lemma 2 (merge). Let N=2hN = 2h, y∈RNy \in \mathbb{R}^N, and let EE and OO be the DHTs of length hh of (y0,y2,…)(y_0, y_2, \ldots) and (y1,y3,…)(y_1, y_3, \ldots). Put θk=2πk/N\theta_k = 2\pi k/N. Then for 0≤k<h0 \le k < h,

DHTN(y)k=Ek+cos⁡θk Ok+sin⁡θk Oh−k,DHTN(y)k+h=Ek−cos⁡θk Ok−sin⁡θk Oh−k,\mathrm{DHT}_N(y)_k = E_k + \cos\theta_k \, O_k + \sin\theta_k \, O_{h-k}, \qquad \mathrm{DHT}_N(y)_{k+h} = E_k - \cos\theta_k \, O_k - \sin\theta_k \, O_{h-k},

with Oh−0=O0O_{h-0} = O_0.

Proof. Split the sum by the parity of the index. For any integer k′k', the even part is ∑my2m cas(2πmk′/h)=Ek′\sum_m y_{2m} \, \mathrm{cas}(2\pi m k'/h) = E_{k'}, and the odd part is ∑my2m+1 cas(2πmk′/h+θk′)\sum_m y_{2m+1} \, \mathrm{cas}(2\pi m k'/h + \theta_{k'}), which by Lemma 1 equals cos⁡θk′ Ok′+sin⁡θk′∑my2m+1 cas(−2πmk′/h)=cos⁡θk′ Ok′+sin⁡θk′ O−k′\cos\theta_{k'} \, O_{k'} + \sin\theta_{k'} \sum_m y_{2m+1} \, \mathrm{cas}(-2\pi m k'/h) = \cos\theta_{k'} \, O_{k'} + \sin\theta_{k'} \, O_{-k'}. For k′=kk' = k this is the first formula. For k′=k+hk' = k + h, EE and OO have period hh, and θk+h=θk+π\theta_{k+h} = \theta_k + \pi flips the signs of cos⁡\cos and sin⁡\sin, which gives the second formula. □\square

Lemma 3 (the four-point butterfly). For 1≤k<h/21 \le k < h/2, lines L10 to L13 store the four values of Lemma 2 for the indices kk, k+hk + h, h−kh - k and 2h−k2h - k of a block, and lines L6 and L7 store those for k=0k = 0, hh, h/2h/2 and 3h/23h/2.

Proof. In line L9, c=cos⁡θkc = \cos\theta_k and σ=sin⁡θk\sigma = \sin\theta_k with θk=πk/h\theta_k = \pi k/h. Line L10 reads a=Oka = O_k and b=Oh−kb = O_{h-k} and sets t1=cos⁡θkOk+sin⁡θkOh−kt_1 = \cos\theta_k O_k + \sin\theta_k O_{h-k}. Since θh−k=π−θk\theta_{h-k} = \pi - \theta_k, cos⁡θh−k=−c\cos\theta_{h-k} = -c and sin⁡θh−k=σ\sin\theta_{h-k} = \sigma, so the odd term of Lemma 2 for the index h−kh - k is −c Oh−k+σ Ok=t2-c \, O_{h-k} + \sigma \, O_k = t_2. Line L11 saves EkE_k and Eh−kE_{h-k}, and lines L12 and L13 store Ek±t1E_k \pm t_1 and Eh−k±t2E_{h-k} \pm t_2 at the places kk, k+hk + h, h−kh - k, 2h−k2h - k, which are the values of Lemma 2. The four cells read are the four cells written, and the sets {k,h−k}\{k, h - k\} for 1≤k<h/21 \le k < h/2 are disjoint from each other and from {0,h/2}\{0, h/2\}, so no value is overwritten before it is read. For k=0k = 0, θ0=0\theta_0 = 0 and Oh=O0O_{h} = O_0, giving E0±O0E_0 \pm O_0 (line L6); for k=h/2k = h/2, θ=π/2\theta = \pi/2 and Oh−h/2=Oh/2O_{h - h/2} = O_{h/2}, giving Eh/2±Oh/2E_{h/2} \pm O_{h/2} (line L7). For h=1h = 1 only k=0k = 0 occurs, and for h=2h = 2 only k=0k = 0 and k=1=h/2k = 1 = h/2. □\square

Theorem 1 (forward). FHT(x)(x) replaces xx by DHTn(x)\mathrm{DHT}_n(x).

Proof. The invariant is: when line L4 tests h=2qh = 2^q, for every block start ss with h∣sh \mid s, x′[s…s+h−1]=DHTh(x(s,h))x'[s \ldots s + h - 1] = \mathrm{DHT}_h(x^{(s,h)}). After line L2, x′[j]=xrevt(j)=x0(j,1)x'[j] = x_{\mathrm{rev}_t(j)} = x^{(j,1)}_0, and a DHT of length 11 is the identity, so the invariant holds for h=1h = 1. If it holds for h<nh < n, take a block start ss with 2h∣s2h \mid s. By Lemma 2 of the FFT proof (which concerns only the indices), x(s,h)x^{(s,h)} and x(s+h,h)x^{(s+h,h)} are the even and the odd entries of x(s,2h)x^{(s,2h)}, so the two halves of the block hold EE and OO for y=x(s,2h)y = x^{(s,2h)}. By Lemma 3, one pass of lines L6 to L13 writes DHT2h(y)\mathrm{DHT}_{2h}(y) into the block, and different blocks are disjoint. After line L14 the invariant holds for 2h2h. When h=nh = n, the only block is s=0s = 0 with x(0,n)=xx^{(0,n)} = x. □\square

Theorem 2 (inverse). Hn2=nI\mathcal H_n^2 = n I, so INVERSE-FHT(DHTn(x))=x(\mathrm{DHT}_n(x)) = x.

Proof. (Hn2)jl=∑kcas αk cas βk(\mathcal H_n^2)_{jl} = \sum_k \mathrm{cas}\,\alpha_k \, \mathrm{cas}\,\beta_k with αk=2πjk/n\alpha_k = 2\pi jk/n and βk=2πlk/n\beta_k = 2\pi lk/n. Expanding, cas a cas b=cos⁡acos⁡b+sin⁡asin⁡b+sin⁡acos⁡b+cos⁡asin⁡b=cos⁡(a−b)+sin⁡(a+b)\mathrm{cas}\,a \, \mathrm{cas}\,b = \cos a \cos b + \sin a \sin b + \sin a \cos b + \cos a \sin b = \cos(a - b) + \sin(a + b). Now ∑kcos⁡(2π(j−l)k/n)+i∑ksin⁡(2π(j−l)k/n)=∑ke2πi(j−l)k/n\sum_k \cos(2\pi(j - l)k/n) + i \sum_k \sin(2\pi(j - l)k/n) = \sum_k e^{2\pi i (j-l)k/n}, which is nn if j≡lj \equiv l and 00 otherwise, by the summation lemma; so ∑kcos⁡(αk−βk)=n[j=l]\sum_k \cos(\alpha_k - \beta_k) = n [j = l]. Similarly ∑ksin⁡(2π(j+l)k/n)\sum_k \sin(2\pi(j + l)k/n) is the imaginary part of a sum that is real (nn or 00), so it is 00. Hence Hn2=nI\mathcal H_n^2 = n I. By Theorem 1, line L15 computes HnHnx=nx\mathcal H_n \mathcal H_n x = n x, and line L16 divides by nn. □\square

Operation count. For h=1h = 1, each of the n/2n/2 blocks does line L6 only: 22 additions. For h≥2h \ge 2, each of the n/(2h)n/(2h) blocks does lines L6 and L7 (44 additions) and h/2−1h/2 - 1 butterflies of lines L10 to L13, each with 44 multiplications and 2+4=62 + 4 = 6 additions. So the pass for h≥2h \ge 2 costs n2h(2h−4)=n−2nh\frac{n}{2h}(2h - 4) = n - \frac{2n}{h} multiplications and n2h(3h−2)=3n2−nh\frac{n}{2h}(3h - 2) = \frac{3n}{2} - \frac{n}{h} additions. Summing over h=2qh = 2^q, 1≤q≤t−11 \le q \le t - 1, with ∑q=1t−12−q=1−21−t\sum_{q=1}^{t-1} 2^{-q} = 1 - 2^{1-t}, the total for n≥2n \ge 2 is

n(t−1)−2n(1−21−t)=nlg⁡n−3n+4 multiplications,n+3n2(t−1)−n(1−21−t)=32nlg⁡n−32n+2 additions.n(t - 1) - 2n(1 - 2^{1-t}) = n \lg n - 3n + 4 \text{ multiplications}, \qquad n + \tfrac{3n}{2}(t - 1) - n(1 - 2^{1-t}) = \tfrac{3}{2} n \lg n - \tfrac{3}{2} n + 2 \text{ additions}.

Theorem 3 (rounding error). Suppose the computed pair (c^,σ^)(\hat c, \hat \sigma) in line L9 satisfies (c^−c)2+(σ^−σ)2≤μ\sqrt{(\hat c - c)^2 + (\hat\sigma - \sigma)^2} \le \mu, and let uu be the unit roundoff and γ2=2u/(1−2u)\gamma_2 = 2u/(1 - 2u). Then the computed H^\hat H satisfies ∥H^−H∥2≤lg⁡n η ∥H∥2+O(u2)\lVert \hat H - H \rVert_2 \le \lg n \, \eta \, \lVert H \rVert_2 + O(u^2), with η=u+2(μ+γ2)\eta = u + \sqrt 2 (\mu + \gamma_2).

Proof. Write the pass for hh as a matrix SqS_q (h=2q−1h = 2^{q-1}) acting on the whole array. On a block it maps (E,O)(E, O) to (E+RO,E−RO)(E + R O, E - R O), where RR fixes O0O_0 and Oh/2O_{h/2} and maps each pair (Ok,Oh−k)(O_k, O_{h-k}), 1≤k<h/21 \le k < h/2, by the matrix with rows (c,σ)(c, \sigma) and (σ,−c)(\sigma, -c), a reflection. So RR is orthogonal, and SqTSq=2IS_q^{\mathsf T} S_q = 2I block by block: Sq=2 QqS_q = \sqrt 2 \, Q_q with QqQ_q orthogonal.

Local error of one pass. Let zz be the computed array before the pass. For a butterfly with a=Oka = O_k, b=Oh−kb = O_{h-k}, the computed t^1=fl(c^a+σ^b)\hat t_1 = \mathrm{fl}(\hat c a + \hat\sigma b) satisfies ∣t^1−t1∣≤∣(c^−c)a+(σ^−σ)b∣+γ2(∣c^a∣+∣σ^b∣)≤(μ+γ2)a2+b2+O(u2)|\hat t_1 - t_1| \le |(\hat c - c) a + (\hat \sigma - \sigma) b| + \gamma_2 (|\hat c a| + |\hat \sigma b|) \le (\mu + \gamma_2) \sqrt{a^2 + b^2} + O(u^2) by the Cauchy-Schwarz inequality, and the same holds for t^2\hat t_2. So the errors τ\tau of all the tt values of a block satisfy ∑τ2≤2(μ+γ2)2∥O∥22+O(u3)\sum \tau^2 \le 2 (\mu + \gamma_2)^2 \lVert O \rVert_2^2 + O(u^3). Each τ\tau enters two outputs, e±t^e \pm \hat t, and each output addition adds a relative error at most uu. Hence the error of the pass is eqe_q with

∥eq∥2≤2(μ+γ2)∥z∥2+u∥Sqz∥2+O(u2)=η ∥Sqz∥2+O(u2),\lVert e_q \rVert_2 \le 2 (\mu + \gamma_2) \lVert z \rVert_2 + u \lVert S_q z \rVert_2 + O(u^2) = \eta \, \lVert S_q z \rVert_2 + O(u^2),

using ∥Sqz∥2=2∥z∥2\lVert S_q z \rVert_2 = \sqrt 2 \lVert z \rVert_2. Lines L6 and L7 contribute only the term with uu.

Accumulation. Line L2 is exact. With z0z_0 the permuted input and zq=Sqzq−1+eqz_q = S_q z_{q-1} + e_q, linearity gives zt=St⋯S1z0+∑q=1tSt⋯Sq+1eqz_t = S_t \cdots S_1 z_0 + \sum_{q=1}^{t} S_t \cdots S_{q+1} e_q. Since ∥St⋯Sq+1w∥2=2(t−q)/2∥w∥2\lVert S_t \cdots S_{q+1} w \rVert_2 = 2^{(t-q)/2} \lVert w \rVert_2 and ∥Sqzq−1∥2=2q/2∥x∥2(1+O(u))\lVert S_q z_{q-1} \rVert_2 = 2^{q/2} \lVert x \rVert_2 (1 + O(u)), each term has norm at most η 2t/2∥x∥2+O(u2)=η∥H∥2+O(u2)\eta \, 2^{t/2} \lVert x \rVert_2 + O(u^2) = \eta \lVert H \rVert_2 + O(u^2), because ∥H∥2=n∥x∥2\lVert H \rVert_2 = \sqrt n \lVert x \rVert_2 by Theorem 2. Summing t=lg⁡nt = \lg n terms gives the bound. ■\blacksquare

Back to Fast Hartley transform