Algorithm Search⌘K

Algorithmadvanced

Invariant subspace algorithm

Also called ISA, V-star algorithm.

Computes the largest controlled invariant subspace inside a subspace K by the descending recursion V_(k+1) = K meet A^(-1)(V_k + im B), which stops after at most dim K + 1 passes.

Time
O(n^3 (n + m)) worst
Space
O(n (n + m)) extra
Where
m = the number of inputs; n = the number of states
Properties
deterministicexactofflineiterative
Origin
Giuseppe Basile, Giovanni Marro, W. Murray Wonham, A. Stephen Morse, 1970

The invariant subspace algorithm (ISA) computes V∗(K)\mathcal{V}^\ast(\mathcal{K}), the largest controlled invariant subspace of x˙=Ax+Bu\dot x = A x + B u inside a given subspace K\mathcal{K}. It starts from V0=K\mathcal{V}_0 = \mathcal{K} and repeats Vk+1=K∩A−1(Vk+im⁡B)\mathcal{V}_{k+1} = \mathcal{K} \cap A^{-1}(\mathcal{V}_k + \operatorname{im} B), where A−1S={x:Ax∈S}A^{-1}\mathcal{S} = \{x : A x \in \mathcal{S}\} is the preimage, not an inverse matrix. The subspaces shrink, and once two of them have the same dimension the last one is V∗\mathcal{V}^\ast. So the algorithm stops after at most dim⁡K+1\dim \mathcal{K} + 1 passes, and each pass is a few rank computations. With K=ker⁡C\mathcal{K} = \ker C it gives the subspace that decides the disturbance decoupling problem and that carries the zero dynamics of a linear system. The algorithm is due to Wonham and Morse (1970), after the controlled invariant subspaces of Basile and Marro (1969).

In plain words

Some states of a machine are safe: from them, a well chosen input can keep the machine safe for all future time. The safe region of interest here is a flat region through the origin, for example all states where a sensor reads zero. Not every state in that region is good, because from some of them the machine must leave the region at once, whatever input you apply. The algorithm removes those states. After the removal, other states may become bad, because their only way to stay was through a removed state. So it removes again, and again. The region gets smaller at each step, and it cannot get smaller more often than its number of dimensions. When a step removes nothing, every remaining state can stay in the region forever.

The problem

Input: A∈Qn×nA \in \mathbb{Q}^{n \times n}, B∈Qn×mB \in \mathbb{Q}^{n \times m} and a basis of a subspace K⊆Qn\mathcal{K} \subseteq \mathbb{Q}^n. Output: a basis of

V∗(K)=the largest subspace V⊆K with AV⊆V+im⁡B.\mathcal{V}^\ast(\mathcal{K}) = \text{the largest subspace } \mathcal{V} \subseteq \mathcal{K} \text{ with } A \mathcal{V} \subseteq \mathcal{V} + \operatorname{im} B.

The largest one exists because the sum of two controlled invariant subspaces is controlled invariant (see controlled invariant subspace). The implementation also returns the list of dimensions dim⁡V0,dim⁡V1,…\dim \mathcal{V}_0, \dim \mathcal{V}_1, \dots, and a friend KK with (A−BK)V∗⊆V∗(A - BK)\mathcal{V}^\ast \subseteq \mathcal{V}^\ast on request. The usual case is K=ker⁡C\mathcal{K} = \ker C for an output y=Cxy = C x, and then V∗\mathcal{V}^\ast is written without the argument.

The algorithm

  1. ISA(A, B, K)
  2. 1V ← K ▷ V_0 = K
  3. 2repeat
  4. 3W ← K ∩ A⁻¹(V + im B) ▷ V_(k+1); A⁻¹ is the preimage
  5. 4if dim W = dim V then
  6. 5return W ▷ W = V = V*
  7. 6V ← W

Line L1 starts with the whole subspace K\mathcal{K}. Line L3 is the only real work. The sum V+im⁡B\mathcal{V} + \operatorname{im} B is the span of the two bases, reduced to a basis by reduced row echelon form. The preimage of a subspace S\mathcal{S} with basis matrix SS is the xx part of the kernel of [A,−S][A, -S], because Ax=SzA x = S z for some zz exactly when x∈A−1Sx \in A^{-1}\mathcal{S}. The intersection of two subspaces with basis matrices UU and VV is UU times the aa part of the kernel of [U,−V][U, -V]. Line L4 compares only dimensions. This is enough, because Vk+1⊆Vk\mathcal{V}_{k+1} \subseteq \mathcal{V}_k always holds, and a subspace of the same dimension inside another one is equal to it. Line L6 makes the new subspace the current one.

The implementation uses exact rational arithmetic (Python Fraction), so every rank decision is exact. It also builds a friend: on a basis v1,…,vqv_1, \dots, v_q of V∗\mathcal{V}^\ast it solves Avi=∑jwijvj−BuiA v_i = \sum_j w_{ij} v_j - B u_i, and it sets Kvi=−uiK v_i = -u_i and K=0K = 0 on a complement.

Example

A disturbance decoupling example. Take

A=[01000100−1],B=e2,C=[100],K=ker⁡C=span⁡(e2,e3).A = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & -1 \end{bmatrix}, \quad B = e_2, \quad C = \begin{bmatrix} 1 & 0 & 0 \end{bmatrix}, \quad \mathcal{K} = \ker C = \operatorname{span}(e_2, e_3).
pass Vk\mathcal{V}_k Vk+im⁡B\mathcal{V}_k + \operatorname{im} B A−1(Vk+im⁡B)A^{-1}(\mathcal{V}_k + \operatorname{im} B) Vk+1\mathcal{V}_{k+1} dimensions
1 span⁡(e2,e3)\operatorname{span}(e_2, e_3) span⁡(e2,e3)\operatorname{span}(e_2, e_3) {x:x2=0}=span⁡(e1,e3)\{x : x_2 = 0\} = \operatorname{span}(e_1, e_3) span⁡(e3)\operatorname{span}(e_3) 2 to 1
2 span⁡(e3)\operatorname{span}(e_3) span⁡(e2,e3)\operatorname{span}(e_2, e_3) span⁡(e1,e3)\operatorname{span}(e_1, e_3) span⁡(e3)\operatorname{span}(e_3) 1 to 1, stop

