What Can the Matrix Sign Function mcsgn Compute?

In "The Derivative of msign", we formally introduced two matrix sign functions, $\newcommand{msign}{\mathop{\text{msign}}}\msign$ and $\newcommand{mcsgn}{\mathop{\text{mcsgn}}}\mcsgn$, where $\msign$ is the core operation of Muon, while $\mcsgn$ is used to solve the Sylvester equation. So besides solving Sylvester equations, what else can $\mcsgn$ be used for? This post collects some answers to that question.

Two kinds of sign

Let matrix $\boldsymbol{M}\in\mathbb{R}^{n\times m}$. We have two matrix sign functions:

\begin{gather}\msign(\boldsymbol{M}) = (\boldsymbol{M}\boldsymbol{M}^{\top})^{-1/2}\boldsymbol{M}= \boldsymbol{M}(\boldsymbol{M}^{\top}\boldsymbol{M})^{-1/2} \\[6pt] \mcsgn(\boldsymbol{M}) = (\boldsymbol{M}^2)^{-1/2}\boldsymbol{M}= \boldsymbol{M}(\boldsymbol{M}^2)^{-1/2} \end{gather}

The first applies to matrices of any shape, while the second only applies to square matrices; $^{-1/2}$ is the inverse of the $1/2$-th power of the matrix — if it's not invertible, we compute it via the "pseudo-inverse" instead. In general $\msign$ and $\mcsgn$ give different results, but when $\boldsymbol{M}$ is a symmetric matrix, they coincide.

The difference between them is this: if $\boldsymbol{M}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^{\top}$, where $\boldsymbol{U},\boldsymbol{V}$ is an orthogonal matrix, then $\msign(\boldsymbol{M}) = \boldsymbol{U}\msign(\boldsymbol{\Sigma})\boldsymbol{V}^{\top}$; whereas if $\boldsymbol{M}=\boldsymbol{P}\boldsymbol{\Lambda}\boldsymbol{P}^{-1}$, where $\boldsymbol{P}$ is an invertible matrix, then $\mcsgn(\boldsymbol{M})=\boldsymbol{P}\mcsgn(\boldsymbol{\Lambda})\boldsymbol{P}^{-1}$. In plain terms, one has orthogonal invariance and the other has similarity invariance; one turns all nonzero singular values into 1, and the other turns all nonzero eigenvalues into $\pm 1$.

For how to compute $\msign$, see "Newton-Schulz Iteration for the msign Operator (Part 1)" and "Newton-Schulz Iteration for the msign Operator (Part 2)" — it is GPU-efficient. As for $\mcsgn$, since eigenvalues may be complex, the general case can get quite complicated, but when the eigenvalues of $\boldsymbol{M}$ are all real (which, in fact, covers nearly all practical use cases of $\mcsgn$), we can reuse the iteration for $\msign$:

\begin{equation}\newcommand{tr}{\mathop{\text{tr}}}\boldsymbol{X}_0 = \frac{\boldsymbol{M}}{\sqrt{\tr(\boldsymbol{M}^2)}},\qquad \boldsymbol{X}_{t+1} = a_{t+1}\boldsymbol{X}_t + b_{t+1}\boldsymbol{X}_t^3 + c_{t+1}\boldsymbol{X}_t^5\end{equation}

We won't dwell on further properties here; instead, let's focus on the applications of $\mcsgn$.

Block Identity

Historically, $\mcsgn$ was introduced precisely for solving equations — not just the Sylvester equation, but more generally the algebraic Riccati equation; the original paper can be found in "Solving the algebraic Riccati equation with the matrix sign function".

Consider the block matrix $\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}$. We have $\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}^{-1} = \begin{bmatrix}\boldsymbol{0} & \boldsymbol{I} \\ -\boldsymbol{I} & \boldsymbol{X}\end{bmatrix}$, which can be verified as

\begin{equation}\begin{bmatrix}\boldsymbol{0} & \boldsymbol{I} \\ -\boldsymbol{I} & \boldsymbol{X}\end{bmatrix}\begin{bmatrix}\boldsymbol{A} & \boldsymbol{C} \\ \boldsymbol{D} & \boldsymbol{B}\end{bmatrix}\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}=\begin{bmatrix}\boldsymbol{B} + \boldsymbol{D}\boldsymbol{X} & -\boldsymbol{D} \\ \boldsymbol{X}\boldsymbol{D}\boldsymbol{X} + \boldsymbol{X}\boldsymbol{B} - \boldsymbol{A}\boldsymbol{X} - \boldsymbol{C} & \boldsymbol{A} - \boldsymbol{X}\boldsymbol{D}\end{bmatrix}\end{equation}

If

