Algorithm Search⌘K

Algorithmadvanced

Pade via Lanczos

Also called PVL, Feldmann-Freund PVL.

Feldmann and Freund's reduced-order model of a linear circuit that matches 2q moments of the transfer function stably using the nonsymmetric Lanczos process.

Time
O(F + q s + q N) worst
Space
O(N + q) extra
Where
F = the cost of one sparse LU factorization of G + s0 C; N = the number of MNA unknowns; q = the number of Lanczos steps (the order of the model); s = the cost of one solve with those factors plus one product with C
Properties
deterministicnot exactiterative
Origin
Peter Feldmann, Roland W. Freund, 1995

Padé via Lanczos (PVL) replaces a large linear circuit, such as an extracted interconnect, by a small model whose transfer function agrees with that of the circuit in its first 2q2q Taylor coefficients (moments) around an expansion point. It is the same Padé approximant that asymptotic waveform evaluation computes, but Feldmann and Freund (1995) obtain it from qq steps of the nonsymmetric Lanczos process, which never forms the moments and so stays accurate at orders where AWE fails. It belongs to the circuit simulation half of the logic and circuit simulation sub-area, next to PRIMA, which gives up some moments to keep passivity.

In plain words

A long wire on a chip, cut into many small resistors, capacitors and inductors, has thousands of equations. Its effect at its two ends can usually be described by a formula with a few terms. Model order reduction finds such a formula.

AWE finds it by measuring a list of numbers, the moments, and fitting a fraction of two polynomials to them. The trouble is that the later moments all look alike, so in computer arithmetic they carry almost no new information, and the fit stops getting better after about eight terms. PVL builds the same fraction another way: it walks step by step through the directions that the circuit reaches from its input and from its output, keeping each new direction separate from the old ones. Each step adds one pole to the model, and the accuracy keeps improving.

The problem

The circuit is linear, in modified nodal analysis form in the Laplace domain, (G+sC)x=b u(G + sC)x = b\,u, with input uu and output y=lTxy = l^{\mathsf T} x, so its transfer function is H(s)=lT(G+sC)−1bH(s) = l^{\mathsf T}(G + sC)^{-1} b. This is the matrix pair of AC analysis. Choose an expansion point s0s_0 with K=G+s0CK = G + s_0 C nonsingular, and put A=−K−1CA = -K^{-1} C and r=K−1br = K^{-1} b. Then

H(s0+σ)=lT(I−σA)−1r=∑k≥0mkσk,mk=lTAkr.H(s_0 + \sigma) = l^{\mathsf T}(I - \sigma A)^{-1} r = \sum_{k \ge 0} m_k \sigma^k, \qquad m_k = l^{\mathsf T} A^k r.

The mkm_k are the moments at s0s_0. Input: GG, CC, bb, ll, s0s_0 and the order qq. Output: a model HqH_q of order qq with Hq(s0+σ)−H(s0+σ)=O(σ2q)H_q(s_0 + \sigma) - H(s_0 + \sigma) = O(\sigma^{2q}). This is the [q−1/q][q-1/q] Padé approximant of HH at s0s_0.

The algorithm

  1. PVL(G, C, b, l, s₀, q)
  2. 1factor K = G + s₀C by sparse LU; r ← K⁻¹ b
  3. 2v₁ ← r/ρ₁; w₁ ← l/η₁; d₁ ← w₁ᵀv₁; if d₁ = 0 then report breakdown
  4. 3for k = 1, ..., q
  5. 4u ← A v_k = −K⁻¹(C v_k); t ← Aᵀ w_k = −Cᵀ(K⁻ᵀ w_k)
  6. 5α_k ← w_kᵀ u / d_k; β_k ← η_k d_k / d_{k−1}; γ_k ← ρ_k d_k / d_{k−1} (β₁ = γ₁ = 0)
  7. 6ρ_{k+1} v_{k+1} ← u − α_k v_k − β_k v_{k−1}; η_{k+1} w_{k+1} ← t − α_k w_k − γ_k w_{k−1}
  8. 7d_{k+1} ← w_{k+1}ᵀ v_{k+1}; if d_{k+1} = 0 and k < q then report breakdown
  9. 8T_q ← the tridiagonal matrix with diagonal α₁..α_q, subdiagonal ρ₂..ρ_q, superdiagonal β₂..β_q
  10. 9return H_q(s) = (lᵀr) e₁ᵀ (I − (s − s₀) T_q)⁻¹ e₁

The right vectors vkv_k span the Krylov subspace of AA and rr, and the left vectors wkw_k that of ATA^{\mathsf T} and ll. The coefficients make the two sequences biorthogonal, wiTvj=0w_i^{\mathsf T} v_j = 0 for i≠ji \ne j, with three-term recurrences, as in the biconjugate gradient method. The scale factors ρk+1\rho_{k+1} and ηk+1\eta_{k+1} are free; the code divides by the largest entry, which keeps rational arithmetic exact. Line L4 solves with KK and with KTK^{\mathsf T}, both with the factors of line L1, so the whole run costs one factorization.

The model is cheap to use. HqH_q at any ss costs one tridiagonal solve of order qq. Its poles are s0+1/λs_0 + 1/\lambda for the nonzero eigenvalues λ\lambda of TqT_q, and its residues come from the eigenvectors, which give a time-domain response as a sum of qq exponentials. In a circuit simulator the model is written back as a small set of equations and connected to the rest of the circuit.

Example

Two nodes by hand. Node 1 has 1 S to ground and 1 S to node 2, each node has 1 F to ground, a current of 1 A enters node 1, and the output is the voltage of node 2. So G=(2−1−11)G = \begin{pmatrix} 2 & -1 \\ -1 & 1 \end{pmatrix}, C=IC = I, b=e1b = e_1, l=e2l = e_2, and H(s)=1/(s2+3s+1)H(s) = 1/(s^2 + 3s + 1). At s0=0s_0 = 0, A=−G−1A = -G^{-1} with G−1=(1112)G^{-1} = \begin{pmatrix} 1 & 1 \\ 1 & 2 \end{pmatrix}, and the moments are 1,−3,8,−21,551, -3, 8, -21, 55.