In pass 1, Ax=(x2,x3,−x3)A x = (x_2, x_3, -x_3) lies in span⁡(e2,e3)\operatorname{span}(e_2, e_3) exactly when x2=0x_2 = 0. The intersection with K\mathcal{K} leaves span⁡(e3)\operatorname{span}(e_3). In pass 2 the sum with im⁡B\operatorname{im} B is the same as before, so line L4 stops and line L5 returns V∗=span⁡(e3)\mathcal{V}^\ast = \operatorname{span}(e_3). The list of dimensions is [2,1,1][2, 1, 1]. The friend from the code is K=[001]K = \begin{bmatrix} 0 & 0 & 1 \end{bmatrix}: then (A−BK)e3=e2−e3−e2=−e3(A - BK) e_3 = e_2 - e_3 - e_2 = -e_3. The disturbance decoupling problem page uses this result.

A chain of four integrators. For x˙1=x2\dot x_1 = x_2, x˙2=x3\dot x_2 = x_3, x˙3=x4\dot x_3 = x_4, x˙4=u\dot x_4 = u and y=x1y = x_1, the passes give span⁡(e2,e3,e4)\operatorname{span}(e_2, e_3, e_4), then span⁡(e3,e4)\operatorname{span}(e_3, e_4), then span⁡(e4)\operatorname{span}(e_4), then {0}\{0\}, and the dimensions are [3,2,1,0,0][3, 2, 1, 0, 0]. Each pass removes one state, because the output must have zero derivatives up to order 3, and the input reaches only the fourth derivative. The result V∗={0}\mathcal{V}^\ast = \{0\} says that this system has no zero dynamics. This example needs the maximum number of passes: three passes that shrink and one that confirms, which is dim⁡K+1=4\dim \mathcal{K} + 1 = 4.

Correctness

The full proof is in proofs/correctness.md. It has four steps, and each is a theorem.

  1. The sequence decreases. V1⊆K=V0\mathcal{V}_1 \subseteq \mathcal{K} = \mathcal{V}_0. If Vk⊆Vk−1\mathcal{V}_k \subseteq \mathcal{V}_{k-1}, then Vk+im⁡B⊆Vk−1+im⁡B\mathcal{V}_k + \operatorname{im} B \subseteq \mathcal{V}_{k-1} + \operatorname{im} B, and the preimage and the intersection keep this order, so Vk+1⊆Vk\mathcal{V}_{k+1} \subseteq \mathcal{V}_k.
  2. It stops. Each pass either lowers the dimension or gives Vk+1=Vk\mathcal{V}_{k+1} = \mathcal{V}_k. The dimension starts at dim⁡K\dim \mathcal{K} and cannot go below 0, so line L4 succeeds at the latest in pass dim⁡K+1\dim \mathcal{K} + 1.
  3. The result is controlled invariant and lies in K\mathcal{K}. At the stop, V=K∩A−1(V+im⁡B)\mathcal{V} = \mathcal{K} \cap A^{-1}(\mathcal{V} + \operatorname{im} B). So V⊆A−1(V+im⁡B)\mathcal{V} \subseteq A^{-1}(\mathcal{V} + \operatorname{im} B), which says AV⊆V+im⁡BA \mathcal{V} \subseteq \mathcal{V} + \operatorname{im} B.
  4. The result contains every controlled invariant subspace in K\mathcal{K}. Let U⊆K\mathcal{U} \subseteq \mathcal{K} with AU⊆U+im⁡BA\mathcal{U} \subseteq \mathcal{U} + \operatorname{im} B. Then U⊆V0\mathcal{U} \subseteq \mathcal{V}_0, and if U⊆Vk\mathcal{U} \subseteq \mathcal{V}_k, then AU⊆Vk+im⁡BA \mathcal{U} \subseteq \mathcal{V}_k + \operatorname{im} B, so U⊆K∩A−1(Vk+im⁡B)=Vk+1\mathcal{U} \subseteq \mathcal{K} \cap A^{-1}(\mathcal{V}_k + \operatorname{im} B) = \mathcal{V}_{k+1}.

A second description of Vk\mathcal{V}_k gives an independent check. By induction on kk, Vk\mathcal{V}_k is the set of states x0x_0 for which some inputs u0,…,uk−1u_0, \dots, u_{k-1} keep the discrete-time sequence xj+1=Axj+Bujx_{j+1} = A x_j + B u_j in K\mathcal{K} for j=0,…,kj = 0, \dots, k. With K=ker⁡C\mathcal{K} = \ker C this is the set of x0x_0 for which Okx0∈im⁡Tk\mathcal{O}_k x_0 \in \operatorname{im} T_k, where Ok\mathcal{O}_k stacks C,CA,…,CAkC, CA, \dots, CA^k and TkT_k is the block Toeplitz matrix of the Markov parameters CAiBCA^iB. The tests compare the algorithm with this formula for k=nk = n on 500 random integer systems, and they check the friend, the dimension list, and a brute force search over feedback gains for the decoupling problem.

Proof: The invariant subspace algorithm stops after at most dim K + 1 steps and returns the largest (A, B)-invariant subspace in Kfull