\begin{equation}\boldsymbol{X}\boldsymbol{D}\boldsymbol{X} + \boldsymbol{X}\boldsymbol{B} - \boldsymbol{A}\boldsymbol{X} - \boldsymbol{C} = \boldsymbol{0}\label{eq:riccati}\end{equation}

then

\begin{equation}\begin{bmatrix}\boldsymbol{A} & \boldsymbol{C} \\ \boldsymbol{D} & \boldsymbol{B}\end{bmatrix}=\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}\begin{bmatrix}\boldsymbol{B} + \boldsymbol{D}\boldsymbol{X} & -\boldsymbol{D} \\ \boldsymbol{0} & \boldsymbol{A} - \boldsymbol{X}\boldsymbol{D}\end{bmatrix}\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}^{-1}\end{equation}

Equation $\eqref{eq:riccati}$ is exactly the algebraic Riccati equation. Taking $\mcsgn$ of both sides, we obtain the identity

\begin{equation}\begin{aligned} \mcsgn\left(\begin{bmatrix}\boldsymbol{A} & \boldsymbol{C} \\ \boldsymbol{D} & \boldsymbol{B}\end{bmatrix}\right)=&\,\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}\mcsgn\left(\begin{bmatrix}\boldsymbol{B} + \boldsymbol{D}\boldsymbol{X} & -\boldsymbol{D} \\ \boldsymbol{0} & \boldsymbol{A} - \boldsymbol{X}\boldsymbol{D}\end{bmatrix}\right)\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}^{-1} \\[6pt] =&\,\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}\begin{bmatrix}\mcsgn(\boldsymbol{B} + \boldsymbol{D}\boldsymbol{X}) & \boldsymbol{Y} \\ \boldsymbol{0} & \mcsgn(\boldsymbol{A} - \boldsymbol{X}\boldsymbol{D})\end{bmatrix}\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}^{-1} \end{aligned}\end{equation}

The second equality relies on properties of (block) triangular matrices. The eigenvalues of a triangular matrix are simply its diagonal entries, so applying $\mcsgn$ to a triangular matrix yields another triangular matrix whose diagonal entries are the $\mathop{\text{csgn}}$ of the original matrix's diagonal entries. This property also holds for block triangular matrices, which is why the result takes the form of the second equality, with $\boldsymbol{Y}$ being an undetermined matrix.

A Few Results

Below we further simplify things case by case, arriving at some potentially useful results.

First example

Suppose $\boldsymbol{D}=\boldsymbol{0}$, where $\boldsymbol{B}$ is positive definite and $\boldsymbol{A}$ is negative definite. Since block-diagonal matrix operations are closed, we have $\boldsymbol{Y}=\boldsymbol{0}$, and therefore

\begin{equation}\mcsgn\left(\begin{bmatrix}\boldsymbol{A} & \boldsymbol{C} \\ \boldsymbol{0} & \boldsymbol{B}\end{bmatrix}\right)=\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}\begin{bmatrix}\boldsymbol{I} & \boldsymbol{0} \\ \boldsymbol{0} & -\boldsymbol{I}\end{bmatrix}\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}^{-1} = \begin{bmatrix}-\boldsymbol{I} & 2\boldsymbol{X} \\ \boldsymbol{0} & \boldsymbol{I}\end{bmatrix}\end{equation}

This means we can directly read off the solution to the Sylvester equation $\boldsymbol{X}\boldsymbol{B} - \boldsymbol{A}\boldsymbol{X} = \boldsymbol{C}$ from $\mcsgn\left(\begin{bmatrix}\boldsymbol{A} & \boldsymbol{C} \\ \boldsymbol{0} & \boldsymbol{B}\end{bmatrix}\right)$.

Second example

Suppose $\boldsymbol{A},\boldsymbol{B}=\boldsymbol{0}$, $\boldsymbol{D}=\boldsymbol{I}$, with $\boldsymbol{C}$ positive definite. Then the Riccati equation reduces to $\boldsymbol{X}^2 = \boldsymbol{C}$, i.e., $\boldsymbol{X}=\boldsymbol{C}^{1/2}$, so $\mcsgn(\boldsymbol{C}^{1/2})=\boldsymbol{I}$, giving

\begin{equation}\mcsgn\left(\begin{bmatrix}\boldsymbol{0} & \boldsymbol{C} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}\right)=\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}\begin{bmatrix}\boldsymbol{I} & \boldsymbol{Y} \\ \boldsymbol{0} & - \boldsymbol{I}\end{bmatrix}\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}^{-1} = \begin{bmatrix}-\boldsymbol{X}\boldsymbol{Y}-\boldsymbol{I} & 2\boldsymbol{X} + \boldsymbol{X}\boldsymbol{Y}\boldsymbol{X} \\ -\boldsymbol{Y} & \boldsymbol{Y}\boldsymbol{X} + \boldsymbol{I}\end{bmatrix}\end{equation}

