Monday, March 27, 2017

Revisiting persistent homology

Here we revisit and expand on persistent homology, previously in the post "Persistent homology (an example)," 2016-05-19. All homology, except where noted, will be over a field $k$, and $X$ will be a topological space. Often a Morse-type function $f:X\to \R$ is introduced along with $X$, but we will try to take a more abstract view.

Definition: The space $X$ may be described as a filtered space with a filtration of sublevel sets
\[ \emptyset = X_0 \subseteq X_1\subseteq \cdots \subseteq X_m = X, \] whose persistence module is the (not necessarily exact) sequence
\[ 0 = H(X_0) \to H(X_1)\to\cdots \to H(X_m) = H(X) \] of homology groups of the filtration.

Remark: Every persistence module may be uniquely decomposed as a direct sum of sequences $0\to k\to \cdots\to k\to 0$, where every map is $\id$, except the first and last. The indices at which each sequence in the summand has its first and last non-zero map are called the birth and death of the homology class represented by the sequence.

In some cases a homology class may not die, so we consider the extended persistence module to make everything finite. We introduce the superlevel sets $X^i = X\setminus X_i$. If $f$ was our Morse-type function for $X$, with critical points $p_1<\cdots<p_m$, then for $t_0<p_1<t_1<\cdots<p_m<t_m$, we set $X_i = f^{-1}(-\infty,t_i]$ and $X^i = f^{-1}[t_i,\infty)$. The extended persistence module of $X$ is
\[
0 = H_k(X_0) \to H_k(X_1)\to\cdots \to H_k(X_m) \to H_k(X,X^m) \to H_k(X,X^{m-1}) \to \cdots \to H_k(X,X^0)=0.
\]
Definition: The persistence of a homology class in a persistence module conveys the idea of how long it is alive, presented by a persistence pair.
The persistence of all homology classes in a persistence module is often presented in a persistence diagram, the collection of persistence pairs $(i,j)$, or $(p_i,p_j)$ or $(f(p_i),f(p_j))$, as desired; or a linear barcode, the collection of persistence pairs $(i,j)$ as intervals $[i,j]$, ordered vertically. 

Example: Let $X = T^n=(S^1)^n$ be the $n$-torus. One filtration of $X$ is $X_0=\emptyset$ and $X_i = T^i$ for $1\leqslant i\leqslant n$. Note that $H_k(T^n,T^n\setminus X_n)=H_k(T^n)$ and $H_k(T^n,T^n\setminus X_0)=H_k(\emptyset)$. The first $n+1$ modules of the extended persistence module at level $k$ split into $\binom nk$ sequences, as $H_k(T^n) = \Z^{\binom nk}$. Geometric considerations allow $X^i = T^n\setminus T^i$ to be simplified in some cases. For instance, when $n=3$ and $k=0,1$ we have that $\widetilde H_k(T^3,T^3\setminus T^2)\cong \widetilde H_k(T^3,T^2) \cong \widetilde H_k(T^3/T^2)$, and knowing that $X^1=T^3\setminus T^1\simeq (S^1\vee S^1)\times S^1$, the relevant part of the long exact sequence for relative homology is

The two 1-cycles from $S^1\vee S^1\subset X^1$ map via $f$ to the same 1-cycle in $T^3$, hence $\text{im}(g)=\Z^2$. By exactness, $\text{ker}(g)=\Z^2$, and as $g$ is surjective, $A=\Z$.  Hence the extended persistence $k$-modules decompose as 
The persistence pairs are $(1,3)$ with multiplicity 2 and $(2,3)$, $(3,1)$ with multiplicity 1. The persistence diagrams and barcodes of the degree 0 and 1 homology classes are given below.
The diagonal $y=x$ is often given to indicate how short a lifespan a class has. Barcodes are usually not given for extended persistence diagrams, as length of a class (birth to death) is less important than position (above or below the diagonal).

Now we consider some generalizations of the ideas presented above.

Remark: A filtration can also be viewed as a diagram $X_0 \to X_1 \to \cdots \to X_m$, where each arrow is the inclusion map. We could generalize and consider a zigzag diagram, a sequence $X_0 \leftrightarrow X_1 \leftrightarrow \cdots \leftrightarrow X_m$, where $\leftrightarrow$ represents either $\to$ or $\leftarrow$. Homology can be applied and the resulting seuquence can also be uniquely decomposed into summands $k \leftrightarrow \cdots \leftrightarrow k$ where every arrow is the identity, giving zigzag persistent homology.

Remark: A filtration could also be viewed as a functor $F:\{0,\dots,m\}\to \text{Top}$, where $F(i)=X_i$ and $F(i\to j)$, for $j\>i$, is the composition of maps $X_i\to \cdots \to X_j$. Hence the degree-$k$ persistent homology of $X_i$ can be defined as the image of the maps $H_kF(i\to j)$, for all $j\>i$, and the functor $H_kF:\{0,\dots,m\}\to \text{Vec}$ may be viewed as the $k$th persistence module. This is a categorification of persistent homology.

Remark: A space $X$ can be filtered in several different ways. A multifiltration $X_\alpha$, for $\alpha$ a multi-index, is a collection of filtrations such that fixing all but one of the indices in $\alpha$ gives a (one-dimensional) filtration of $X$. The multidimensional persistence of $X_\alpha$ is a $|\alpha|$-dimensional grid of homology groups, with the barcode generalizing to the rank invariant, a map on the grid.

Another generalization, viewing filtrations as quivers, will not be discussed here, but rather presented as a separate post later.

References: Edelsbrunner and Morozov (Persistent homology: theory and practice), Carlsson, de Silva, and Morozov (Zigzag persistent homology and real-valued functions), Bubenik and Scott (Categorification of persistent homology), Carlsson and Zomorodian (The theory of multidimensional persistence)

Wednesday, March 15, 2017

Lengths of paths on projective varieties