Let A∈Rn×nA \in \mathbb{R}^{n \times n}, B∈Rn×mB \in \mathbb{R}^{n \times m} and let K⊆Rn\mathcal{K} \subseteq \mathbb{R}^n be a subspace. Write B=im⁡B\mathcal{B} = \operatorname{im} B. A subspace V\mathcal{V} is (A,B)(A, B)-invariant when AV⊆V+BA \mathcal{V} \subseteq \mathcal{V} + \mathcal{B}. For a subspace W\mathcal{W}, the preimage is A−1W={x:Ax∈W}A^{-1} \mathcal{W} = \{x : A x \in \mathcal{W}\}; it is a subspace even when AA is singular. The algorithm computes

V0=K,Vk+1=K∩A−1(Vk+B),\mathcal{V}_0 = \mathcal{K}, \qquad \mathcal{V}_{k+1} = \mathcal{K} \cap A^{-1}(\mathcal{V}_k + \mathcal{B}),

and stops at the first kk with dim⁡Vk+1=dim⁡Vk\dim \mathcal{V}_{k+1} = \dim \mathcal{V}_k. It returns Vk+1\mathcal{V}_{k+1}. All operations are exact (rational arithmetic in the implementation), so every dimension is computed without error.

Lemma 1: the sequence is nonincreasing

For every kk, Vk+1⊆Vk\mathcal{V}_{k+1} \subseteq \mathcal{V}_k.

Proof. By induction on kk. For k=0k = 0, V1=K∩A−1(⋅)⊆K=V0\mathcal{V}_1 = \mathcal{K} \cap A^{-1}(\cdot) \subseteq \mathcal{K} = \mathcal{V}_0. Assume Vk⊆Vk−1\mathcal{V}_{k} \subseteq \mathcal{V}_{k-1}. Then Vk+B⊆Vk−1+B\mathcal{V}_k + \mathcal{B} \subseteq \mathcal{V}_{k-1} + \mathcal{B}, and the preimage keeps inclusions, so A−1(Vk+B)⊆A−1(Vk−1+B)A^{-1}(\mathcal{V}_k + \mathcal{B}) \subseteq A^{-1}(\mathcal{V}_{k-1} + \mathcal{B}). Intersect both sides with K\mathcal{K} to get Vk+1⊆Vk\mathcal{V}_{k+1} \subseteq \mathcal{V}_k. □\square

Lemma 2: equal dimension means a fixed point

If dim⁡Vk+1=dim⁡Vk\dim \mathcal{V}_{k+1} = \dim \mathcal{V}_k, then Vj=Vk\mathcal{V}_{j} = \mathcal{V}_k for every j≥kj \ge k.

Proof. By Lemma 1, Vk+1⊆Vk\mathcal{V}_{k+1} \subseteq \mathcal{V}_k. A subspace of a finite-dimensional space with the same dimension is the whole space, so Vk+1=Vk\mathcal{V}_{k+1} = \mathcal{V}_k. The map V↦K∩A−1(V+B)\mathcal{V} \mapsto \mathcal{K} \cap A^{-1}(\mathcal{V} + \mathcal{B}) depends only on its argument, so it maps Vk+1=Vk\mathcal{V}_{k+1} = \mathcal{V}_k to Vk+2=Vk+1\mathcal{V}_{k+2} = \mathcal{V}_{k+1}, and so on. □\square

Lemma 3: termination

The loop stops after at most dim⁡K+1\dim \mathcal{K} + 1 evaluations of the update.

Proof. While the loop runs, each step lowers the dimension by at least 1 (Lemma 1 and the stop test). The dimension starts at dim⁡K\dim \mathcal{K} and cannot go below 0. So at most dim⁡K\dim \mathcal{K} steps lower it, and the next step finds an equal dimension. □\square

Lemma 4: the result is an (A, B)-invariant subspace in K

Let V∗\mathcal{V}^\ast be the returned subspace. Then V∗⊆K\mathcal{V}^\ast \subseteq \mathcal{K} and AV∗⊆V∗+BA \mathcal{V}^\ast \subseteq \mathcal{V}^\ast + \mathcal{B}.

Proof. Every Vk\mathcal{V}_{k} with k≥1k \ge 1 is an intersection with K\mathcal{K}, and V0=K\mathcal{V}_0 = \mathcal{K}, so V∗⊆K\mathcal{V}^\ast \subseteq \mathcal{K}. By Lemma 2, V∗=K∩A−1(V∗+B)\mathcal{V}^\ast = \mathcal{K} \cap A^{-1}(\mathcal{V}^\ast + \mathcal{B}). So each x∈V∗x \in \mathcal{V}^\ast is in A−1(V∗+B)A^{-1}(\mathcal{V}^\ast + \mathcal{B}), that is, Ax∈V∗+BA x \in \mathcal{V}^\ast + \mathcal{B}. □\square

Lemma 5: the result contains every (A, B)-invariant subspace in K

Let V⊆K\mathcal{V} \subseteq \mathcal{K} with AV⊆V+BA \mathcal{V} \subseteq \mathcal{V} + \mathcal{B}. Then V⊆Vk\mathcal{V} \subseteq \mathcal{V}_k for every kk.

Proof. By induction on kk. For k=0k = 0, V⊆K=V0\mathcal{V} \subseteq \mathcal{K} = \mathcal{V}_0. Assume V⊆Vk\mathcal{V} \subseteq \mathcal{V}_k and let x∈Vx \in \mathcal{V}. Then Ax∈V+B⊆Vk+BA x \in \mathcal{V} + \mathcal{B} \subseteq \mathcal{V}_k + \mathcal{B}, so x∈A−1(Vk+B)x \in A^{-1}(\mathcal{V}_k + \mathcal{B}). Also x∈Kx \in \mathcal{K}. So x∈Vk+1x \in \mathcal{V}_{k+1}. □\square

Theorem

The algorithm stops after at most dim⁡K+1\dim \mathcal{K} + 1 updates, and the returned subspace V∗\mathcal{V}^\ast is the largest (A,B)(A, B)-invariant subspace contained in K\mathcal{K}: it is one of them, and it contains each of them.