Step 1: r=(1,1)r = (1, 1), v1=(1,1)v_1 = (1, 1), w1=(0,1)w_1 = (0, 1), d1=1d_1 = 1. Then Av1=(−2,−3)A v_1 = (-2, -3) and ATw1=(−1,−2)A^{\mathsf T} w_1 = (-1, -2), so α1=−3\alpha_1 = -3. With q=1q = 1 the model is H1=1/(1+3s)H_1 = 1/(1 + 3s), with moments 1,−3,91, -3, 9: two match, the third does not. Its pole −1/3-1/3 is the reciprocal of the Elmore delay 3, against the dominant pole (−3+5)/2=−0.382(-3 + \sqrt 5)/2 = -0.382 of the circuit.

Step 2: v2=(−2,−3)+3(1,1)=(1,0)v_2 = (-2, -3) + 3(1, 1) = (1, 0) and w2=(−1,−2)+3(0,1)=(−1,1)w_2 = (-1, -2) + 3(0, 1) = (-1, 1), both with scale 1, and d2=−1d_2 = -1: the left and right vectors are not equal and d2d_2 is negative, which a symmetric process would never give. β2=η2d2/d1=−1\beta_2 = \eta_2 d_2/d_1 = -1, and Av2=(−1,−1)A v_2 = (-1, -1) gives α2=0\alpha_2 = 0. So T2=(−3−110)T_2 = \begin{pmatrix} -3 & -1 \\ 1 & 0 \end{pmatrix} and e1T(I−sT2)−1e1=1/(1+3s+s2)e_1^{\mathsf T}(I - sT_2)^{-1} e_1 = 1/(1 + 3s + s^2): with q=2=Nq = 2 = N the model is exact.

An RC line. 60 sections of 10 Ω and 10 fF, driven by a current source with 50 Ω and loaded by 1 MΩ, output at the far end, expanded at s0=0s_0 = 0. The table gives the largest error over 121 log-spaced frequencies from 1 MHz to 10 GHz, divided by the largest ∣H∣|H|, for PVL and for AWE in floating point (Padé from explicit moments by a Hankel solve):

q 1 2 4 6 8 12 16
PVL 0.17 0.025 1.3×10−51.3 \times 10^{-5} 8.7×10−118.7 \times 10^{-11} 6.4×10−146.4 \times 10^{-14} 6.4×10−146.4 \times 10^{-14} 6.4×10−146.4 \times 10^{-14}
AWE 0.17 0.025 1.3×10−51.3 \times 10^{-5} 5.0×10−85.0 \times 10^{-8} 4.9×10−84.9 \times 10^{-8} 5.1×10−85.1 \times 10^{-8} 5.0×10−85.0 \times 10^{-8}

The two agree while the moments carry information. From q=6q = 6 AWE stalls near 5×10−85 \times 10^{-8}, while PVL reaches rounding level.

An RLC line. 20 sections of 2 Ω, 1 nH and 1 pF (41 unknowns), with 25 Ω at the source and 50 Ω at the load, from 100 MHz to 3 GHz at 121 linear points, expanded at s0=2π×109 s−1s_0 = 2\pi \times 10^9\ \mathrm{s^{-1}}. The band holds several resonances, so a low order cannot follow it:

q 12 16 20 24 30
PVL 0.31 5.7×10−45.7 \times 10^{-4} 1.3×10−71.3 \times 10^{-7} 1.9×10−101.9 \times 10^{-10} 1.3×10−111.3 \times 10^{-11}
AWE 0.31 0.014 0.018 0.094 3.3×1043.3 \times 10^{4}

At q=36q = 36 the AWE Hankel solve meets a zero pivot: the explicit moments shrink by a factor near 10−1010^{-10} per step and are 0 in floating point from m34m_{34} on.

Correctness

The proof in proofs/correctness.md shows:

  1. q = 1 in full. T1=(α1)T_1 = (\alpha_1) with α1=m1/m0\alpha_1 = m_1/m_0, so H1=m0/(1−σα1)H_1 = m_0/(1 - \sigma \alpha_1) matches m0m_0 and m1m_1.
  2. Any q, without breakdown. The vectors are biorthogonal; Ajv1=VqTqje1A^j v_1 = V_q T_q^j e_1 for j<qj < q; and WqTAVq=DqTqW_q^{\mathsf T} A V_q = D_q T_q is the transpose of the left recurrence's matrix times DqD_q. Together these give mk=(lTr) e1TTqke1m_k = (l^{\mathsf T} r)\, e_1^{\mathsf T} T_q^k e_1 for k≤2q−1k \le 2q - 1. This is Feldmann and Freund's theorem, which they also prove with look-ahead.
  3. HqH_q has a numerator of degree at most q−1q - 1 and a denominator of degree qq, so it is the Padé approximant, the model of AWE; with q=Nq = N it equals HH.

Breakdown, rounding and passivity are not covered by the proof. The tests check, in exact rational arithmetic:

  • The hand example, step by step.
  • 40 random unsymmetric systems of order 3 to 6 (seed 91), every order q≤Nq \le N, real expansion points from −1-1 to 2: the first 2q2q moments of the model equal the exact moments in every case, and moment 2q2q differs in all 141 cases with q<Nq < N.
  • With seed 92, the model equals the AWE rational function at three rational points for each order.
  • With seed 93, q=Nq = N reproduces HH at three points.
  • The transposed solve with the LU factors of KK equals a direct solve with KTK^{\mathsf T} (seed 94).

In floating point they check the two lines above: PVL below 10−1210^{-12} at q=8q = 8 on the RC line and below 10−1010^{-10} at q=30q = 30 on the RLC line, while AWE stays above 10−910^{-9} and above 10−310^{-3}.

Proof: PVL with q Lanczos steps matches 2q moments of the transfer functionfull

We use the notation of the page. The circuit is (G+sC)x=b u(G + sC)x = b\,u with output y=lTxy = l^{\mathsf T} x. For the expansion point s0s_0 with K=G+s0CK = G + s_0 C nonsingular, put A=−K−1CA = -K^{-1} C and r=K−1br = K^{-1} b. Then for s=s0+σs = s_0 + \sigma,