This post contains calculations that continue on the ideas from the previous post "Fubini--Study metric," 2017-03-05. First we suppose that $\gamma$ lies on a curve $C\subset \P^2$, with the curve defined as the zero locus of a polynomial $P$. Taking the derivative of $P$ on $\C^2$ gives $P_{z_1}dz_1 + P_{z_2}dz_2=0$, which can be manipulated to give
\begin{align*}
dz_2 & = \frac{-P_{z_1}}{P_{z_2}}dz_1, & \frac\dy{\dy z_2} & = \frac{-P_{z_2}}{P_{z_1}} \frac\dy{\dy z_1},\\
d\overline{z_2} & = \frac{-\overline{P_{z_1}}}{\overline{P_{z_2}}}d\overline{z_1}, & \frac\dy{\dy \overline{z_2}} & = \frac{-\overline{P_{z_2}}}{\overline{P_{z_1}}} \frac\dy{\dy \overline{z_1}}.
\end{align*}
Using the above and an equation from the mentioned post, for $e = \frac\dy{\dy z_1} + \frac\dy{\dy \overline {z_1}} + \frac\dy{\dy z_2} + \frac\dy{\dy \overline{z_2}}$, we get
\begin{align*}
\frac{d \gamma}{dt} & = \left(\overline\gamma_1'-\frac{P_{z_2}}{P_{z_1}}\overline \gamma_2'\right)\frac\dy{\dy z_1} + \left(\gamma_1' - \frac{\overline{P_{z_2}}}{\overline{P_{z_1}}}\gamma_2'\right)\frac\dy{\dy \overline{z_1}} \\
\left(\sum_{k,\ell=1}^2\chi_{k\ell}(\gamma)dz_k\wedge d\overline{z_\ell}\right)(e,e) & = 1+|\gamma_2|^2 + \frac{\overline{P_{z_1}}}{\overline{P_{z_2}}} \overline \gamma_1\gamma_2 + \frac{P_{z_1}}{P_{z_2}}\gamma_1\overline\gamma_2 + \left|\frac{P_{z_1}}{P_{z_2}}\right|^2 \left(1+|\gamma_1|^2\right) = 1 +\left|\frac{P_{z_1}}{P_{z_2}}\right|^2 + \left|\frac{P_{z_1}}{P_{z_2}}\gamma_1+\gamma_2\right|^2, \\
(dz_1\wedge d\overline{z_1})\left(\frac{d\gamma}{dt},I\frac{d\gamma}{dt}\right) & = \det
\begin{bmatrix}
\overline\gamma_1'-\frac{P_{z_2}}{P_{z_1}}\overline \gamma_2' & i\left(\overline\gamma_1'-\frac{P_{z_2}}{P_{z_1}}\overline \gamma_2'\right) \\[5pt]
\gamma_1' - \frac{\overline{P_{z_2}}}{\overline{P_{z_1}}}\gamma_2' & -i\left(\gamma_1' - \frac{\overline{P_{z_2}}}{\overline{P_{z_1}}}\gamma_2'\right)
\end{bmatrix} = -2i \left|\gamma_1' - \frac{\overline{P_{z_2}}}{\overline{P_{z_1}}}\gamma_2'\right|^2.
\end{align*}
Hence
\[
g\left(\frac{d\gamma}{dt},\frac{d\gamma}{dt}\right) = \frac{\left(1 +\left|\frac{P_{z_1}}{P_{z_2}}\right|^2 + \left|\frac{P_{z_1}}{P_{z_2}}\gamma_1+\gamma_2\right|^2\right)\left|\gamma_1' - \frac{\overline{P_{z_2}}}{\overline{P_{z_1}}}\gamma_2'\right|^2}{\pi\left(1+|\gamma_1|^2+|\gamma_2|^2\right)^2}.
\]

Now we move to $\P^n$, and consider $X\subset \P^n$ a complete intersection of codimension $r$, or the zero set of polynomials $P_1=0,\dots,P_r=0$. Expressing some covectors in terms of others reduces the number of determinants we calculated above from $2n$ to $2(n-r)$. Then
\begin{align*}
P_{1,z_1}dz_1 + \cdots + P_{1,z_n}dz_n & = 0, & dz_n & = c_{n,1}dz_1 + \cdots + c_{n,n-r}dz_{n-r}, \\
& \ \ \vdots & & \ \ \vdots \\
P_{r,z_1}dz_1 + \cdots + P_{r,z_n}dz_n & = 0, & dz_{n-r+1} & = c_{n-r+1,1}dz_1 + \cdots + c_{n-r+1,n-r}dz_{n-r},
\end{align*}
for the $c_{i,j}$ some combinations of the $P_{k,z_\ell}$. By orthonormality of the basis vectors, and assuming that the $c_{i,j}$ are all non-zero, we find
\[
\frac\dy{\dy z_i} = \sum_{j=1}^{n-r} \frac1{(n-r)c_{i,j}}\frac\dy{\dy z_j},\hspace{2cm}
\frac\dy{\dy \overline{z_i}} = \sum_{j=1}^{n-r} \frac1{(n-r)\overline{c_{i,j}}}\frac\dy{\dy \overline{z_j}},
\]
for all integers $n-r<i\leqslant n$. This allows us to rewrite the path derivative as
\begin{align*}
\frac{d\gamma}{dt} & = \sum_{i=1}^n \overline \gamma_i'\frac\dy{\dy z_i} +\gamma_i'\frac\dy{\dy \overline{z_i}} \\
& = \sum_{i=1}^{n-r} \left(\overline \gamma_i'\frac\dy{\dy z_i} +\gamma_i'\frac\dy{\dy \overline{z_i}}\right) +\sum_{i=n-r+1}^n \left(\sum_{j=1}^{n-r} \frac{\overline \gamma_i'}{(n-r)c_{i,j}}\frac\dy{\dy z_j} + \sum_{j=1}^{n-r} \frac{\gamma_i'}{(n-r)\overline{c_{i,j}}}\frac\dy{\dy \overline{z_j}}\right) \\
& = \sum_{i=1}^{n-r}\left(\overline\gamma_i' + \sum_{j=n-r+1}^n \frac{\overline\gamma_j'}{(n-r)c_{j,i}}\right)\frac\dy{\dy z_i} + \left(\gamma_i'+\sum_{j=n-r+1}^n \frac{\gamma_j'}{(n-r)\overline{c_{j,i}}}\right)\frac\dy{\dy \overline{z_i}}.
\end{align*}

In the case of a curve in $\P^n$, when $r=n-1$, let $c_{1,1}=1$ and  $e = \frac\dy{\dy z_1} + \frac\dy{\dy \overline {z_1}} + \cdots + \frac\dy{\dy z_n} + \frac\dy{\dy \overline{z_n}}$ to get
\begin{align*}
 \frac{d\gamma}{dt} & = \left(\sum_{j=1}^n \frac{\overline\gamma_j'}{c_{j1}}\right)\frac\dy{\dy z_1} + \left(\sum_{j=1}^n \frac{\gamma_j'}{\overline{c_{j1}}}\right)\frac\dy{\dy \overline{z_1}},\\
 \left(\sum_{k,\ell=1}^n\chi_{k\ell}(\gamma)dz_k\wedge d\overline{z_\ell}\right)(e,e) & = \sum_{k,\ell=1}^n \left(1+\sum_{i=1}^n |\gamma_i|^2\right)\delta_{k\ell} - \overline{\gamma_kc_{\ell1}}\gamma_\ell c_{k1}, \\