Proof. Lemma 3 gives termination. Lemma 4 shows that V∗\mathcal{V}^\ast is in the family. Lemma 5, applied at the final index, shows that each member of the family is in V∗\mathcal{V}^\ast. A member of a family that contains every member is unique, so the largest element exists and the algorithm returns it. □\square

Lemma 6: the friend computed by the implementation

Let V\mathcal{V} be (A,B)(A, B)-invariant with basis v1,…,vqv_1, \dots, v_q. Complete it to a basis v1,…,vnv_1, \dots, v_n of Rn\mathbb{R}^n. For each i≤qi \le q choose wiw_i and uiu_i with Avi=∑j(wi)jvj+BuiA v_i = \sum_j (w_i)_j v_j + B u_i, where the sum runs over j≤qj \le q. Define KK by Kvi=uiK v_i = u_i for i≤qi \le q and Kvi=0K v_i = 0 for i>qi > q. Then (A−BK)V⊆V(A - B K) \mathcal{V} \subseteq \mathcal{V}.

Proof. The choice of wiw_i and uiu_i exists because Avi∈V+BA v_i \in \mathcal{V} + \mathcal{B}. The matrix KK exists and is unique because v1,…,vnv_1, \dots, v_n is a basis: K=UT−1K = U T^{-1} with T=[v1,…,vn]T = [v_1, \dots, v_n] and U=[u1,…,uq,0,…,0]U = [u_1, \dots, u_q, 0, \dots, 0]. For i≤qi \le q, (A−BK)vi=Avi−Bui=∑j(wi)jvj∈V(A - BK) v_i = A v_i - B u_i = \sum_j (w_i)_j v_j \in \mathcal{V}. A linear map that sends a basis of V\mathcal{V} into V\mathcal{V} sends all of V\mathcal{V} into V\mathcal{V}. □\square

The implementation returns None for the disturbance decoupling problem exactly when im⁡E⊈V∗\operatorname{im} E \not\subseteq \mathcal{V}^\ast with K=ker⁡C\mathcal{K} = \ker C. When im⁡E⊆V∗\operatorname{im} E \subseteq \mathcal{V}^\ast, Lemma 6 gives KK with (A−BK)V∗⊆V∗(A - BK) \mathcal{V}^\ast \subseteq \mathcal{V}^\ast, so (A−BK)jE(A - BK)^j E has its columns in V∗⊆ker⁡C\mathcal{V}^\ast \subseteq \ker C for every j≥0j \ge 0, and the transfer function C(sI−A+BK)−1EC (sI - A + BK)^{-1} E is zero. The converse (no KK works when im⁡E⊈V∗\operatorname{im} E \not\subseteq \mathcal{V}^\ast) is proved on the disturbance decoupling problem page: for any KK, the smallest (A−BK)(A - BK)-invariant subspace that contains im⁡E\operatorname{im} E is (A,B)(A, B)-invariant and lies in ker⁡C\ker C when the output is decoupled, so it is in V∗\mathcal{V}^\ast by Lemma 5.

Complexity

In the real RAM, with exact arithmetic on the entries:

  • Line L3 builds a matrix with nn rows and at most n+mn + m columns for the sum, one with nn rows and at most 2n+m2n + m columns for the preimage, and one with nn rows and at most 2n2n columns for the intersection. Each kernel or rank by Gaussian elimination costs O(n2(n+m))O(n^2 (n + m)).
  • Lines L4 and L6 cost O(n2)O(n^2).
  • Lines L2 to L6 run at most dim⁡K+1≤n+1\dim \mathcal{K} + 1 \le n + 1 times.

So the time is O(n3(n+m))O(n^3 (n + m)) and the extra space is O(n(n+m))O(n (n + m)). This is a theorem about the number of arithmetic operations. With Fraction entries the cost in bit operations is higher, because the numerators and denominators grow; for integer data of bit size β\beta the sizes stay polynomial in nn and β\beta if the elimination is done in a fraction-free way, but the implementation does not bound them.

Properties

  • The result for one input and one output. If CAiB=0C A^{i} B = 0 for i<ρ−1i < \rho - 1 and CAρ−1B≠0C A^{\rho - 1} B \ne 0, the relative degree is ρ\rho. Then the rows C,CA,…,CAρ−1C, CA, \dots, CA^{\rho - 1} are linearly independent, V∗=ker⁡[CCA⋮CAρ−1]\mathcal{V}^\ast = \ker \begin{bmatrix} C \\ CA \\ \vdots \\ CA^{\rho - 1} \end{bmatrix} and dim⁡V∗=n−ρ\dim \mathcal{V}^\ast = n - \rho. This is a theorem; for the chain it gives 4−4=04 - 4 = 0, and for the first example 3−2=13 - 2 = 1.
  • Fixed poles are zeros. The eigenvalues of A−BKA - BK restricted to V∗\mathcal{V}^\ast that are the same for every friend KK are the invariant zeros of (A,B,C)(A, B, C). For a system with as many inputs as outputs and an invertible transfer function they are the transmission zeros. This is a theorem of the geometric theory; in the first example the only friend eigenvalue on V∗\mathcal{V}^\ast is −1-1, and C(sI−A)−1B=(s+1)/(s2(s+1))C(sI - A)^{-1} B = (s + 1)/(s^2 (s + 1)) before cancellation, so −1-1 is the invariant zero.
  • Dual algorithm. The smallest conditioned invariant subspace containing a subspace S0\mathcal{S}_0 comes from the increasing recursion Sk+1=S0+A(Sk∩ker⁡C)\mathcal{S}_{k+1} = \mathcal{S}_0 + A(\mathcal{S}_k \cap \ker C). It is the ISA for (AT,CT)(A^T, C^T) applied to orthogonal complements, and it is used for observers with unknown inputs (see unknown input observer).
  • Not continuous in the data. V∗\mathcal{V}^\ast can jump when the matrices change by a small amount, as the second pitfall below shows. The exact algorithm computes the right answer for the given rational data, but that answer can be a poor model of a physical system whose matrices are known only approximately.