H(s)=lT(K+σC)−1b=lT(I−σA)−1r=∑k≥0mkσk,mk=lTAkr,H(s) = l^{\mathsf T} (K + \sigma C)^{-1} b = l^{\mathsf T} (I - \sigma A)^{-1} r = \sum_{k \ge 0} m_k \sigma^k, \qquad m_k = l^{\mathsf T} A^k r,

for ∣σ∣|\sigma| below 1/ρ(A)1/\rho(A), where ρ(A)\rho(A) is the spectral radius. The mkm_k are the moments at s0s_0.

The process. Take nonzero scalars ρ1,η1\rho_1, \eta_1 and set v1=r/ρ1v_1 = r/\rho_1, w1=l/η1w_1 = l/\eta_1, d1=w1Tv1d_1 = w_1^{\mathsf T} v_1. For k=1,2,…k = 1, 2, \ldots, while dk≠0d_k \ne 0:

αk=wkTAvkdk,βk=ηkdkdk−1,γk=ρkdkdk−1(β1=γ1=0),\alpha_k = \frac{w_k^{\mathsf T} A v_k}{d_k}, \qquad \beta_k = \frac{\eta_k d_k}{d_{k-1}}, \qquad \gamma_k = \frac{\rho_k d_k}{d_{k-1}} \quad (\beta_1 = \gamma_1 = 0),
ρk+1vk+1=Avk−αkvk−βkvk−1,ηk+1wk+1=ATwk−αkwk−γkwk−1,dk+1=wk+1Tvk+1,\rho_{k+1} v_{k+1} = A v_k - \alpha_k v_k - \beta_k v_{k-1}, \qquad \eta_{k+1} w_{k+1} = A^{\mathsf T} w_k - \alpha_k w_k - \gamma_k w_{k-1}, \qquad d_{k+1} = w_{k+1}^{\mathsf T} v_{k+1},

with any nonzero scale factors ρk+1,ηk+1\rho_{k+1}, \eta_{k+1} (the code uses the largest entry). PVL returns Hq(s0+σ)=(lTr) e1T(I−σTq)−1e1H_q(s_0 + \sigma) = (l^{\mathsf T} r)\, e_1^{\mathsf T} (I - \sigma T_q)^{-1} e_1, where TqT_q is the q×qq \times q tridiagonal matrix with diagonal α1,…,αq\alpha_1, \ldots, \alpha_q, subdiagonal ρ2,…,ρq\rho_2, \ldots, \rho_q and superdiagonal β2,…,βq\beta_2, \ldots, \beta_q. We assume d1,…,dq≠0d_1, \ldots, d_q \ne 0, which is the condition that no breakdown occurs.

The case q = 1

Theorem 1. If lTr≠0l^{\mathsf T} r \ne 0, then H1H_1 matches m0m_0 and m1m_1.

Proof. T1=(α1)T_1 = (\alpha_1) with α1=w1TAv1/d1=lTAr/lTr\alpha_1 = w_1^{\mathsf T} A v_1 / d_1 = l^{\mathsf T} A r / l^{\mathsf T} r, since the scale factors cancel. So

H1(s0+σ)=lTr1−σα1=lTr+(lTr)α1σ+(lTr)α12σ2+⋯ ,H_1(s_0 + \sigma) = \frac{l^{\mathsf T} r}{1 - \sigma \alpha_1} = l^{\mathsf T} r + (l^{\mathsf T} r)\alpha_1 \sigma + (l^{\mathsf T} r)\alpha_1^2 \sigma^2 + \cdots,

whose first two coefficients are lTr=m0l^{\mathsf T} r = m_0 and (lTr)α1=lTAr=m1(l^{\mathsf T} r)\alpha_1 = l^{\mathsf T} A r = m_1. □\square

The third coefficient is m12/m0m_1^2/m_0, which is not m2m_2 in general: in the example of the page, m0,m1,m2=1,−3,8m_0, m_1, m_2 = 1, -3, 8 and m12/m0=9m_1^2/m_0 = 9. At s0=0s_0 = 0 the one pole of the model is σ=1/α1=m0/m1\sigma = 1/\alpha_1 = m_0/m_1. For an RC circuit with m0=1m_0 = 1, TD=−m1T_D = -m_1 is the Elmore delay, so the pole is −1/TD-1/T_D.

The general case

The full result is Feldmann and Freund's (1995). We give a complete proof for the version above, which has no look-ahead.

Lemma 1 (biorthogonality). If d1,…,dq≠0d_1, \ldots, d_q \ne 0, then wiTvj=0w_i^{\mathsf T} v_j = 0 for all i≠ji \ne j with i,j≤q+1i, j \le q + 1.

Proof. Induction on kk: suppose the claim holds for all indices up to k≤qk \le q; we show wiTvk+1=0w_i^{\mathsf T} v_{k+1} = 0 for i≤ki \le k (the claim for wk+1w_{k+1} against viv_i is the same argument with ATA^{\mathsf T} and γ\gamma). Up to the factor ρk+1\rho_{k+1},

wiTρk+1vk+1=wiTAvk−αkwiTvk−βkwiTvk−1.w_i^{\mathsf T} \rho_{k+1} v_{k+1} = w_i^{\mathsf T} A v_k - \alpha_k w_i^{\mathsf T} v_k - \beta_k w_i^{\mathsf T} v_{k-1}.

For i=ki = k it is wkTAvk−αkdk=0w_k^{\mathsf T} A v_k - \alpha_k d_k = 0 by the choice of αk\alpha_k. For i<ki < k write wiTAvk=(ATwi)Tvk=(ηi+1wi+1+αiwi+γiwi−1)Tvkw_i^{\mathsf T} A v_k = (A^{\mathsf T} w_i)^{\mathsf T} v_k = (\eta_{i+1} w_{i+1} + \alpha_i w_i + \gamma_i w_{i-1})^{\mathsf T} v_k. If i=k−1i = k - 1, the hypothesis leaves ηkdk\eta_k d_k, and the sum is ηkdk−βkdk−1=0\eta_k d_k - \beta_k d_{k-1} = 0 by the choice of βk\beta_k. If i≤k−2i \le k - 2, every index on the right is below kk, so every term is 0. □\square