Note that $\mcsgn$ is an odd function, and the odd function of an anti-diagonal matrix must also be anti-diagonal; hence $\boldsymbol{Y}\boldsymbol{X} + \boldsymbol{I}=\boldsymbol{0}$, from which we solve for $\boldsymbol{Y} = -\boldsymbol{X}^{-1} = -\boldsymbol{C}^{-1/2}$, and substituting back into the above yields

\begin{equation}\mcsgn\left(\begin{bmatrix}\boldsymbol{0} & \boldsymbol{C} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}\right)=\begin{bmatrix}\boldsymbol{0} & \boldsymbol{C}^{1/2} \\ \boldsymbol{C}^{-1/2} & \boldsymbol{0}\end{bmatrix}\end{equation}

This shows that $\mcsgn$ can also be used to compute the square root and inverse square root of a matrix.

Third example

Suppose $\boldsymbol{A},\boldsymbol{B}=\boldsymbol{0}$, $\boldsymbol{D}=\boldsymbol{C}^{\top}$. Then the Riccati equation reduces to $\boldsymbol{X}\boldsymbol{C}^{\top}\boldsymbol{X} = \boldsymbol{C}$, and it's easy to verify that $\boldsymbol{X}=\msign(\boldsymbol{C})$ is indeed its solution. We only demonstrate the most ideal case, where $\boldsymbol{C}$ is a full-rank square matrix, so that both $\boldsymbol{C}^{\top}\boldsymbol{X}$ and $\boldsymbol{X}\boldsymbol{C}^{\top}$ are positive definite, and thus

\begin{equation}\mcsgn\left(\begin{bmatrix}\boldsymbol{0} & \boldsymbol{C} \\ \boldsymbol{C}^{\top} & \boldsymbol{0}\end{bmatrix}\right)=\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}\begin{bmatrix}\boldsymbol{I} & \boldsymbol{Y} \\ \boldsymbol{0} & -\boldsymbol{I}\end{bmatrix}\begin{bmatrix}\boldsymbol{X} & -\boldsymbol{I} \\ \boldsymbol{I} & \boldsymbol{0}\end{bmatrix}^{-1}=\begin{bmatrix}-\boldsymbol{X}\boldsymbol{Y}-\boldsymbol{I} & 2\boldsymbol{X} + \boldsymbol{X}\boldsymbol{Y}\boldsymbol{X} \\ -\boldsymbol{Y} & \boldsymbol{Y}\boldsymbol{X} + \boldsymbol{I}\end{bmatrix}\end{equation}

By the same reasoning as in the previous section, $\boldsymbol{Y}\boldsymbol{X} + \boldsymbol{I}=0$, so

\begin{equation}\mcsgn\left(\begin{bmatrix}\boldsymbol{0} & \boldsymbol{C} \\ \boldsymbol{C}^{\top} & \boldsymbol{0}\end{bmatrix}\right)=\begin{bmatrix}\boldsymbol{0} & \msign(\boldsymbol{C}) \\ \msign(\boldsymbol{C}^{\top}) & \boldsymbol{0}\end{bmatrix}\end{equation}

That is, $\mcsgn$ can also be used to compute $\msign$. In fact, this identity can be directly proven to hold for arbitrary matrices $\boldsymbol{C}$, but proving it by way of solving the Riccati equation, as we've done here, involves some tedious details, which we leave for the reader to fill in.

Fourth example

The second and third examples can be generalized into a broader conclusion:

\begin{equation}\mcsgn\left(\begin{bmatrix}\boldsymbol{0} & \boldsymbol{C} \\ \boldsymbol{D} & \boldsymbol{0}\end{bmatrix}\right)=\begin{bmatrix}\boldsymbol{0} & \boldsymbol{C}(\boldsymbol{D}\boldsymbol{C})^{-1/2} \\ \boldsymbol{D}(\boldsymbol{C}\boldsymbol{D})^{-1/2} & \boldsymbol{0}\end{bmatrix}\end{equation}

which holds identically for any $\boldsymbol{C},\boldsymbol{D}$ of compatible shape. We leave the proof to the reader.

Summary

In this post, starting from the angle of solving the algebraic Riccati equation, we've collected several identities related to $\mcsgn$.

English translation of a post from 科学空间 | Scientific Spaces by 苏剑林. Original: https://kexue.fm/archives/11056
Translated automatically with claude-sonnet-5; all equations are reproduced verbatim from the source. Copyright remains with the original author.