Variants and improvements

  • Controllability subspace algorithm. The largest controllability subspace R∗\mathcal{R}^\ast in ker⁡C\ker C comes from a second, increasing recursion inside V∗\mathcal{V}^\ast: S0={0}\mathcal{S}_0 = \{0\}, Sk+1=V∗∩(ASk+im⁡B)\mathcal{S}_{k+1} = \mathcal{V}^\ast \cap (A \mathcal{S}_k + \operatorname{im} B). It is needed for the decoupling problems with pole placement (Wonham and Morse 1970).
  • Stabilizable version. For disturbance decoupling with internal stability one needs the largest stabilizability subspace in ker⁡C\ker C. It is computed from V∗\mathcal{V}^\ast, R∗\mathcal{R}^\ast and the fixed poles: keep the part of V∗\mathcal{V}^\ast that belongs to fixed poles in the open left half plane.
  • Orthonormal bases in floating point. Numerical versions replace the echelon forms by QR decompositions with column pivoting or by the singular value decomposition, and decide each rank with a tolerance. They give a nearby subspace for a nearby system, which is what one can ask for an ill-posed problem.
  • Pencil methods. V∗\mathcal{V}^\ast can also be read from the Kronecker structure of the system pencil [A−λIBC0]\begin{bmatrix} A - \lambda I & B \\ C & 0 \end{bmatrix}, which staircase algorithms compute with orthogonal transformations. This is the usual route in numerical libraries.

When to use it

Use the exact ISA to decide structural questions about a model with known rational entries: whether a disturbance can be decoupled, what the zero dynamics of a linear system are, whether an observer with unknown inputs exists. It is also the right tool in teaching and in symbolic work, because each pass has a clear meaning. For models with measured or rounded entries, use a numerical version with orthogonal bases and an explicit rank tolerance, and check the answer for a few tolerances. If you need only the invariant zeros of a square system, a generalized eigenvalue computation on the system pencil is cheaper and better conditioned.

Pitfalls

  • Line L3 without the intersection with K\mathcal{K}. Without "K∩\mathcal{K} \cap", the recursion Vk+1=A−1(Vk+im⁡B)\mathcal{V}_{k+1} = A^{-1}(\mathcal{V}_k + \operatorname{im} B) does not stay in K\mathcal{K}, and its limit is a controlled invariant subspace that has nothing to do with the output. In the first example it gives span⁡(e1,e3)\operatorname{span}(e_1, e_3) in pass 1, which is not in ker⁡C\ker C.
  • Line L3 with floating-point rank decisions. Take A=[0100]A = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}, C=[10]C = \begin{bmatrix} 1 & 0 \end{bmatrix} and B=[ε1]B = \begin{bmatrix} \varepsilon \\ 1 \end{bmatrix}. For ε≠0\varepsilon \ne 0 the sum ker⁡C+im⁡B\ker C + \operatorname{im} B is the whole plane and V∗=ker⁡C\mathcal{V}^\ast = \ker C, of dimension 1. For ε=0\varepsilon = 0 it is ker⁡C\ker C itself, and V∗={0}\mathcal{V}^\ast = \{0\}. The exact code returns dimension lists [1,1][1, 1] for ε=1/1000\varepsilon = 1/1000 and [1,0,0][1, 0, 0] for ε=0\varepsilon = 0. In floating point an ε\varepsilon near the rounding unit of the floating-point model can fall on either side of the rank tolerance. State the tolerance, and look at the gaps of the singular values next to each rank decision.
  • Line L3 with the image instead of the preimage. The recursion K∩A(Vk+im⁡B)\mathcal{K} \cap A(\mathcal{V}_k + \operatorname{im} B) is a different map. The forward image belongs to the dual, increasing algorithm for conditioned invariant subspaces, and it does not give V∗\mathcal{V}^\ast.
  • Line L4 that compares bases. Two bases of the same subspace can differ entrywise, so a test "W=VW = V as matrices" can fail to stop. Compare dimensions, as line L4 does, or compare the reduced row echelon forms, which are unique.
  • Line L5 is not the end of a design. V∗\mathcal{V}^\ast alone does not give a usable feedback. The friend is not unique, and its fixed poles, the invariant zeros, may be in the right half plane. A disturbance decoupling design with such a friend has an unstable closed loop; use the stabilizable version.

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.

invariant_subspace_algorithm.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/invariant-subspace-algorithm/. The authors are listed in prov/55N3T2.jsonl.

"""The invariant subspace algorithm (ISA) of geometric control.

For x' = A x + B u and a subspace K of R^n (for example ker C), the
sequence

    V_0 = K,    V_(k+1) = K intersected with A^(-1)(V_k + im B)

is nonincreasing and stops after at most dim K + 1 steps at V*, the largest
(A, B)-invariant subspace contained in K. A subspace V is (A, B)-invariant
when A V is contained in V + im B; then some K_f gives (A - B K_f) V in V.

All subspace operations are exact in Fraction: a subspace is a list of basis
vectors (flat lists), kept in reduced row echelon form, so two equal
subspaces have the same representation.

The disturbance decoupling problem (DDP) for x' = A x + B u + E d, y = C x,
with state feedback u = -K x, is solvable if and only if im E is contained
in V*, the largest (A, B)-invariant subspace in ker C.
"""

from fractions import Fraction

__all__ = [
    "rref", "span", "kernel", "image", "subspace_sum", "intersection",
    "preimage", "contains", "is_ab_invariant", "isa", "friend",
    "ddp", "markov_zero",
]