Matrix form. With Vq=(v1,…,vq)V_q = (v_1, \ldots, v_q), Wq=(w1,…,wq)W_q = (w_1, \ldots, w_q) and Dq=diag⁡(d1,…,dq)D_q = \operatorname{diag}(d_1, \ldots, d_q), the recurrences read

AVq=VqTq+ρq+1vq+1eqT,ATWq=WqT~q+ηq+1wq+1eqT,A V_q = V_q T_q + \rho_{q+1} v_{q+1} e_q^{\mathsf T}, \qquad A^{\mathsf T} W_q = W_q \tilde T_q + \eta_{q+1} w_{q+1} e_q^{\mathsf T},

where T~q\tilde T_q has the same diagonal, subdiagonal η2,…,ηq\eta_2, \ldots, \eta_q and superdiagonal γ2,…,γq\gamma_2, \ldots, \gamma_q. By Lemma 1, WqTVq=DqW_q^{\mathsf T} V_q = D_q, WqTvq+1=0W_q^{\mathsf T} v_{q+1} = 0 and VqTwq+1=0V_q^{\mathsf T} w_{q+1} = 0. Multiply the first identity by WqTW_q^{\mathsf T} and the transpose of the second by VqV_q:

WqTAVq=DqTq=T~qTDq.(1)W_q^{\mathsf T} A V_q = D_q T_q = \tilde T_q^{\mathsf T} D_q. \tag{1}

Lemma 2. For 0≤j≤q−10 \le j \le q - 1, Ajv1=VqTqje1A^j v_1 = V_q T_q^j e_1, and Aqv1=VqTqqe1+c vq+1A^q v_1 = V_q T_q^q e_1 + c\, v_{q+1} for a scalar cc. In the same way (AT)iw1=WqT~qie1(A^{\mathsf T})^i w_1 = W_q \tilde T_q^i e_1 for 0≤i≤q−10 \le i \le q - 1.

Proof. TqT_q is tridiagonal, so Tqje1T_q^j e_1 is zero below entry j+1j + 1. Suppose Ajv1=VqTqje1A^j v_1 = V_q T_q^j e_1 for some j≤q−1j \le q - 1. Then Aj+1v1=AVqTqje1=VqTqj+1e1+ρq+1vq+1(eqTTqje1)A^{j+1} v_1 = A V_q T_q^j e_1 = V_q T_q^{j+1} e_1 + \rho_{q+1} v_{q+1} (e_q^{\mathsf T} T_q^j e_1). The last factor is 0 when j+1≤q−1j + 1 \le q - 1, and it is some scalar when j+1=qj + 1 = q. The case j=0j = 0 is v1=Vqe1v_1 = V_q e_1. □\square

Theorem 2 (moment matching). If d1,…,dq≠0d_1, \ldots, d_q \ne 0, then mk=(lTr) e1TTqke1m_k = (l^{\mathsf T} r)\, e_1^{\mathsf T} T_q^k e_1 for 0≤k≤2q−10 \le k \le 2q - 1. Hence H(s0+σ)−Hq(s0+σ)=O(σ2q)H(s_0 + \sigma) - H_q(s_0 + \sigma) = O(\sigma^{2q}).

Proof. Write k=i+jk = i + j with 0≤i≤q−10 \le i \le q - 1 and 0≤j≤q0 \le j \le q. By Lemma 2,

mk=ρ1η1 ((AT)iw1)T(Ajv1)=ρ1η1 e1T(T~qT)i WqT(VqTqje1+c vq+1)=ρ1η1 e1T(T~qT)iDqTqje1,m_k = \rho_1 \eta_1\, \big((A^{\mathsf T})^i w_1\big)^{\mathsf T} \big(A^j v_1\big) = \rho_1 \eta_1\, e_1^{\mathsf T} (\tilde T_q^{\mathsf T})^i\, W_q^{\mathsf T} \big(V_q T_q^j e_1 + c\, v_{q+1}\big) = \rho_1 \eta_1\, e_1^{\mathsf T} (\tilde T_q^{\mathsf T})^i D_q T_q^j e_1,

with c=0c = 0 unless j=qj = q, and WqTvq+1=0W_q^{\mathsf T} v_{q+1} = 0. By (1), T~qTDq=DqTq\tilde T_q^{\mathsf T} D_q = D_q T_q, so (T~qT)iDq=DqTqi(\tilde T_q^{\mathsf T})^i D_q = D_q T_q^i, and mk=ρ1η1d1 e1TTqi+je1m_k = \rho_1 \eta_1 d_1\, e_1^{\mathsf T} T_q^{i+j} e_1. Finally ρ1η1d1=lTr\rho_1 \eta_1 d_1 = l^{\mathsf T} r. The expansion e1T(I−σTq)−1e1=∑kσke1TTqke1e_1^{\mathsf T} (I - \sigma T_q)^{-1} e_1 = \sum_k \sigma^k e_1^{\mathsf T} T_q^k e_1 gives the second claim. □\square

Corollary 1 (it is the Padé approximant). By Cramer's rule, e1T(I−σTq)−1e1=det⁡(I−σTq′)/det⁡(I−σTq)e_1^{\mathsf T}(I - \sigma T_q)^{-1} e_1 = \det(I - \sigma T_q')/\det(I - \sigma T_q), where Tq′T_q' is TqT_q without its first row and column. So HqH_q is a rational function with a numerator of degree at most q−1q - 1 and a denominator of degree at most qq with value 1 at σ=0\sigma = 0, and it matches 2q2q moments. When the [q−1/q][q-1/q] Padé approximant of HH at s0s_0 exists, it is the unique such function, so HqH_q is that approximant: the same model that AWE computes from the explicit moments. The two methods differ only in rounding. The poles of HqH_q are s0+1/λs_0 + 1/\lambda for the nonzero eigenvalues λ\lambda of TqT_q.

Corollary 2 (q = N is exact). If d1,…,dN≠0d_1, \ldots, d_N \ne 0 for the order NN of AA, then HN=HH_N = H.

