Salta al contenuto
Note per Studenti Structured Block Matrices - Reducing Recursive Calls Report

Structured Block Matrices - Reducing Recursive Calls

In questa pagina 3

A matrix with a lot of repetition can be handled with algorithms that are sublinear in the number of entries. A matrix n×nn\times n, n=2kn=2^k, belongs to a recursive family if n=1n=1 or it is made of n2×n2\frac n2\times\frac n2 blocks that are repeated or related and belong to the same family. Typical requests: (1) closure under sum, difference (and sometimes product), by induction; (2) algorithms for sum, difference, product (or matrix-vector product, or inverse) with o(n2)o(n^2) scalar operations (hint: "only three" or "only two" recursive calls); (3) the recurrence and its order via the Master TheoremThe Master Theorem for T(n) = aT(n/b) + w(n) compares w(n) with the threshold n^(log_b a). Case 1 (w polynomially smaller): Theta(n^(log_b a)); case 2 (same order): Theta(n^(log_b a) log n); case 3 (polynomially larger and regular): Theta(w(n)). Full proof from the levels of the tree, extended version with floors and ceilings, a table of applications, and the misuse when no case applies (w = n log n).Master Theorem →. Prerequisites: Matrix Multiplication - Iterative and Recursive Block ProductCost model on n x n matrices (scalar operations, size n or N = n^2); sum in n^2 operations (optimal); iterative row-by-column product with exact cost 2n^3 - n^2; the fractal property of the block product proved on indices; recursive algorithm RMUL with T(n) = 8T(n/2) + n^2, Theta(n^3) and exact solution 2n^3 - n^2: it performs the same operations as the iterative one.Matrix Multiplication - Iterative and Recursive Block Product →, Strassen's AlgorithmStrassen computes the n x n product with 7 recursive calls instead of 8, using 10 matrix additions in Divide and 8 in Conquer: T(n) = 7T(n/2) + (9/2)n^2, Theta(n^(log2 7)) with exact solution 7n^(log2 7) - 6n^2. Its leading constant 7 is more than three times that of the iterative algorithm (2), so Strassen beats it only from n = 655 (from 1024 for powers of two).Strassen's Algorithm →. The supercirculant family is treated in full in Supercirculant and Circulant MatricesSupercirculant matrices (alternating recursive quadrants) have only n distinct values: sum in n operations, product in 4n log2 n + n with the trick (A1+A2)(B1+B2) and (A1-A2)(B1-B2) instead of 4 calls (Theta(n^2)); their eigenvalues are the Hadamard transform of the first row (FHT, n log2 n). Circulant matrices are polynomials in the rotation matrix R, their product is the cyclic convolution of the first rows, and the Fourier matrix diagonalizes them: product in O(n log n) with the FFT.Supercirculant and Circulant Matrices →.

The method in five steps

  1. Count the free parameters. A matrix of the family is determined by its independent blocks; recursively only nn scalars remain, not n2n^2. E.g. SIR (blocks (T10T2T1)\begin{pmatrix}T_1&0\\T_2&T_1\end{pmatrix}, two independent blocks): p(n)=2p(n2)p(n)=2p(\frac n2), p(1)=1p(1)=1, so p(n)=np(n)=n. Sum and difference then cost nn: two calls on n2\frac n2, no internal work, T(n)=2T(n2)T(n)=2T(\frac n2), T(1)=1T(1)=1. Repeated or opposite blocks cost nothing (already known).
  2. Write the block product with the row-by-column rule, substituting the structure.
  3. Closure. The blocks of the result are sums, differences and products of blocks of the family; the induction hypothesis (which must hold for all three operations) places them in the family. Base n=1n=1: every scalar belongs.
  4. Count the distinct block products in the result. If there are aa products of size n2\frac n2 and the border sums cost Θ(n)\Theta(n), then T(n)=aT(n2)+Θ(n)T(n)=aT(\frac n2)+\Theta(n) and the MT gives Θ(nlog⁡2a)\Theta(n^{\log_2a}): a=4a=4 is not enough (Θ(n2)\Theta(n^2)), a=3a=3 gives Θ(n1.585)\Theta(n^{1.585}), a=2a=2 gives Θ(nlog⁡n)\Theta(n\log n).
  5. Reduce aa with sums and differences (two models below), then write the exact recurrence, solve it with the general formula (Recurrence Relations - Recursion Tree and General FormulaThe recurrence tree has the shape of the call tree of the worst instance and T(n) is the sum of the works of its nodes. For the family T(n) = s(n) T(f(n)) + w(n) with base T0 for n <= n0, counting nodes per level with the iterates of f and the level f*(n,n0) gives the closed formula T(n) = sum over levels of [product of s] w + [product of s] T0, proved by induction and applied to merge sort, Hanoi and square-root recurrences.Recurrence Relations - Recursion Tree and General Formula →) and check with n=1,2,4n=1,2,4.

Two reduction models