def _frac_matrix(a):
    return [[Fraction(v) for v in row] for row in a]


def rref(rows):
    """Return the nonzero rows of the reduced row echelon form of rows."""
    m = [[Fraction(v) for v in r] for r in rows]
    if not m:
        return []
    ncol = len(m[0])
    out_row = 0
    for c in range(ncol):
        piv = None
        for r in range(out_row, len(m)):
            if m[r][c] != 0:
                piv = r
                break
        if piv is None:
            continue
        m[out_row], m[piv] = m[piv], m[out_row]
        p = m[out_row][c]
        m[out_row] = [v / p for v in m[out_row]]
        for r in range(len(m)):
            if r != out_row and m[r][c] != 0:
                f = m[r][c]
                m[r] = [x - f * y for x, y in zip(m[r], m[out_row])]
        out_row += 1
        if out_row == len(m):
            break
    return [r for r in m[:out_row] if any(v != 0 for v in r)]


def span(vectors):
    """Return the canonical basis (reduced row echelon form) of the span."""
    return rref(vectors)


def kernel(a, n=None):
    """Return a basis of {x : a x = 0}; n is the number of columns if a is empty."""
    a = _frac_matrix(a)
    if n is None:
        n = len(a[0]) if a else 0
    r = rref(a) if a else []
    pivots = []
    for row in r:
        for j, v in enumerate(row):
            if v != 0:
                pivots.append(j)
                break
    free = [j for j in range(n) if j not in pivots]
    basis = []
    for f in free:
        x = [Fraction(0)] * n
        x[f] = Fraction(1)
        for row, pj in zip(r, pivots):
            x[pj] = -row[f]
        basis.append(x)
    return span(basis)


def image(a):
    """Return a basis of the column space of a."""
    if not a or not a[0]:
        return []
    cols = [[Fraction(a[i][j]) for i in range(len(a))] for j in range(len(a[0]))]
    return span(cols)


def subspace_sum(u, v):
    """Return a basis of U + V."""
    return span(list(u) + list(v))


def intersection(u, v, n):
    """Return a basis of U intersected with V, both subspaces of R^n."""
    if not u or not v:
        return []
    # x = U a = V b: solve [U, -V] (a, b) = 0 and map back with U.
    k = len(u)
    mat = [[u[j][i] for j in range(k)] + [-v[j][i] for j in range(len(v))] for i in range(n)]
    sols = kernel(mat, k + len(v))
    vecs = [[sum(s[j] * u[j][i] for j in range(k)) for i in range(n)] for s in sols]
    return span(vecs)


def preimage(a, v):
    """Return a basis of A^(-1) V = {x : A x in V}."""
    n = len(a[0])
    # A x - V b = 0: solve [A, -V] (x, b) = 0 and keep the x part.
    mat = [[Fraction(a[i][j]) for j in range(n)] + [-w[i] for w in v] for i in range(len(a))]
    sols = kernel(mat, n + len(v))
    return span([s[:n] for s in sols])


def contains(u, v):
    """Return True if the subspace V is contained in U."""
    return len(subspace_sum(u, v)) == len(span(u))


def _matvec(a, x):
    return [sum(Fraction(ai) * xi for ai, xi in zip(row, x)) for row in a]


def is_ab_invariant(a, b, v):
    """Return True if A V is contained in V + im B."""
    target = subspace_sum(v, image(b))
    return all(contains(target, [_matvec(a, x)]) for x in v)


def isa(a, b, k_space):
    """Return (V*, dims): the largest (A, B)-invariant subspace in K.

    k_space is a basis of K. dims lists dim V_0, dim V_1, ... up to the
    first repeated value, so the last two entries are equal.
    """
    n = len(a)
    im_b = image(b)
    v = span(k_space)  # @line L1
    dims = [len(v)]
    while True:  # @line L2
        w = intersection(span(k_space), preimage(a, subspace_sum(v, im_b)), n)  # @line L3
        dims.append(len(w))
        if len(w) == len(v):  # @line L4
            return w, dims  # @line L5
        v = w  # @line L6


def _solve_square(m, rhs):
    """Solve m x = rhs exactly; m is square and invertible, rhs is a matrix."""
    n = len(m)
    aug = [list(map(Fraction, m[i])) + list(map(Fraction, rhs[i])) for i in range(n)]
    r = rref(aug)
    if len(r) < n or any(r[i][i] != 1 for i in range(n)):
        raise ValueError("matrix is singular")
    return [row[n:] for row in r]


def friend(a, b, v):
    """Return K (m by n, Fraction) with (A - B K) V contained in V.

    K is chosen on a basis of V and set to 0 on a complement of V. Raises
    ValueError if V is not (A, B)-invariant.
    """
    n = len(a)
    m = len(b[0]) if b and b[0] else 0
    basis = span(v)
    cols = []
    for x in basis:
        ax = _matvec(a, x)
        # A x = V w + B u: solve [V, B] (w, u) = A x.
        mat = [[w[i] for w in basis] + [Fraction(b[i][j]) for j in range(m)] for i in range(n)]
        sol = _particular(mat, ax)
        if sol is None:
            raise ValueError("V is not (A, B)-invariant")
        cols.append(sol[len(basis):])
    # Complete the basis of V to a basis T of R^n with unit vectors.
    t = list(basis)
    for i in range(n):
        e = [Fraction(int(i == j)) for j in range(n)]
        if len(span(t + [e])) > len(t):
            t.append(e)
    # K T = [u_1 ... u_k, 0 ... 0], so K = U T^(-1).
    u = [[cols[j][i] if j < len(cols) else Fraction(0) for j in range(n)] for i in range(m)]
    tmat = [[t[j][i] for j in range(n)] for i in range(n)]
    # Solve T^T K^T = U^T for K^T.
    tt = [[tmat[j][i] for j in range(n)] for i in range(n)]
    ut = [[u[i][j] for i in range(m)] for j in range(n)]
    kt = _solve_square(tt, ut)
    return [[kt[j][i] for j in range(n)] for i in range(m)]