Proof. WNTVN=DNW_N^{\mathsf T} V_N = D_N is nonsingular, so VNV_N and WNW_N are. Then WNTρN+1vN+1=0W_N^{\mathsf T} \rho_{N+1} v_{N+1} = 0 forces the vector ρN+1vN+1\rho_{N+1} v_{N+1} to vanish, so AVN=VNTNA V_N = V_N T_N, and A=VNTNVN−1A = V_N T_N V_N^{-1}. With VN−1r=ρ1e1V_N^{-1} r = \rho_1 e_1 and lTVN=η1w1TVN=η1d1e1Tl^{\mathsf T} V_N = \eta_1 w_1^{\mathsf T} V_N = \eta_1 d_1 e_1^{\mathsf T}, lT(I−σA)−1r=ρ1η1d1 e1T(I−σTN)−1e1l^{\mathsf T}(I - \sigma A)^{-1} r = \rho_1 \eta_1 d_1\, e_1^{\mathsf T}(I - \sigma T_N)^{-1} e_1. □\square

What is not proved

  • Breakdown. If some dk=0d_k = 0 while vk,wk≠0v_k, w_k \ne 0, the process stops; the [q−1/q][q-1/q] approximant may then not exist, or may need a look-ahead variant of the Lanczos process, which Feldmann and Freund use. The code reports the breakdown.
  • Rounding. In floating point the vectors lose their biorthogonality, as in every Lanczos process. The tests measure the accuracy on two lines; they do not prove a bound.
  • Stability and passivity. A Padé model of a stable or passive circuit can have poles in the right half plane, or fail to be passive. The theorem says nothing about that; PRIMA, a congruence method, was designed to keep passivity.

Complexity

Line L1 is one sparse factorization, cost FF. Each step costs one solve with KK, one with KTK^{\mathsf T}, two products with CC and O(N)O(N) for the dot products and vector updates, so qq steps cost O(F+qs+qN)O(F + q s + q N). Only the last two vectors of each sequence are kept, O(N)O(N), and TqT_q takes O(q)O(q). Evaluating the model at MM frequencies costs O(Mq)O(Mq) with a tridiagonal solver. AWE has the same cost for the moments; the difference is accuracy, not time. The implementation uses dense LU, so its FF is O(N3)O(N^3) and its ss is O(N2)O(N^2).

Properties

  • Padé accuracy. 2q2q moments from qq steps, the most that a model of order qq with q−1q - 1 zeros can match.
  • Numerically stable in practice. The vectors are rescaled at every step, and the recurrence orthogonalizes against the previous directions, so the information that AWE loses to rounding is kept. The tables are measurements, not a bound.
  • Not passive in general. The model of a passive RLC circuit can have poles in the right half plane or produce energy at its ports. Passivity is not part of the Padé conditions.
  • One input and one output. PVL is for a single transfer function; matrix-Padé variants with block Lanczos handle several ports.
  • The expansion point sets the band. Accuracy is best near s0s_0 and fades with distance from it.

Variants and improvements

  • Look-ahead Lanczos. When dkd_k is 0 or tiny, look-ahead steps over the gap with small blocks. Feldmann and Freund use this version.
  • Several ports. A block version of the Lanczos process handles circuits with several inputs and outputs and matches block moments.
  • PRIMA. The Arnoldi process and a congruence projection give passive models of RLC circuits at the price of matching qq block moments instead of 2q2q: PRIMA.
  • Several expansion points. Rational Krylov methods combine expansions at several s0s_0 to cover a wide band.

When to use it

Use PVL to reduce a large linear network with one input and one output, such as an interconnect line or a filter, for a fast frequency or time response, or for many noise or AC evaluations. Use it instead of AWE whenever more than a few poles are needed. When the model is connected back to a nonlinear circuit for transient simulation, prefer a passive method such as PRIMA, or check the poles and the passivity of the PVL model.

Pitfalls

  • Breakdown. dk=0d_k = 0 with nonzero vectors stops the plain process. The code reports it; a robust code needs look-ahead.
  • Unstable poles. A model of a stable circuit can have a pole with positive real part, which turns into a growing exponential in a time-domain simulation. Discard or reflect such poles, or use a passive method.
  • Loss of biorthogonality. In floating point the vectors drift away from biorthogonality, as in every Lanczos process. The accuracy can stall: on the RLC line with the expansion point at 2π×3×109 s−12\pi \times 3 \times 10^9\ \mathrm{s^{-1}}, the error stopped at 2.1×10−52.1 \times 10^{-5} from q=24q = 24 to q=41q = 41.
  • The expansion point. s0=0s_0 = 0 suits RC circuits and step responses; resonant RLC lines need a point inside the band, or several points.
  • Comparing with AWE at low order. At low order the two give the same model; the difference appears only where the explicit moments lose accuracy.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

pade_via_lanczos.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/pade-via-lanczos/. The authors are listed in prov/JW00K7.jsonl.
"""Pade via Lanczos (PVL) for a linear circuit G x + s C x = b u, y = l^T x.

With the expansion point s0, K = G + s0 C, A = -K^{-1} C and r = K^{-1} b,
the transfer function is H(s0 + sigma) = l^T (I - sigma A)^{-1} r, whose
Taylor coefficients are the moments m_k = l^T A^k r. The nonsymmetric Lanczos
process on A with the start vectors r and l gives a q x q tridiagonal T_q, and
H_q(s0 + sigma) = (l^T r) e1^T (I - sigma T_q)^{-1} e1 matches m_0..m_{2q-1}.

The code works with float or Fraction entries; with Fraction it is exact.
Vectors are scaled by their largest entry, which keeps Fractions exact.
"""

import sim3dense


class Breakdown(ArithmeticError):
    """w_k^T v_k = 0 with nonzero v_k, w_k: the process needs look-ahead."""


def lu_factor(a):
    """Partial-pivoting LU of a square matrix: returns (lu, perm)."""
    n = len(a)
    lu = [list(row) for row in a]
    perm = list(range(n))
    for k in range(n):
        p = max(range(k, n), key=lambda i: abs(lu[i][k]))
        if lu[p][k] == 0:
            raise sim3dense.SingularMatrixError(f"zero pivot in column {k}")
        lu[k], lu[p] = lu[p], lu[k]
        perm[k], perm[p] = perm[p], perm[k]
        for i in range(k + 1, n):
            f = lu[i][k] / lu[k][k]
            lu[i][k] = f
            if f != 0:
                for j in range(k + 1, n):
                    lu[i][j] -= f * lu[k][j]
    return lu, perm