Sum-and-difference model (SC, RCA). The result has blocks C1=A1B1+A2B2C_1=A_1B_1+A_2B_2, C2=A1B2+A2B1C_2=A_1B_2+A_2B_1 (four products). Compute U=(A1+A2)(B1+B2),V=(A1−A2)(B1−B2).U=(A_1+A_2)(B_1+B_2),\qquad V=(A_1-A_2)(B_1-B_2). The mixed terms change sign in VV: U+V=2C1U+V=2C_1, U−V=2C2U-V=2C_2. Two products, four sums in Divide, two in Conquer and two products by 12\frac12: eight operations on size n2\frac n2, so T(n)=2T(n2)+4nT(n)=2T(\frac n2)+4n, exact 4nlog⁡2n+n4n\log_2n+n. For the RCA matrix-vector product the same idea with X=A+BX=A+B, W=A−BW=A-B, r=u+vr=u+v, s=u−vs=u-v gives the same 4nlog⁡2n+n4n\log_2n+n.

Gauss model (ARB). The block product of (AB−BA)\begin{pmatrix}A&B\\-B&A\end{pmatrix} and (CD−DC)\begin{pmatrix}C&D\\-D&C\end{pmatrix} is (EF−FE)\begin{pmatrix}E&F\\-F&E\end{pmatrix} with E=AC−BDE=AC-BD, F=AD+BCF=AD+BC: four products. Compute instead U=ACU=AC, V=BDV=BD, Z=(A+B)(C+D)=AC+AD+BC+BDZ=(A+B)(C+D)=AC+AD+BC+BD (three products). Then E=U−VE=U-V, F=Z−U−VF=Z-U-V: the idea of multiplying complex numbers with three real products. Six operations on size n2\frac n2 (A+BA+B, C+DC+D, U−VU-V, U+VU+V, Z−(U+V)Z-(U+V) and the sign change for −F-F), so T(n)=3T(n2)+3nT(n)=3T(\frac n2)+3n, exact 7nlog⁡23−6n7n^{\log_23}-6n.

When no trick is needed (SIR). TV=(T1V10T2V1+T1V2T1V1)TV=\begin{pmatrix}T_1V_1&0\\T_2V_1+T_1V_2&T_1V_1\end{pmatrix} has three distinct products (T1V1T_1V_1 appears twice, computed once): already a=3a=3, T(n)=3T(n2)+n2T(n)=3T(\frac n2)+\frac n2, exact 2nlog⁡23−n2n^{\log_23}-n. For the inverse T−1=(T1−10−T1−1T2T1−1T1−1)T^{-1}=\begin{pmatrix}T_1^{-1}&0\\-T_1^{-1}T_2T_1^{-1}&T_1^{-1}\end{pmatrix}: one recursive call plus two products, Tinv(n)=Tinv(n2)+2Tmult(n2)T_{inv}(n)=T_{inv}(\frac n2)+2T_{mult}(\frac n2), exact 2nlog⁡23−2n+12n^{\log_23}-2n+1 (sign changes not counted).

family blocks operation recursive products recurrence order
SC (A1A2A2A1)\begin{pmatrix}A_1&A_2\\A_2&A_1\end{pmatrix} product 4→24\to2 2T(n2)+4n2T(\frac n2)+4n Θ(nlog⁡n)\Theta(n\log n)
ARB (AB−BA)\begin{pmatrix}A&B\\-B&A\end{pmatrix} product 4→34\to3 3T(n2)+3n3T(\frac n2)+3n Θ(nlog⁡23)\Theta(n^{\log_23})
SIR (T10T2T1)\begin{pmatrix}T_1&0\\T_2&T_1\end{pmatrix} product 33 (already) 3T(n2)+n23T(\frac n2)+\frac n2 Θ(nlog⁡23)\Theta(n^{\log_23})
SIR as above inverse 11 call + 2+\,2 products T(n2)+2Tmult(n2)T(\frac n2)+2T_{mult}(\frac n2) Θ(nlog⁡23)\Theta(n^{\log_23})
RCA (AB−B−A)\begin{pmatrix}A&B\\-B&-A\end{pmatrix} matrix-vector 4→24\to2 2T(n2)+4n2T(\frac n2)+4n Θ(nlog⁡n)\Theta(n\log n)
any sum or difference 22 (on independent blocks) 2T(n2)2T(\frac n2) nn

When closure fails: the product of two RCA

For T=(AB−B−A)T=\begin{pmatrix}A&B\\-B&-A\end{pmatrix}, V=(CD−D−C)V=\begin{pmatrix}C&D\\-D&-C\end{pmatrix} the block product is TV=(AC−BDAD−BC−BC+AD−BD+AC)=(EFFE),E=AC−BD, F=AD−BC,TV=\begin{pmatrix}AC-BD&AD-BC\\-BC+AD&-BD+AC\end{pmatrix}=\begin{pmatrix}E&F\\F&E\end{pmatrix},\qquad E=AC-BD,\ F=AD-BC, the shape of a supercirculant, not of an RCA (which would need −F-F bottom-left). For n=2n=2: T=(12−2−1)T=\begin{pmatrix}1&2\\-2&-1\end{pmatrix}, V=(31−1−3)V=\begin{pmatrix}3&1\\-1&-3\end{pmatrix} give TV=(1−5−51)TV=\begin{pmatrix}1&-5\\-5&1\end{pmatrix}, not RCA (−5≠−(−5)-5\ne-(-5)). So the hypothesis "the product of two RCA is RCA" is false, and a recursive product algorithm could not call itself on the blocks ACAC, BDBD, ... Hence one asks only for the product by a vector. Always check closure (step 3) before designing the algorithm.

Versione ripasso

Teoria collegata