(dz_1\wedge d\overline{z_1})\left(\frac{d\gamma}{dt},I\frac{d\gamma}{dt}\right) & = \det
\begin{bmatrix}
\sum_{j=1}^n \frac{\overline\gamma_j'}{c_{j1}} & i \sum_{j=1}^n \frac{\overline\gamma_j'}{c_{j1}} \\[5pt]
\sum_{j=1}^n \frac{\gamma_j'}{\overline{c_{j1}}} & -i\sum_{j=1}^n \frac{\gamma_j'}{\overline{c_{j1}}}
\end{bmatrix} = -2i \left|\sum_{j=1}^n \frac{\gamma_j'}{\overline{c_{j1}}}\right|^2.
\end{align*}
Hence
\[
g\left(\frac{d\gamma}{dt},\frac{d\gamma}{dt}\right) = \frac{\left(\sum_{k,\ell=1}^n \left(1+\sum_{i=1}^n |\gamma_i|^2\right)\delta_{k\ell} - \overline{\gamma_kc_{\ell1}}\gamma_\ell c_{k1}\right)\left|\sum_{j=1}^n \frac{\gamma_j'}{\overline{c_{j1}}}\right|^2}{\pi \left(1+\sum_{i=1}^n |\gamma_i|^2\right)^2}.
\]
The terms $\overline{\gamma_kc_{\ell1}}\gamma_\ell c_{k1}$ may be rearranged into terms $|\gamma_kc_{\ell1}-\gamma_\ell c_{k1}|^2$, but it does not provide any enlightening results, similarly to the rest of this post.

Sunday, March 12, 2017

Optimal sampling and arrangement on an n-sphere

The goal of this post is to create a "good" algorithm for sampling and arranging points on the $n$-sphere. We find the $\epsilon$-covering number of the $n$-sphere and arrange the points in a Hamiltonian path of small pairwise consecutive distance. This post relates to several previous posts:
Thanks to Professor Cheng Ouyang for a helpful discussion.
Although rejection sampling is a standard method to sample points uniformly on the $n$-sphere (sample points uniformly on the $(n+1)$-cube, check if the norm is less than or equal to 1, if it is, normalize the point to the $n$-sphere), this is not best for our scenario (the arranging part). A better suited approach is to take a parametrization $f$ from an $n$-cube into $\R^{n+1}$ of the unit $n$-sphere. We use
\[
\begin{array}{r c l}
f\ :\ [0,2\pi]^{n-1}\times[0,\pi) & \to & \R^{n+1}, \\
(\alpha_1,\dots,\alpha_n) & \mapsto & \big(\cos(\alpha_1), \\ && \sin(\alpha_1)\cos(\alpha_2),\\ && \vdots\\ && \sin(\alpha_1)\cdots\sin(\alpha_{n-1})\cos(\alpha_n), \\ && \sin(\alpha_1)\cdots\sin(\alpha_{n-1})\sin(\alpha_n)\big).
\end{array}
\]
Adapting the main Proposition from the "Sampling points" post, we have following proposition.

Proposition: The probability density function $g_n:[0,2\pi]^{n-1}\times[0,\pi] \to \R_{\geqslant0}$, defined as
\[
g_n(\alpha_1,\dots,\alpha_n)=\frac{\prod_{k=1}^{n-1}|\sin^{n-k}(\alpha_k)|}{2^{n-1}\pi\prod_{k=1}^{n-1}\int_0^\pi \sin^{n-k}(\alpha_k)\ d\alpha_k},
\]
is uniform on the natural embedding of the unit $n$-sphere $S^n$ in $\R^{n+1}$.

The denominator of $g_n$ does not seem to have closed form, though the ratios between consecutive terms are given by the denominators of $\Gamma(\frac{\ell+3}2)/\Gamma(\frac{\ell+2}2)$ and $\ell!!/(\ell+1)!!$, with appropriate powers of $\pi$. The first few terms of this sequence are
\[
4\pi,4\pi^2,\frac{32}3\pi^2,8\pi^3,\frac{256}{15}\pi^3,\frac{32}3\pi^4,\frac{2048}{105}\pi^4,\dots.
\]
Next, recall the $n$-surface of an $n$-sphere and $k$-volume of a $k$-ball are
\[
\text{surf}(n,r) = \frac{2\pi^{(n+1)/2}r^n}{\Gamma((n+1)/2)},\hspace{2cm}
\text{vol}(k,r) = \frac{\pi^{k/2}r^k}{\Gamma((k+2)/2)}.
\]
Adapting Proposition 3.2 of Niyogi, Smale and Weinberger, similarly to the "Reconstructing a manifold" post, we have the following proposition.

Proposition: A collection of $N$ points sampled uniformly from $S^n$ is $\epsilon$-dense in $S^n$ with certainty $1-\delta$, given
\[
N \geqslant \frac{\text{surf}(n,1)}{(1-\frac{\epsilon^2}{16})^{n/2}\text{vol}(n,\frac\epsilon2)}\log\left(\frac{\text{surf}(n,1)}{\delta(1-\frac{\epsilon^2}{64})^{n/2}\text{vol}(n,\frac\epsilon4)}\right).
\] Bauer and Polthier sample points "evenly" on the 2-hemisphere and then connect them with a winding path, which winds around the hemisphere 6 times. Generalizing this approach, suppose we wanted to have a path that wind around the $n$-sphere $\ell$ times and has a small distance between consecutive vertices of the path. The following algorithm describes one way of doing this.

Algorithm: SpherePathFinder
Input: Positive integers $n,\ell$ and real numbers $\epsilon,\delta\in (0,1)$
Output: A path on $S^n$ that winds around $\ell$ times, whose vertices are $\epsilon$-dense on $S^n$ with certainty $1-\delta$

Sample $\lceil N\rceil$ points on $[0,2\pi]^{n-1}\times[0,\pi]$ according to $g_n$ in a set $X$
Initiate an empty path $P=()$
for $k_n\in\{1,\dots,\ell\}$:
    for $k_{n-1}\in\{1,\dots,2\ell\}$:
       $\vdots$
           for $k_2\in\{1,\dots,2\ell\}$:
               Set $L=\{\alpha\in X\ :\ \alpha_n\in[(k_n-1)\frac\pi\ell,k_n\frac\pi\ell], \alpha_{n-t}\in[(k_{n-t}-1)\frac{2\pi}{2\ell},k_{n-t}\frac{2\pi}{2\ell}],1<t<n-1\}$
               Order $L$ by increasing values of $\alpha_1$
               Append $L$ to the end of $P$ and set $X=X\setminus L$
Return $P$

Since the sample space is $[0,2\pi]^{n-1}\times[0,\pi]$, finding the appropriate points in the nested for loop is very easy. We conclude with an experimental example with $n=2$, $\ell=12$, $\epsilon=.1$, and $\delta=.01$. We must sample at least 87 points, and we do so below.

Example: To demonstrate the results of the SpherePathFinder algorithm, we sample 100, 300, and 600 points on the 2-sphere. Only the paths are shown, which wind around 12 times. The range of distances $d$ between consecutive ordered points is also given, with an average $\widetilde d$.


As $N$ increases and the winding number stays the same, the path gets more and more jagged. To make the path smoother, we would need to increase the number of times the path winds around the sphere.

References: Bauer and Polthier (Detection of Planar Regions in Volume Data for Topology Optimization), Niyogi, Smale, and Weinberger (Finding the homology of submanifolds with high confidence from random samples), Sloane (OEIS A036069, A004731), Wikipedia (article "N-sphere")

Sunday, March 5, 2017

The Fubini-Study metric and length in projective space

In this post we inspect how the Fubini-Study metric works and compute an example. Professor Mihai Paun for helpful discussions. Recall that from projective space $\P^n$ there are natural maps
\[
[x_0:x_1:\cdots:x_n]\tov{\vp_i}\left(\frac{x_0}{x_i},\dots,\widehat{\frac{x_i}{x_i}},\dots,\frac{x_n}{x_i}\right)
\]
for $i=0,\dots,n$. The maps land in $\C^n$ with coordinates $(z_1,z_2,\dots,z_n)$. We use $\vp_0$ as the main map, and conflate notation for objects in $\P^n$ and in $\C^n$ under $\vp_0$. Most of this post deals with the $n=2$ case.


The metric


The metric used on $\P^n$ is the Fubini-Study metric. Directly from Section 3.1 of Huybrechts, for $n=2$ the associated differential 2-form and its image in $\C^2$ are
\begin{align*}
\omega & = \frac i{2\pi}\partial \bar\partial \log\left(1+\left|\frac{x_1}{x_0}\right|^2+\left|\frac{x_2}{x_0}\right|^2\right), \\
\vp_0(\omega) & = \frac i{2\pi}\partial \bar\partial \log\left(1+\left|z_1\right|^2+\left|z_2\right|^2\right) \\
& =  \underbrace{\frac{i}{2\pi (1+|z_1|^2+|z_2|^2)^2}}_{\lambda_2}\sum_{k,\ell=1}^2\underbrace{(1+|z_1|^2+|z_2|^2)\delta_{k\ell} -\overline{z_k}z_\ell}_{\chi_{k\ell}}dz_k\wedge d\overline{z_\ell}. \hspace{1cm} (1)
\end{align*}
A Hermitian metric on a complex manifold $X$ may be described as a 2-tensor $h=g-i\omega$, where $g$ is a Riemannian metric (also a 2-tensor) on the underlying real manifold and $\omega$ is a Kahler form, a 2-form. As in Lemma 3.3 of Voisin, the relationship between $g$ and $\omega$ is given by
\[
g(u,v)=\omega(u,Iv)=\omega(Iu,v), \hspace{1cm} (2)
\]
where $I:T_xX\to T_xX$ is a tangent space endomorphism defined by
\[
\begin{array}{r c l}
I|_{T^{1,0}_xX} & = & i\cdot \id, \\
\frac{\dy}{\dy z_i} & \mapsto & i\frac{\dy}{\dy z_i},
\end{array}
\hspace{1cm}
\begin{array}{r c l}
I|_{T^{0,1}_xX} & = & -i\cdot \id, \\
\frac{\dy}{\dy \overline{z_i}} & \mapsto & -i\frac{\dy}{\dy \overline{z_i}},
\end{array}
\]
as in Proposition 1.3.1 of Huybrechts.

An application


Let $\gamma:[0,1]\to \C^2$ be a path, described as $\gamma(t)=(\gamma_1(t),\gamma_2(t))$. The derivative of $\gamma$ with respect to $t$, in the basis $\frac{\dy}{\dy z_1}$, $\frac{\dy}{\dy \overline{z_1}}$, $\frac{\dy}{\dy z_2}$, $\frac{\dy}{\dy \overline{z_2}}$ is given by
\[
\frac{d\gamma_1}{dt} = \frac{du_1}{dt}\frac\dy{\dy x_1} + i\frac{dv_1}{dt}\frac\dy{\dy y_1} = \frac{du_1}{dt}\left(\frac\dy{\dy \overline{z_1}}+\frac\dy{\dy z_1}\right) + i\frac{dv_1}{dt}\left(\frac\dy{\dy \overline{z_1}} -\frac{\dy}{\dy z_1}\right) = \underbrace{\left(\frac{du_1}{dt} + i\frac{dv_1}{dt}\right)}_{\gamma_1'}\frac\dy{\dy \overline {z_1}} + \underbrace{\left(\frac{du_1}{dt}-i\frac{dv_1}{dt}\right)}_{\overline \gamma_1'}\frac\dy{\dy z_1},\]
and analogously for $\gamma_2$. Hence
\[
\frac{d\gamma}{dt} =
\overline \gamma_1'\frac\dy{\dy z_1} + \gamma_1'\frac\dy{\dy \overline{z_1}} + \overline \gamma_2' \frac\dy{\dy z_2} + \gamma_2' \frac{\dy}{\dy \overline{z_2}}. \hspace{1cm} (3)
\]
The length of $\gamma$ is
\[
\int_0^1\sqrt{g\left(\frac{d\gamma}{dt},\frac{d\gamma}{dt}\right)}\ dt = \int_0^1\sqrt{\omega\left(\frac{d\gamma}{dt},I\frac{d\gamma}{dt}\right)}\ dt,
\]
using equation (2). Recall that the pairing of vectors with covectors is given by\[
\left(d\alpha_1\wedge \cdots \wedge d\alpha_n\right)\left(\frac\dy{\dy \beta_1},\dots,\frac\dy{\dy \beta_n}\right) = \det\begin{bmatrix}
d\alpha_1\frac\dy{\dy \beta_1} & d\alpha_1\frac{\dy}{\dy \beta_2} & \cdots & d\alpha_1\frac\dy{\dy \beta_n} \\
d\alpha_2\frac\dy{\dy \beta_1} & d\alpha_2\frac{\dy}{\dy \beta_2} & \cdots & d\alpha_2\frac\dy{\dy \beta_n} \\
\vdots & \vdots & \ddots & \vdots \\
d\alpha_n\frac\dy{\dy \beta_1} & d\alpha_n\frac{\dy}{\dy \beta_2} & \cdots & d\alpha_n\frac\dy{\dy \beta_n}
\end{bmatrix}
 \ \ = \ \
\det\left(d\alpha_i\frac\dy{\dy \beta_j}\right),
\]
for $\alpha_i,\beta_j$ a basis of the underlying real manifold (as in the previous post "Vector fields," 2016-10-10). The components of the vector (3) may be viewed as given in directions $z_1,\overline{z_1}, z_2,\overline{z_2}$, respectively, which also indicates how the coefficient functions $\chi_{k\ell}$ act on (3). Apply the definition of $\omega$ from equation (1), and note that we are always at the tangent space to the point $\gamma(t)=(\gamma_1(t),\gamma_2(t))$, to get that
\begin{align*}
& \omega\left(\frac{d \gamma}{dt},I\frac{d\gamma}{dt}\right) \\
& = \lambda_2(\gamma(t)) \sum_{k,\ell=1}^2 \chi_{k\ell}(\gamma(t)) dz_k\wedge d\overline{z_\ell}\left(\overline \gamma_1'\frac\dy{\dy z_1} + \gamma_1'\frac\dy{\dy \overline{z_1}} + \overline \gamma_2' \frac\dy{\dy z_2} + \gamma_2' \frac{\dy}{\dy \overline{z_2}}, i\overline \gamma_1'\frac\dy{\dy z_1} - i\gamma_1'\frac\dy{\dy \overline{z_1}} + i\overline \gamma_2' \frac\dy{\dy z_2} -i\gamma_2' \frac{\dy}{\dy \overline{z_2}}\right) \\
& = \lambda_2(\gamma(t)) \sum_{k,\ell=1}^2 \chi_{k\ell}(\gamma(t))\det
\begin{bmatrix}
\overline \gamma_k'(t) & i\overline \gamma_k'(t) \\[5pt] \gamma_\ell'(t) & -i\gamma_\ell'(t)
\end{bmatrix} \\
& = \frac{(1+|\gamma_2(t)|^2)|\gamma_1'(t)|^2 - \overline\gamma_1(t)\gamma_2(t)\overline\gamma_1'(t)\gamma_2'(t) - \overline\gamma_2(t)\gamma_1(t)\overline \gamma_2'(t)\gamma_1'(t) + (1+|\gamma_1(t)|^2) |\gamma_2'(t)|^2}{\pi\left(1+\left|\gamma_1(t)\right|^2+\left|\gamma_2(t)\right|^2\right)^2}.\end{align*}
Unfortunately this expression does not simplify too much. In $\P^n$, with $\gamma = (\gamma_1,\dots,\gamma_n):[0,1]\to \C^n$, we have that
\[
g\left(\frac{d \gamma}{dt},\frac{d\gamma}{dt}\right) = \lambda_n(\gamma(t)) \sum_{k,\ell=1}^n \chi_{k\ell}(\gamma(t))\det
\begin{bmatrix}
\overline \gamma_k'(t) & i\overline \gamma_k'(t) \\[5pt] \gamma_\ell'(t) & -i\gamma_\ell'(t)
\end{bmatrix}.
\]

An example


Here we compute the distance between two points in $\P^2$. Let $\gamma$ be the straight line segment connecting $p=[p_0:p_1:p_2]$ and $q=[q_0:q_1:q_2]$. The word "straight" is used loosely, and means the segment may be parametrized as
\[
\gamma(t) = [(1-t)p_0+tq_0:(1-t)p_1+tq_1:(1-t)p_2+tq_2],
\]
so $\gamma(0)=p$ and $\gamma(1)=q$. The image of $\gamma$ under $\vp_0$ and its derivative are given by
\[
\vp_0(\gamma(t)) = \left(\frac{(1-t)p_1+tq_1}{(1-t)p_0+tq_0}, \frac{(1-t)p_2+tq_2}{(1-t)p_0+tq_0}\right) = (\gamma_1,\gamma_2),
\hspace{2cm}
\gamma_i' = \frac{q_ip_0-q_0p_i}{((1-t)p_0+tq_0)^2}.
\]
If, for example, $p=[1:1:0]$ and $q=[1:0:1]$, then
\[
\text{length}(\gamma) = \frac{3}{4\pi}\int_0^1\frac1{(t^2-t+1)^2}\ dt = \frac{9+2\pi\sqrt 3}{18\pi}.
\]

A further goal is to consider the path $\gamma$ as lying on a projective variety, beginning with a complete intersection. This would allow some of the $dz_i$ to be expressed in terms of other $dz_j$.

References: Huybrechts (Complex geometry, Section 3.1), Voisin (Hodge theory and complex algebraic geometry 1, Chapter 3.1), Wells (Differential analysis on complex manifolds, Chapter V.4)

Friday, February 24, 2017

Serre duality on schemes

 Lecture topic

This post goes through the statement and proof of Serre duality for arbitrary projective schemes, as presented in Chapter III.7 of Hartshorne. Only the necessary tools and definitions to prove the statement are introduced.

Recall a scheme is a topological space $X$ and a sheaf of rings $\mathcal O_X$ such that for every open set $U\subset X$, $\mathcal O_X(U)\cong \Spec(R)$ for some ring $R$. Its dimension is its dimension as a topological space. A projective scheme is a scheme where $X\subset \P^n$. A sheaf (or scheme) over a scheme $X$ is a sheaf (or scheme) $Y$ and a morphism $Y\to X$. Recall also the sheafification $\widetilde {\mathcal F}$ of a presheaf $\mathcal F$.

Definition 1: Let $\mathcal F$ be a sheaf over a projective scheme $X$. Then $\mathcal F$ is
  • proper if it is the image of a proper morphism (separated, finite type, universally closed),
  • quasi-coherent if there exists a cover $\{U_i=\Spec(A_i)\}$ of $X$ such that $\mathcal F|_{U_i} = \widetilde{M_i}$ for some $A_i$-module $M_i$,
  • coherent if it is quasi-coherent and each $M_i$ is finitely-generated as an $A_i$-module,
  • locally free if for every $x\in X$, there exists $U\owns x$ open such that $\mathcal F|_U = \bigoplus_{i\in I} \mathcal O_X|_U$,
  • very ample if there is an immersion $i:X\to \P^n$ for some $n$ such that $i^*\mathcal O(1) \cong \mathcal F$.
Often we say $\mathcal F$ is very ample if it has "enough sections," as $\P^n$ has many sections.

Remark 1: Recall some basic definitions of the $\Ext$ functor. Let $\mathcal F,\mathcal G$ be sheaves of $\mathcal O_X$-modules, and $\mathcal L$ a locally free sheaf of finite rank. Then:
  1. $\Ext^i(\mathcal O_X,\mathcal F) \cong H^i(X,\mathcal F)$ for all $i\>0$ (Proposition III.6.3)
  2. $\Ext^i(\mathcal F\otimes \mathcal L,\mathcal G) \cong \Ext^i(F,\mathcal L^\vee\otimes \mathcal G)$ (Proposition III.6.7)
  3. $\Ext^i_{\mathcal O_X}(\mathcal F_x,\mathcal G_x) \cong \mathcal Ext (\mathcal F,\mathcal G)_x $ (Proposition III.6.8)
  4. $\Ext^i(\mathcal F,\mathcal G(q)) \cong \Gamma(X,\mathcal Ext^i(\mathcal F,\mathcal G(q))$ (Proposition III.6.9)
  5. $\mathcal Ext^i(\mathcal F\otimes \mathcal L,\mathcal G) \cong \mathcal Ext^i(F,\mathcal L^\vee\otimes \mathcal G) \cong \mathcal Ext^i(\mathcal F,\mathcal G)\otimes \mathcal L^\vee$
  6. $\mathcal Ext^0(\mathcal O_X,\mathcal F) \cong \mathcal F$
  7. $\mathcal Ext^i(\mathcal O_X,\mathcal F) \cong 0$ for all $i>0$
Recall that a local ring of a scheme $X$ is $\mathcal O_{X,x}$ for $x\in X$. It is equivalently a ring with a unique maximal left or right ideal. A regular local ring is a local ring $R$ whose maximal ideal is generated by $\dim(R)$ elements.

Preliminary definitions and lemmas


Let $A,B$ be abelian categories (recall this means kernels and cokernels exist).

Definition 2: A $\delta$-functor between $A$ and $B$ is a collection of functors $T^i:A\to B$ that generalize derived functors, in the sense that $R^i\mathcal F = T^i$. A $\delta$-functor is universal if for any other $\delta$-functor $U$, there is a natural transformation $f:T^0\to U^0$ that induces a unique collection of morphisms $f^{i\geqslant 0}:T^i\to U^i$ that extend $f$.

See Weibel for a more thorough definition (and Grothendieck for the original setting). These functors may be covariant or contravariant, homological or cohomological. Note that $\delta$-functors are unique up to isomorphism.

Definition 3: Let $F:A\to B$ be a functor. $F$ is effaceable if for every $X\in A$ there exists a monomorphism $u\in \Hom_A(X,Y)$ such that $F(u)=0$. Similarly, $F$ is coeffaceable if for every $X\in A$ there exists an epimorphism $v\in \Hom_A(Y,X)$ such that $F(v)=0$.

Lemma 1: If a covariant (or contravariant) cohomological $\delta$-functor is effaceable for every $i>0$, then it is universal. Similarly, if a covariant (or contravariant) homological $\delta$-functor is coeffaceable for every $i>0$, then it is universal.

This appears as Proposition II.2.2.1 in Grothendieck and Exercise 2.4.5 in Weibel. Now let $\mathcal F$ be a sheaf over a projective scheme $X$.
Lemma 2: (Theorem III.5.2 in Hartshorne) If $\mathcal F$ is coherent, there is $q\gg 0$ such that $H^i(X,\mathcal F(q))=0$ all $i>0$.

Definition 4: The dualizing sheaf of $X$ is a coherent sheaf $\omega_X^\circ$ and a trace map $t:H^n(X,\omega_X^\circ) \to k$ such that the isomorphism $\Hom(\mathcal F,\omega_X^\circ)\to H^n(X,\mathcal F)^\vee$ is induced by the natural pairing
\[\Hom(\mathcal F,\omega_X^\circ)\times H^n(X,\mathcal F) \to H^n(X,\omega_X^\circ)\]
composed with $t$.

Lemma 3:
(Corollary II.5.18 in Hartshorne) If $\mathcal F$ is coherent, then it is a quotient of $\bigoplus_{i=1}^N \mathcal O_X(-q)$ for $q\gg 0$.

Next we recall some ring theory. Let $A$ be a ring and $M$ an $A$-module.

Definition 5: A sequence $a_1,\dots,a_n\in M$ is $M$-regular if $a_i$ is not a zero divisor of $M/(a_1,\dots,a_{i-1})M$ and $M\neq (a_1,\dots,a_i)M$ for all $i$. The depth of $M$ is the maximal length of an $M$-regular sequence of elements in some maximal ideal $\mathfrak m\leqslant M$. A local Noetherian ring is Cohen-Macaulay if $\text{depth}(A)=\dim(A)$, where dimension is Krull dimension (maximal length of prime ideal chains). A scheme $X$ is Cohen-Macaulay if every point $x\in X$ has a neighborhood $U$ such that the local ring $\mathcal O_X(U)$ is Cohen--Macaulay.

Lemma 4: Let $A$ be a regular local ring of dimension $n$ and $M,N$ be $A$-modules. Then:
  1. $\text{pd}(M)\leqslant n$ iff $\Ext^i(M,N)=0$ for all $i>n$ (Proposition III.6.10)
  2. $\text{pd}(M)+\text{depth}(M)=n$ if $M$ is f.g. (Proposition III.6.12A)

Main theorem and proof


First we state the duality theorem for $X=\P^n$, without proof. Let $\omega_X$ be the canonical sheaf of $X$.

Theorem 1: (Theorem III.7.1 in Hartshorne) For $\mathcal F$ coherent over $\P^n$, for $i\geqslant 0$ there are natural isomorphisms
\[ \Hom(\mathcal F,\omega_X) \cong H^n(X,\mathcal F)^\vee, \hspace{2cm} \Ext^i(\mathcal F,\omega) \cong H^{n-i}(X,\mathcal F)^\vee.\]

Now we give the duality theorem for an arbitrary projective scheme, going through the proof as in Hartshorne.

Theorem 2: (Theorem III.7.6 in Hartshorne) Let $X$ be a projective scheme of dimension $n$ such that $\mathcal O(1)$ is very ample. For $\mathcal F$ coherent,
\begin{align*}
\Ext^i(\mathcal F, \omega_X^\circ) \cong H^{n-i}(X,\mathcal F)^\vee &\ \iff\ H^i(X,\mathcal F(-q))=0 \text{ for all $\mathcal F$ locally free, }i<n,q\gg0,\\
&\ \iff\ X\text{ is CM and equidimensional.}
\end{align*}

Proof: Natural maps $\Ext^i(\mathcal F,\omega^\circ_X)\to H^{n-i}(X,\mathcal F)^\vee$ exist, as $\Ext^i(-,\omega_X^\circ):\text{Coh}(X)\to \text{Mod}$ is a coeffaceable $\delta$-functor for every $i>0$, hence universal by Lemma 1. Indeed, by Lemma 3, we have a surjection
\[\underbrace{\bigoplus_{j=1}^N \mathcal O_X(-q)}_{\mathcal E}\tov u \mathcal F\to 0,\]
for which
\[\Ext^i(\mathcal E,\omega_X^\circ) = \bigoplus_{j=1}^N \Ext^i(\mathcal O_X(-q),\omega_X^\circ)= \bigoplus_{j=1}^N \Ext^i(\mathcal O_X,\omega_X^\circ (q)) = 0\]
for $i>0$. The first equality was distributing $\Ext^i$ over the sum and the second was by applying Remark 1.2. Hence $\Ext^i(-,\omega_X^\circ)(u)=0$ for $i>0$, so the functor is coeffeaceable for $i>0$, and so universal. By Definition 2 there exist maps generalizing the map $\Ext^0$ from Definition 4.

First iff $\Leftarrow$: Since universal $\delta$-functors are unique (up to isomorphism), we show $H^{n-i}(X,-)^\vee:\text{Coh}(X)\to \text{Mod}$ is also universal contravariant, which follows as it is coeffaceable for $i>0$. Using the same sequence and sheaf as in the equation above, we have that
\[H^{n-i}(X,\mathcal E) = \bigoplus_{j=1}^N H^{n-i}(X,\mathcal O_X(-q)) = 0\]
whenever $n-i<n$ by hypothesis, or equivalently, when $i>0$. The dual module is then also zero for $i>0$, so we are done.

First iff $\Rightarrow$: Assume the hypothesis with index $n-i$ and a locally free sheaf $\mathcal F(-q)$ for $q\gg 0$, for which
\begin{align*}
H^i(X,\mathcal F(-q))^\vee & \cong \Ext^{n-i}(\mathcal F(-q),\omega_X^\circ) & (\text{hypothesis}) \\
& \cong \Ext^{n-i}(\mathcal O_X,\mathcal F^\vee \otimes \mathcal O_X(q) \otimes\omega_X^\circ) & (\text{Remark 1.2}) \\
& \cong H^{n-i}(X,(\mathcal F^\vee \otimes\omega_X^\circ)\otimes \mathcal O_X(q)). & (\text{Remark 1.1})
\end{align*}
Tensoring with $\mathcal O_X(q)$ is twisting by $q$, and Lemma 2 says that $H^{n-i}(X,\mathcal G(q))=0$ for $\mathcal G$ coherent, for all $n-i>0$, for $q$ large enough. So for $i<n$ and $q$ large enough $H^i(X,\mathcal F(-q))^\vee=0$, and so its dual, the original cohomology group, is also trivial.

Second iff $\Leftarrow$: Embed $X\hookrightarrow \P^N$. As $X$ is Cohen--Macaulay and equidimensional of dimension $n$, for $\mathcal F$ locally free on $X$, a stalk $\mathcal F_x$ of a closed point $x\in X$ has depth $n$. Also, $\mathcal F_x\subset \mathcal O_{\P^N,x}$, and $\mathcal O_{\P^n,x}$ is regular as $\P^N$ is smooth over $k$. By Lemma 4.2, we have that
\[\text{pd}(\mathcal F_x) +n \leqslant \text{pd}(\mathcal O_{\P^N,x})+n=N, \]
so Lemma 4.1 and Remark 1.3 gives us that, for $i>N-n$,
\[\Ext^i(\mathcal F_x,-)=0
\ \ \implies\ \
\mathcal Ext^i(\mathcal F_x,-)=0
\ \ \implies\ \
\mathcal Ext^i(\mathcal F,-)=0.\]
Applying Theorem 1, Remark 1.4, and letting the functor $\mathcal Ext^i(\mathcal F,-)$ act on $\omega_{\P^N}(q)$, we have
\[H^i(X,\mathcal F(-q))^\vee \cong \Ext_{\P^n}^{N-i}(\mathcal F,\omega_{\P^N}(q)) \cong \Gamma(\P^N,\mathcal Ext_{\P^N}^{N-i}(\mathcal F, \omega_{\P^n}(q))) \cong \Gamma(\P^N, 0) = 0\]
for $q\gg0$ and $N-i>N-n$, or $i<n$. Since the dual is trivial, the cohomology group $H^i(X,\mathcal F(-q))$ is also trivial.

Second iff $\Rightarrow$: Omitted (techniques are similar to previous step, but use many others not used elsewhere). $\square$

Addendum


In certain cases, Serre duality holds for the canonical sheaf instead of the dualizing sheaf.

Proposition 1: For $X$ a smooth projective variety over $k=\overline k$, $\omega_X^\circ \cong \omega_X$.

References: Grothendieck (Tohoku paper), Hartshorne (Algebraic Geometry, Section III.7), Weibel (An introduction to homological algebra, Section 2.1), Matsumura (Commutative algebra, Chapter 6)

Sunday, February 12, 2017

Generalizing planar detection to k-plane detection

In this post the planar detection algorithm in $\R^3$ of Bauer and Polthier in Detection of Planar Regions in Volume Data for Topology Optimization is generalized to detect $k$-planes with largest density in $\R^n$. Let $\Omega\subset \R^n$ be the compact support of a piecewise-constant probability density function $\rho:\R^n\to \R_{\geqslant 0}$.

Definition: Let $(G,\rho)$ be a grid, where $G \subset \lambda \Z^n + c \subset \R^n$ is a lattice in $\Omega$.  A cell $x$ of the grid is $B_\infty(x,\lambda/2) = \{y\in \R^n\ :\ ||x-y||_\infty\leqslant\lambda/2\}$, for $x\in G$. Every cell is assigned a value
\[
\int_{B_\infty(x,\lambda/2)}\rho\ dx,
\]
called the mass of the cell, which may be though of as a type of Radon transform of $\rho$.

Assuming that $k$ is a global variable, running $Recursive(G,w,k)$ will give the desired result. This algorithm is the naive generalization of Bauer and Polthier, and suffers from calculating mass along the same $k$-plane several times, whenever $k<n-1$ (as any $k$-plane does not lie in a unique $(k+1)$-plane).

Algorithm: $k$PlaneFinder
$Recursive(G,w,k)$:
Input: A grid $(G,\rho)$, a width $w$ of fattened $k$-planes, the current plane dimension $k\leqslant k'<n$
Output: A $k$-planar connected component covering most mass in $G$

discretize the unit $(k'-1)$-hemisphere in an appropriate manner
order the vertices by a Hamiltonian path
for each vertex $\textbf{n}$:
    sort the grid cells in direction $\textbf{n}$
    discretize the range in direction $\textbf{n}$ equidistantly
    for each $k'$-plane $(\textbf{n},d)$:
        collect the cells closer than $w$ to the $k'$-plane into a graph $G'$
        if $k'\neq k$:
            run $Recursive(G',w,k'-1)$
        else:
            compute the connected component having the most mass in $G'$
return the connected $k$-component having most mass (and the corresponding $k$-plane)


Measuring along connected components of a $k$-plane works the same way as in the original version, as the gird on $\R^n$ similarly induces a connectivity graph.

Remark: Bauer and Polthier cite Kantaforoush and Shahshahani in evenly sampling points on the unit 2-sphere, but it is not clear how their method (using the inscribed icosahedron) generalizes. Another method would be uniformly sampling random points on $S^{k-1}$ and take all on one hemisphere. A Hamiltonian path could then be taken from an arbitrary point and then using the greedy algorithm (with respect to Euclidean distance) to find consecutive vertices (to keep down the time of consecutive sorting operations).

Recall the Grassmannian $Gr(n,k)$ of all $k$-planes in $\R^n$ through the origin, a compact manifold of dimension $k(n-k)$. Note that any $k$-plane $P\subset \R^n$ is a translation of an element $Q\in Gr(n,k)$ by an element of $Q^\perp$ (we conflate notation for $Q$ and its natural embedding in $\R^n$).

Remark:
$Gr(n,k)$ is parametrizable, so by choosing directions in the unit $(n-k)$-hemisphere, the process of choosing $k$-planes in the algorithm may be completely parametrized. The quick sorting of points that was available in Bauer and Polthier's $n=3,k=2$ case may be replaced by an iterated restriction of the original data set through a complete flag $P\subset \cdots \subset \R^n$.

References: Bauer and Polthier (Detection of Planar Regions in Volume Data for Topology Optimization), Katanforoush and Shahshahani (Distributing points on the Sphere 1)

Tuesday, January 24, 2017

Defining and implementing spheres from sampled points

Let $p_1,\dots,p_{n+1}\in \R^n$ be points with coordinates $p_i = (p_{i,1},\dots,p_{i,n})$, and $\R^n$ with coordinates $x_1,\dots,x_n$. It is clear that if theses $n+1$ points are in general position, then they define a unique $(n-1)$-sphere in $\R^n$, on which they all lie.

Guess: Every point $(x_1,\dots,x_n)$ on the unique $(n-1)$-sphere in $\R^n$ defined by $p_1,\dots,p_{n+1}$ satisfies
\begin{equation}
\det\begin{bmatrix}
\sum_{i=1}^n x_i^2 & x_1 & x_2 & \cdots & x_n & 1 \\
\sum_{i=1}^n p_{1,i}^2 & p_{1,1} & p_{1,2} & \cdots & p_{1,n} & 1 \\
\sum_{i=1}^n p_{2,i}^2 & p_{2,1} & p_{2,2} & \cdots & p_{2,n} & 1 \\
\vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\
\sum_{i=1}^n p_{n+1,i}^2 & p_{n+1,1} & p_{n+1,2} & \cdots & p_{n+1,n} & 1 \\
\end{bmatrix} = 0.
\end{equation}
Call this equation (1).

This guess is made based on the 2-sphere version presented in Zwillinger. It is immediate that every point $p_i$ satisfies this equation, as then the matrix has two rows with identical entries. From this guess, we may conclude the following.

Proposition: The radius of the $(n-1)$-sphere defined by $p_1,\dots,p_{n+1}$ in $\R^n$ is
\[
\sqrt{\sum_{j=2}^{n+1}\frac{A_{1,j}^2}{4A_{1,1}^2} +(-1)^n\frac{A_{1,n+2}}{A_{1,1}}},
\]
for $A_{i,j}$ the $(i,j)$-minor of the matrix in equation (1). Call this expression (2).

Proof: This follows by comparing two equations. Assume that these points define a sphere of radius $r$ centered at $(a_1,\dots,a_n)$. Then points on it satisfy
\[
r^2 = (x_1-a_1)^2+\cdots+(x_n-a_n)^2 = x_1^2-2a_1x_1+a_1^2+\cdots + x_n^2-2a_nx_n + a_n^2.
\]
Equation (1) may be expanded out along the first row as
\[
\sum_{i=1}^n x_i^2 A_{1,1} - x_1A_{1,2}+\cdots + (-1)^nx_nA_{1,n+1} + (-1)^{n+1}A_{1,n+2} =0,
\]
where none of the $A_{i,j}$ are in any of the $x_i$. Dividing by the leading factor and comparing coefficients of these two equations, we find
\begin{align*}
A_{1,1} & = 1, \\
-A_{1,2}/A_{1,1} & = -2a_1, \\
& \ \ \vdots \\
(-1)^nA_{1,n+1}/A_{1,1} & = -2a_n, \\
(-1)^{n+1}A_{1,n+2}/A_{1,1} &  = a_1^2+\cdots + a_{n^2} - r^2.
\end{align*}
The given expression follows by solving for $r$. $\square$

Since any collection of $k+1$ points in general position in $\R^n$ define a $k$-plane, it is natural to ask what would be the radius of the $(k-1)$-sphere in that $k$-plane defined by those $k+1$ points. One approach to answer this is to define a new coordinate system on $\R^n$ with the first $k$ vectors spanning the given $k$-plane, restrict to the first $k$-coordinates, and apply the proposition above. More precisely, subtract the first vector from the other $k$ vectors to define a new "origin," preform the Gram--Schmidt orthogonalization process on these shifted vectors, then take the QR-decomposition of this matrix of vectors whose inverse is the map from the standard basis to the new basis. In Sage code, this may be implemented as below.

# Returns the (i,j)-minor (determinant when ith row, jth col removed) of input matrix mat
def minor(mat,i,j):
    return mat.delete_rows([i]).delete_columns([j]).det()
    
# Returns the radius of an (n-1)-sphere defined by n+1 points in R^n
def sphere_radius(L,field=CDF):
    n = len(L)-1
    M1 = [[0]*(n+2)]
    for pt in L:
        tempL = [pt*pt]
        for pos in range(n):
            tempL.append(pt[pos])
        tempL.append(1)
        M1.append(tempL)
    M2 = matrix(field,n+2,n+2,M1)
    return sqrt(reduce(lambda x,y: x+y, map(lambda z: minor(M2,0,z-1)**2/(4*minor(M2,0,0)**2),
        range(1,n+2)))+(-1)**n*minor(M2,0,n+1)/minor(M2,0,0))
    
# Returns the radius of a (k-1)-sphere defined by k+1 points in R^n
def sphere_radius_general(L,field=CDF):
    k = len(L)-1
    n = len(L[0])
    L1 = []
    for vec in L[1:]:
        L1.append(vec-L[0])    
    M = matrix(field,k,n,L1)
    Q,R = M.transpose().QR()
    L2 = [vector(field,[0]*k)]
    Qinv = Q.inverse()
    for vec in L1:
        L2.append((Qinv*vec)[:k-n])
    return sphere_radius(L2)

Now in Mathematica.

(*Returns the (i,j)-minor of a an input matrix mat*)
minor[mat_,i_,j_] := Map[Reverse,Minors[mat],{0,1}][[i]][[j]]

(*Returns the radius of an (n-1)-sphere defined by n+1 points in R^n*)
SphereRadius[L_] := Module[{n, M},
    n = Length[L]-1;
    M = Join[{Array[0#&,n+2]},Table[Join[{Sum[L[[j]][[l]]^2,{l,1,n}]},L[[j]],{1}],{j,1,n+1}]];
    Sqrt[Sum[minor[M,1,j]^2/(4*minor[M,1,1]^2),{j,2,n+1}]+(-1)^n*minor[M,1,n+2]/minor[M,1,1]]]
    
(*Returns the radius of a (k-1)-sphere defined by k+1 points in R^n*)
SphereRadiusGeneral[L_] := Module[{n,k,Lv,L1,q,qq,qinv},
   n = Length[L[[1]]];
   k = Length[L]-1;
   Lv = Table[Unique["q"],{n}];
   L1 = L[[2;;]]-Table[L[[1]],{l,1,k}];
   q = QRDecomposition[Transpose[L1]][[1]];
   qq = Join[q,{Lv}]/.Solve[{q.Lv==0,Total[#^2&/@Lv]==1},Lv][[1]];
   qinv = Inverse[Transpose[qq]];
   SphereRadius[Join[{Array[0#&,k]},#[[;;-(n-k)-1]]&/@(qinv.#&/@L1)]]]
The variable L is a list of $(n+1)$-dimensional vectors of appropriate length. Both methods skip creating the first line of the matrix in (1), since it does not appear in the expression (2). The method in Sage is probably faster in practice, but less accurate. For example:
Note that the exact square root result is approximately $10.9682$, off by around $0.01$ from the Sage result.

References: Zwillinger (CRC Standard Mathematical Tables and Formulae, Section 4.8.1)