def lu_solve(fac, b):
    """Solve K x = b with the factors of K."""
    lu, perm = fac
    n = len(lu)
    y = [b[p] for p in perm]
    for i in range(n):
        y[i] = y[i] - sum(lu[i][k] * y[k] for k in range(i))
    for i in range(n - 1, -1, -1):
        y[i] = (y[i] - sum(lu[i][k] * y[k] for k in range(i + 1, n))) / lu[i][i]
    return y


def lu_solve_transposed(fac, b):
    """Solve K^T x = b with the same factors (P K = L U, so K^T = U^T L^T P)."""
    lu, perm = fac
    n = len(lu)
    z = list(b)
    for i in range(n):
        z[i] = (z[i] - sum(lu[k][i] * z[k] for k in range(i))) / lu[i][i]
    for i in range(n - 1, -1, -1):
        z[i] = z[i] - sum(lu[k][i] * z[k] for k in range(i + 1, n))
    x = [0 * z[0]] * n
    for i, p in enumerate(perm):
        x[p] = z[i]
    return x


def _dot(x, y):
    return sum(a * b for a, b in zip(x, y))


def _scale(x):
    return max(abs(v) for v in x)


def pvl(G, C, b, l, s0, q, tol=0.0):
    """Run q steps of PVL. Returns (m0, T) with T the q x q tridiagonal matrix."""
    n = len(G)
    K = [[G[i][j] + s0 * C[i][j] for j in range(n)] for i in range(n)]
    fac = lu_factor(K)  # @line L1
    r = lu_solve(fac, b)
    rho, eta = _scale(r), _scale(l)
    if rho == 0 or eta == 0:
        raise ValueError("b and l must be nonzero")
    v, w = [x / rho for x in r], [x / eta for x in l]
    d = _dot(w, v)  # @line L2
    if abs(d) <= tol * _scale(v) * _scale(w) * n or d == 0:
        raise Breakdown("l^T r = 0")
    m0 = rho * eta * d
    alpha, beta, sub = [], [], []
    v_prev, w_prev, d_prev = [0 * x for x in v], [0 * x for x in w], None
    rho_k, eta_k = None, None
    for k in range(q):  # @line L3
        cv = sim3dense.matvec(C, v)
        av = [-x for x in lu_solve(fac, cv)]  # @line L4
        y = lu_solve_transposed(fac, w)
        aw = [-x for x in sim3dense.matvec(sim3dense.transpose(C), y)]
        a = _dot(w, av) / d  # @line L5
        bt = eta_k * d / d_prev if k else 0 * a
        gm = rho_k * d / d_prev if k else 0 * a
        alpha.append(a)
        if k:
            beta.append(bt)
        if k == q - 1:
            break
        vt = [x - a * y1 - bt * y0 for x, y1, y0 in zip(av, v, v_prev)]  # @line L6
        wt = [x - a * y1 - gm * y0 for x, y1, y0 in zip(aw, w, w_prev)]
        rho_k, eta_k = _scale(vt), _scale(wt)
        if rho_k == 0 or eta_k == 0:  # an invariant subspace: H_k is exact
            break
        v_prev, w_prev, d_prev = v, w, d
        v, w = [x / rho_k for x in vt], [x / eta_k for x in wt]
        d = _dot(w, v)  # @line L7
        if d == 0 or abs(d) <= tol * n:
            raise Breakdown(f"w^T v = 0 at step {k + 2}")
        sub.append(rho_k)
    size = len(alpha)
    T = [[0 * m0] * size for _ in range(size)]  # @line L8
    for i in range(size):
        T[i][i] = alpha[i]
        if i + 1 < size:
            T[i + 1][i] = sub[i]
            T[i][i + 1] = beta[i]
    return m0, T  # @line L9


def model_eval(m0, T, s0, s):
    """H_q(s) = m0 e1^T (I - (s - s0) T)^{-1} e1."""
    sig = s - s0
    n = len(T)
    M = [[(1 if i == j else 0) - sig * T[i][j] for j in range(n)] for i in range(n)]
    e1 = [1] + [0] * (n - 1)
    return m0 * sim3dense.solve(M, e1)[0]


def model_moments(m0, T, count):
    """m0 e1^T T^k e1 for k < count."""
    n = len(T)
    x = [1] + [0 * m0] * (n - 1)
    out = []
    for _ in range(count):
        out.append(m0 * x[0])
        x = [sum(T[i][j] * x[j] for j in range(n)) for i in range(n)]
    return out


def exact_moments(G, C, b, l, s0, count):
    """m_k = l^T A^k r, computed by repeated solves (as in AWE)."""
    n = len(G)
    fac = lu_factor([[G[i][j] + s0 * C[i][j] for j in range(n)] for i in range(n)])
    x = lu_solve(fac, b)
    out = []
    for _ in range(count):
        out.append(_dot(l, x))
        x = [-v for v in lu_solve(fac, sim3dense.matvec(C, x))]
    return out


def awe(moments, q):
    """Pade [q-1/q] from 2q moments by the Hankel system (AWE).

    Returns (num, den): num has q coefficients, den has q + 1 with den[0] = 1.
    """
    m = moments
    H = [[m[q + i - j - 1] for j in range(q)] for i in range(q)]
    rhs = [-m[q + i] for i in range(q)]
    tail = sim3dense.solve(H, rhs)
    den = [1] + tail
    num = [sum(den[j] * m[i - j] for j in range(i + 1)) for i in range(q)]
    return num, den


def rational_eval(num, den, sig):
    def poly(c):
        acc = 0
        for x in reversed(c):
            acc = acc * sig + x
        return acc

    return poly(num) / poly(den)


def transfer(G, C, b, l, s):
    n = len(G)
    Y = [[G[i][j] + s * C[i][j] for j in range(n)] for i in range(n)]
    return _dot(l, sim3dense.solve(Y, [complex(x) for x in b]))