def _particular(mat, rhs):
    """Return one solution x of mat x = rhs, or None if there is none."""
    ncol = len(mat[0])
    aug = [list(map(Fraction, mat[i])) + [Fraction(rhs[i])] for i in range(len(mat))]
    r = rref(aug)
    x = [Fraction(0)] * ncol
    for row in r:
        lead = next(j for j, v in enumerate(row) if v != 0)
        if lead == ncol:
            return None
        x[lead] = row[ncol]
    return x


def ddp(a, b, c, e):
    """Solve the disturbance decoupling problem by state feedback.

    Returns (K, V*) with C (A - B K)^j E = 0 for all j, or (None, V*) when
    im E is not contained in V*.
    """
    n = len(a)
    vstar, _ = isa(a, b, kernel(c, n))
    if not contains(vstar, image(e)):
        return None, vstar
    return friend(a, b, vstar), vstar


def markov_zero(a, b, c, e, k):
    """Return True if C (A - B K)^j E = 0 for j = 0, ..., n - 1."""
    n = len(a)
    m = len(b[0])
    acl = [[Fraction(a[i][j]) - sum(Fraction(b[i][t]) * k[t][j] for t in range(m)) for j in range(n)] for i in range(n)]
    cols = [[Fraction(e[i][j]) for i in range(n)] for j in range(len(e[0]))]
    for _ in range(n):
        for x in cols:
            if any(v != 0 for v in _matvec(c, x)):
                return False
        cols = [_matvec(acl, x) for x in cols]
    return True
test_invariant_subspace_algorithm.py 203 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/invariant-subspace-algorithm/. The authors are listed in prov/55N3T2.jsonl.

import itertools
import random
from fractions import Fraction

from invariant_subspace_algorithm import (
    contains, ddp, friend, image, intersection, is_ab_invariant, isa,
    kernel, markov_zero, preimage, span, subspace_sum,
)


def unit(i, n):
    return [Fraction(int(i == j)) for j in range(n)]


def rank(a):
    """Rank by fraction-free elimination, written apart from the module."""
    m = [[Fraction(v) for v in row] for row in a]
    r = 0
    ncol = len(m[0]) if m else 0
    for c in range(ncol):
        p = next((i for i in range(r, len(m)) if m[i][c] != 0), None)
        if p is None:
            continue
        m[r], m[p] = m[p], m[r]
        for i in range(r + 1, len(m)):
            f = m[i][c] / m[r][c]
            m[i] = [x - f * y for x, y in zip(m[i], m[r])]
        r += 1
    return r


def matmul(a, b):
    return [[sum(Fraction(a[i][t]) * b[t][j] for t in range(len(b))) for j in range(len(b[0]))] for i in range(len(a))]


def matvec(a, x):
    return [sum(Fraction(v) * w for v, w in zip(row, x)) for row in a]


def rand_mat(rng, n, m, lo=-2, hi=2):
    return [[rng.randint(lo, hi) for _ in range(m)] for _ in range(n)]


def toeplitz_reference(a, b, c):
    """V* as the states x0 for which inputs u_0..u_(n-1) give y_0 = ... = y_n = 0.

    For x_(k+1) = A x_k + B u_k, y_k = C x_k, stack y_0..y_n = O x0 + T u
    and return {x0 : O x0 in im T}, as the x part of ker [O, T].
    """
    n, m, p = len(a), len(b[0]), len(c)
    powers = [[[Fraction(int(i == j)) for j in range(n)] for i in range(n)]]
    for _ in range(n):
        powers.append(matmul(a, powers[-1]))
    obs = []
    for k in range(n + 1):
        obs.extend(matmul(c, powers[k]))
    big = []
    for k in range(n + 1):
        for i in range(p):
            row = list(obs[k * p + i])
            for j in range(n):
                if j < k:
                    blk = matmul(matmul(c, powers[k - 1 - j]), b)
                    row.extend(blk[i])
                else:
                    row.extend([Fraction(0)] * m)
            big.append(row)
    sols = kernel(big, n + n * m)
    return span([s[:n] for s in sols])


def test_kernel_matches_rank():
    rng = random.Random(1)
    for _ in range(60):
        n, k = rng.randint(1, 5), rng.randint(1, 5)
        a = rand_mat(rng, k, n)
        ker = kernel(a, n)
        assert len(ker) + rank(a) == n
        for x in ker:
            assert all(v == 0 for v in matvec(a, x))


def test_subspace_operations():
    rng = random.Random(2)
    for _ in range(40):
        n = rng.randint(2, 5)
        u = span([[Fraction(rng.randint(-2, 2)) for _ in range(n)] for _ in range(rng.randint(1, n))])
        v = span([[Fraction(rng.randint(-2, 2)) for _ in range(n)] for _ in range(rng.randint(1, n))])
        s = subspace_sum(u, v)
        i = intersection(u, v, n)
        assert len(s) + len(i) == len(u) + len(v)
        assert contains(u, i) and contains(v, i)
        a = rand_mat(rng, n, n)
        pre = preimage(a, v)
        for x in pre:
            assert contains(v, [matvec(a, x)])
        # dim A^(-1) V = dim ker A + dim (V intersected with im A)
        assert len(pre) == len(kernel(a, n)) + len(intersection(v, image(a), n))


def test_chain_of_four_integrators():
    n = 4
    a = [[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], [0, 0, 0, 0]]
    b = [[0], [0], [0], [1]]
    c = [[1, 0, 0, 0]]
    vstar, dims = isa(a, b, kernel(c, n))
    assert dims == [3, 2, 1, 0, 0]
    assert vstar == []