def rlc_line(sections, r, ind, cap, rs, rl):
    """MNA matrices of a lumped RLC line: a 1 A source with resistance rs drives
    node 1; each section has a series r and ind and a cap to ground; rl
    terminates the far end. Unknowns: the node voltages, then the inductor
    currents. The output is the far-end voltage."""
    n = sections + 1  # nodes 0..sections, plus the inductor-current unknowns
    N = n + sections
    G = [[0.0] * N for _ in range(N)]
    C = [[0.0] * N for _ in range(N)]
    G[0][0] += 1 / rs
    G[n - 1][n - 1] += 1 / rl
    for k in range(sections):
        a, c, j = k, k + 1, n + k  # node a - r - L - node c, current j
        # the series r and L as one branch: e_a - e_c - r j - ind dj/dt = 0
        G[a][j] += 1
        G[c][j] -= 1
        G[j][a] += 1
        G[j][c] -= 1
        G[j][j] -= r
        C[j][j] -= ind
        C[c][c] += cap
    b = [0.0] * N
    b[0] = 1.0
    l = [0.0] * N
    l[n - 1] = 1.0
    return G, C, b, l
sim3dense.py 70 lines
# SPDX-License-Identifier: MIT
# Shared helper of the sim3 eda pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Small dense linear algebra for Fraction, float or complex entries.

The circuit pages of group sim3 use this module as a reference solver and for
the small dense systems inside their tests. It holds no sparse method and no
circuit method. Matrices are lists of rows.
"""

from fractions import Fraction


class SingularMatrixError(ValueError):
    """The matrix has no inverse (a zero pivot in exact arithmetic)."""


def _exact(x):
    return Fraction(x) if isinstance(x, int) else x


def solve(a, b, tol=0.0):
    """Solve a x = b by Gaussian elimination with partial pivoting.

    With Fraction entries the result is exact. b is a vector or a matrix
    (a list of rows); the result has the same shape.
    """
    n = len(a)
    m = [[_exact(x) for x in row] for row in a]
    vec = not (b and isinstance(b[0], list))
    rhs = [[_exact(x)] for x in b] if vec else [[_exact(x) for x in row] for row in b]
    for k in range(n):
        p = max(range(k, n), key=lambda i: abs(m[i][k]))
        if abs(m[p][k]) <= tol:
            raise SingularMatrixError(f"zero pivot in column {k}")
        m[k], m[p] = m[p], m[k]
        rhs[k], rhs[p] = rhs[p], rhs[k]
        for i in range(k + 1, n):
            if m[i][k] != 0:
                f = m[i][k] / m[k][k]
                for j in range(k, n):
                    m[i][j] -= f * m[k][j]
                for j in range(len(rhs[i])):
                    rhs[i][j] -= f * rhs[k][j]
    x = [[0] * len(rhs[0]) for _ in range(n)]
    for i in range(n - 1, -1, -1):
        for j in range(len(rhs[0])):
            s = rhs[i][j] - sum(m[i][k] * x[k][j] for k in range(i + 1, n))
            x[i][j] = s / m[i][i]
    return [r[0] for r in x] if vec else x


def transpose(a):
    return [list(r) for r in zip(*a)]


def matvec(a, x):
    return [sum(aij * xj for aij, xj in zip(row, x)) for row in a]


def matmul(a, b):
    bt = transpose(b)
    return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]


def identity(n, one=1):
    return [[one if i == j else 0 * one for j in range(n)] for i in range(n)]


def inverse(a):
    return solve(a, identity(len(a)))
test_pade_via_lanczos.py 179 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/pade-via-lanczos/. The authors are listed in prov/JW00K7.jsonl.

import math
import random
from fractions import Fraction as Fr

import pytest

import sim3dense
from pade_via_lanczos import (
    Breakdown,
    awe,
    exact_moments,
    lu_factor,
    lu_solve,
    lu_solve_transposed,
    model_eval,
    model_moments,
    pvl,
    rational_eval,
    rlc_line,
    transfer,
)


def two_node():
    """1 S from node 1 to ground and from node 1 to node 2, 1 F from each node
    to ground, 1 A into node 1, output node 2: G = [[2, -1], [-1, 1]], C = I."""
    G = [[Fr(2), Fr(-1)], [Fr(-1), Fr(1)]]
    C = [[Fr(1), Fr(0)], [Fr(0), Fr(1)]]
    return G, C, [Fr(1), Fr(0)], [Fr(0), Fr(1)]


def test_hand_example():
    G, C, b, l = two_node()
    assert exact_moments(G, C, b, l, 0, 5) == [1, -3, 8, -21, 55]
    m0, T = pvl(G, C, b, l, Fr(0), 1)
    assert (m0, T) == (1, [[-3]])
    assert model_moments(m0, T, 3) == [1, -3, 9]  # two moments match, the third does not
    m0, T = pvl(G, C, b, l, Fr(0), 2)
    assert T == [[-3, -1], [1, 0]]
    for s in (Fr(0), Fr(1), Fr(-1, 2), Fr(7, 3)):
        assert model_eval(m0, T, 0, s) == 1 / (s * s + 3 * s + 1)  # exact for q = n


def random_circuit(rng, n):
    G = [[Fr(rng.randint(-3, 3)) for _ in range(n)] for _ in range(n)]
    for i in range(n):
        G[i][i] += 3 * n
    C = [[Fr(rng.randint(-2, 2)) for _ in range(n)] for _ in range(n)]
    b = [Fr(rng.randint(-2, 2)) for _ in range(n)]
    l = [Fr(rng.randint(-2, 2)) for _ in range(n)]
    b[0], l[-1] = Fr(1), Fr(1)  # nonzero
    return G, C, b, l


def test_exact_arithmetic_matches_2q_moments():
    rng = random.Random(91)
    short = more = 0
    for _ in range(40):
        n = rng.randint(3, 6)
        G, C, b, l = random_circuit(rng, n)
        s0 = Fr(rng.randint(-1, 2))
        ref = exact_moments(G, C, b, l, s0, 2 * n + 1)
        for q in range(1, n + 1):
            m0, T = pvl(G, C, b, l, s0, q)  # no breakdown occurs with this seed
            got = model_moments(m0, T, 2 * q + 1)
            assert got[: 2 * q] == ref[: 2 * q]
            if q == n:
                assert got[2 * q] == ref[2 * q]  # the full model matches every moment
            else:
                short += 1
                more += got[2 * q] != ref[2 * q]
    assert short == 141 and more == short  # moment 2q is missed in every case


def test_same_model_as_awe_in_exact_arithmetic():
    rng = random.Random(92)
    for _ in range(20):
        n = rng.randint(3, 6)
        G, C, b, l = random_circuit(rng, n)
        for q in range(1, n):
            try:
                m0, T = pvl(G, C, b, l, Fr(0), q)
                num, den = awe(exact_moments(G, C, b, l, 0, 2 * q), q)
            except (Breakdown, sim3dense.SingularMatrixError):
                break
            for sig in (Fr(1, 7), Fr(-2, 5), Fr(3)):
                try:
                    want = rational_eval(num, den, sig)
                except ZeroDivisionError:
                    continue
                assert model_eval(m0, T, 0, sig) == want


def test_q_equal_n_reproduces_the_transfer_function():
    rng = random.Random(93)
    for _ in range(10):
        n = rng.randint(2, 5)
        G, C, b, l = random_circuit(rng, n)
        try:
            m0, T = pvl(G, C, b, l, Fr(0), n)
        except Breakdown:
            continue
        for s in (Fr(1, 3), Fr(2), Fr(-1, 5)):
            Y = [[G[i][j] + s * C[i][j] for j in range(n)] for i in range(n)]
            want = sum(a * x for a, x in zip(l, sim3dense.solve(Y, b)))
            assert model_eval(m0, T, 0, s) == want


def test_breakdown_is_reported():
    G = [[Fr(1), Fr(0)], [Fr(0), Fr(1)]]
    C = [[Fr(1), Fr(1)], [Fr(0), Fr(1)]]
    with pytest.raises(Breakdown):
        pvl(G, C, [Fr(1), Fr(0)], [Fr(0), Fr(1)], Fr(0), 2)  # l^T r = 0


def test_transposed_solve_reuses_the_factors():
    rng = random.Random(94)
    for _ in range(20):
        n = rng.randint(1, 8)
        K = [[Fr(rng.randint(-5, 5)) for _ in range(n)] for _ in range(n)]
        for i in range(n):
            K[i][i] += 11
        w = [Fr(rng.randint(-5, 5)) for _ in range(n)]
        fac = lu_factor(K)
        assert lu_solve(fac, w) == sim3dense.solve(K, w)
        assert lu_solve_transposed(fac, w) == sim3dense.solve(sim3dense.transpose(K), w)


def rc_line(n, r, c, rs, rload):
    N = n + 1
    G = [[0.0] * N for _ in range(N)]
    C = [[0.0] * N for _ in range(N)]
    for k in range(n):
        g = 1 / r
        G[k][k] += g
        G[k + 1][k + 1] += g
        G[k][k + 1] -= g
        G[k + 1][k] -= g
        C[k + 1][k + 1] += c
    G[0][0] += 1 / rs
    G[N - 1][N - 1] += 1 / rload
    b = [0.0] * N
    b[0] = 1.0
    l = [0.0] * N
    l[-1] = 1.0
    return G, C, b, l


def errors(G, C, b, l, s0, fs, qs):
    exact = [transfer(G, C, b, l, 2j * math.pi * f) for f in fs]
    peak = max(abs(h) for h in exact)
    mom = exact_moments(G, C, b, l, s0, 2 * max(qs))
    out = {}
    for q in qs:
        m0, T = pvl(G, C, b, l, s0, q)
        e_pvl = max(abs(model_eval(m0, T, s0, 2j * math.pi * f) - h) for f, h in zip(fs, exact)) / peak
        num, den = awe(mom, q)
        e_awe = max(abs(rational_eval(num, den, 2j * math.pi * f - s0) - h) for f, h in zip(fs, exact)) / peak
        out[q] = (e_pvl, e_awe)
    return out


def test_rc_line_pvl_converges_and_awe_stalls():
    fs = [10 ** (6 + 4 * i / 120) for i in range(121)]
    e = errors(*rc_line(60, 10.0, 10e-15, 50.0, 1e6), 0.0, fs, [2, 4, 8, 12])
    assert e[2][0] == pytest.approx(e[2][1], rel=1e-6)  # the same model while the moments are accurate
    assert e[4][0] < 1e-4 and e[8][0] < 1e-12 and e[12][0] < 1e-12
    assert e[8][1] > 1e-9 and e[12][1] > 1e-9  # explicit moments lose the later directions


def test_rlc_line_with_a_real_expansion_point():
    G, C, b, l = rlc_line(20, 2.0, 1e-9, 1e-12, 25.0, 50.0)
    fs = [1e8 + (3e9 - 1e8) * i / 120 for i in range(121)]
    e = errors(G, C, b, l, 2 * math.pi * 1e9, fs, [20, 30])
    assert e[20][0] < 1e-6 and e[30][0] < 1e-10
    assert e[20][1] > 1e-3

History

Lanczos (1950) gave the two-sided process for nonsymmetric matrices, with left and right vectors that are biorthogonal. AWE (Pillage and Rohrer, 1990) made Padé approximation from moments a standard tool for interconnect analysis, but its explicit moments limit the useful order. Feldmann and Freund (1995) showed that the Lanczos process gives the same Padé approximant without the explicit moments, with look-ahead against breakdown, and named the method PVL. PVL gives no passivity guarantee, and PRIMA (1997 and 1998) was presented as a passive alternative.

References

  1. Peter Feldmann and Roland W. Freund, Efficient linear circuit analysis by Padé approximation via the Lanczos process, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 14(5), 639 to 649, 1995, the PVL algorithm, the theorem that q Lanczos steps give the Padé approximant with 2q matched moments, the look-ahead Lanczos process and the comparison with AWE
  2. Cornelius Lanczos, An iteration method for the solution of the eigenvalue problem of linear differential and integral operators, Journal of Research of the National Bureau of Standards 45(4), from page 255, 1950, the two-sided (biorthogonal) form of the process for a nonsymmetric matrix
  3. Yousef Saad, Iterative Methods for Sparse Linear Systems, second edition, SIAM, 2003, Section 7.1, Lanczos biorthogonalization (the recurrences, the biorthogonality and the breakdowns)
  4. Lawrence T. Pillage and Ronald A. Rohrer, Asymptotic waveform evaluation for timing analysis, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 9(4), 352 to 366, 1990, the Padé model from explicit moments that PVL replaces

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example