def test_ddp_example_of_the_page():
    a = [[0, 1, 0], [0, 0, 1], [0, 0, -1]]
    b = [[0], [1], [0]]
    c = [[1, 0, 0]]
    e = [[0], [0], [1]]
    vstar, dims = isa(a, b, kernel(c, 3))
    assert dims == [2, 1, 1]
    assert vstar == [unit(2, 3)]
    k, v = ddp(a, b, c, e)
    assert k == [[0, 0, 1]]
    assert markov_zero(a, b, c, e, k)
    # Every K = [k1, k2, 1] decouples, and K = [1, 2, 1] puts all poles at -1.
    assert markov_zero(a, b, c, e, [[Fraction(1), Fraction(2), Fraction(1)]])
    assert not markov_zero(a, b, c, e, [[Fraction(1), Fraction(2), Fraction(0)]])
    # With the disturbance in the input channel, DDP has no solution.
    k2, _ = ddp(a, b, c, [[0], [1], [0]])
    assert k2 is None


def test_sum_closed_intersection_not():
    a = [[0, 1, 0], [0, 0, 1], [0, 0, 0]]
    b = [[0], [0], [1]]
    v1 = span([unit(0, 3), unit(1, 3)])
    v2 = span([unit(1, 3), [Fraction(1), Fraction(0), Fraction(1)]])
    assert is_ab_invariant(a, b, v1) and is_ab_invariant(a, b, v2)
    assert is_ab_invariant(a, b, subspace_sum(v1, v2))
    meet = intersection(v1, v2, 3)
    assert meet == [unit(1, 3)]
    assert not is_ab_invariant(a, b, meet)


def test_random_systems_against_toeplitz_reference():
    rng = random.Random(3)
    nontrivial = 0
    for trial in range(500):
        n = rng.randint(2, 5) if trial < 80 else rng.randint(1, 3)
        m = rng.randint(1, 2)
        p = rng.randint(1, 2)
        a = rand_mat(rng, n, n)
        b = rand_mat(rng, n, m)
        c = rand_mat(rng, p, n)
        if trial % 4 == 0:
            # Make C B = 0 often, so V* is not trivial.
            b = [[0] * m for _ in range(n)]
            b[n - 1] = [1] * m
            c = [[rng.randint(-2, 2) for _ in range(n - 1)] + [0] for _ in range(p)]
        ker_c = kernel(c, n)
        vstar, dims = isa(a, b, ker_c)
        # the sequence is nonincreasing, strictly until it stops, and short
        assert all(x > y for x, y in zip(dims[:-2], dims[1:-1]))
        assert dims[-1] == dims[-2]
        assert len(dims) - 1 <= len(ker_c) + 1
        assert contains(ker_c, vstar)
        assert is_ab_invariant(a, b, vstar)
        assert vstar == toeplitz_reference(a, b, c)
        if vstar:
            nontrivial += 1
            k = friend(a, b, vstar)
            acl = [[Fraction(a[i][j]) - sum(Fraction(b[i][t]) * k[t][j] for t in range(m)) for j in range(n)] for i in range(n)]
            for x in vstar:
                assert contains(vstar, [matvec(acl, x)])
    assert nontrivial >= 10


def test_ddp_random_against_brute_force_feedback():
    rng = random.Random(4)
    yes = no = 0
    for _ in range(60):
        n = rng.randint(2, 3)
        a = rand_mat(rng, n, n)
        b = rand_mat(rng, n, 1)
        c = rand_mat(rng, 1, n)
        e = rand_mat(rng, n, 1)
        k, vstar = ddp(a, b, c, e)
        if k is not None:
            yes += 1
            assert markov_zero(a, b, c, e, k)
        else:
            no += 1
            for ks in itertools.product(range(-2, 3), repeat=n):
                kk = [[Fraction(v) for v in ks]]
                assert not markov_zero(a, b, c, e, kk)
    assert yes >= 3 and no >= 10


def test_full_state_space_when_c_is_zero():
    a = [[1, 2], [3, 4]]
    b = [[1], [0]]
    vstar, dims = isa(a, b, kernel([[0, 0]], 2))
    assert len(vstar) == 2 and dims == [2, 2]

History

Basile and Marro (1969) introduced controlled and conditioned invariant subspaces as tools for linear system theory. Wonham and Morse (1970) introduced the name (A,B)(A, B)-invariant subspace, proved that the supremal one in a given subspace exists, gave the descending recursion to compute it, and used it to solve the disturbance decoupling problem and the decoupling of outputs by state feedback. Wonham's book Linear Multivariable Control, A Geometric Approach (first edition 1974, third edition 1985) made the method a standard part of linear control theory. The book of Trentelman, Stoorvogel and Hautus (2001) gives a modern treatment with the stabilizability subspaces.

References

  1. W. M. Wonham and A. S. Morse, Decoupling and pole assignment in linear multivariable systems, a geometric approach, SIAM Journal on Control 8(1), 1-18, 1970, the supremal (A, B)-invariant subspace contained in a given subspace and the descending recursion for it
  2. G. Basile and G. Marro, Controlled and conditioned invariant subspaces in linear system theory, Journal of Optimization Theory and Applications 3(5), 306-315, 1969, the controlled and conditioned invariant subspaces and the algorithms for the extreme ones
  3. W. Murray Wonham, Linear Multivariable Control, A Geometric Approach, third edition, Springer, 1985, Chapter 4, Disturbance Decoupling and Output Stabilization (the algorithm for the supremal (A, B)-invariant subspace)
  4. Harry L. Trentelman, Anton A. Stoorvogel and Malo Hautus, Control Theory for Linear Systems, Springer, 2001, Chapter 4, Controlled invariant subspaces

Where this leads

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