This jupyter notebook contains the code and numerical illustrations associated with our paper Flagfolds https://arxiv.org/abs/2305.10583 B. Buet, X. Pennec.

This code is distributed under the Licence CC-BY-NC

Let $n \in \mathbb{N}$, $n \geq 2$. We introduce the notations: $\mathring{\Delta}(n) = \{ \mu = (\mu_1, \ldots, \mu_n) \in (0,1)^n \: : \: \mu_1 + \ldots + \mu_n = 1 \}$ and

$$ {\rm O}(n) = \{ U \in {\rm M}_n(\mathbb{R}) \: : \: U^T U = I_n \} \quad \text{and} \quad {\rm Sym}(n) = \{ A \in {\rm M}_n(\mathbb{R}) \: : \: A^T = A \} \quad \text{and} \quad {\rm Skew}(n) = \{ B \in {\rm M}_n(\mathbb{R}) \: : \: B^T = - B \} .$$

Visualization with ellipsoids

We will represent $(\mu, U) \in \mathring{\Delta}(n) \times {\rm O}(n)$ by an ellipsoïd $\mathcal{Ell}(\mu,U)$ as follows. For $k \in \{1, \ldots, n\}$, we define $\lambda_k = \sum_{j=k}^n \frac{\mu_j}{j}$ and we denote by $u_k$ the $k^{th}$ column of $U$. Then, $\mathcal{Ell}(\mu,U)$ is the ellipsoïd of axes directed by $u_1, \ldots, u_n$ with semi-axis lengths $\sqrt{n \lambda_1}, \ldots, \sqrt{n \lambda_n}$.

When representing several ellipsoïds, we translate theirs centers so that they do not overlap.

Numerical Scheme

We refer to Section 5 of the Arxiv version.

We are given $f : [0,1]^n \rightarrow [0, +\infty[$ satisfying $f(\mu) = 0$ if and only if $\mu = 0$ and we assume that $f$ is ${\rm C}^2$ in $[0,1]^n \setminus \{0\}$.

Given $1 \leq i < j \leq n$, we denote $\mu_{i \to j} = (0, \ldots, 0, \mu_i, \mu_{i+1}, \ldots,\mu_{j-1}, \mu_j, 0, \ldots, 0) \in [0,1]^n$.

We are interested in $(\mu, U) : I \subset \mathbb{R} \rightarrow \mathring{\Delta}(n) \times {\rm O}(n)$ solutions of the following differential equations:

$$ U^\prime = U B \quad \text{with } B = (b_{ij})_{ij} \in {\rm Skew(n)} \text{ and for } i<j, \, b_{ij} = \frac{1}{f(\mu_{i \to j})^2} \left( U^T U(0) C(0) U(0)^T U \right)_{ij} \quad \text{and} \quad C(0) = \left( f(\mu_{i \to j}(0))^2 b_{ij}(0) \right)_{ij} \: . $$

and $$ \mu_k^{\prime\prime} = \frac{1}{n}\sum_{\substack{l = 1 \\ l \neq k}}^n \sum_{1 \leq i \leq l < j \leq n} f(\mu_{i \to j}) \: \partial_l f (\mu_{i \to j}) b_{ij}^2 - \frac{n-1}{n} \sum_{1 \leq i \leq k < j \leq n} f(\mu_{i \to j}) \: \partial_k f (\mu_{i \to j}) b_{ij}^2 \quad \text{for } k \in \{1, \ldots, n\} \: . $$

Let us discretize $[0,1]$ with $0 = t_0 < t_1 < \ldots < t_N = 1$ uniformly: for all $p$, $t_{p+1} - t_p = h = \frac{1}{N}$. We propose the following numerical scheme to compute $(\mu^{(p)}, U^{(p)})_p$ in $\mathring{\Delta}(n) \times {\rm O}(n)$:

Initial data are $(\mu^{(0)}, U^{(0)}) \in \mathring{\Delta}(n) \times {\rm O}(n)$ and $(\mu^\prime)^{(0)} \in \{ x = (x_1, \ldots, x_n) \in \mathbb{R}^n \: : \: x_1 + \ldots + x_n = 0 \}$, $B^{(0)} \in {\rm Skew(n)}$.

For $p \in \{0, \ldots, N-1\}$,

$$ \begin{align} b_{ij}^{(p)} & = \frac{1}{f(\mu_{i \to j}^{(p)})^2} \left( (U^{(p)})^T U^{(0)} C^{(0)} (U^{(0)})^T U^{(p)} \right)_{ij} \quad \text{where} \quad C^{(0)} = \left( f(\mu_{i \to j}^{(0)})^2 b_{ij}^{(0)} \right)_{ij} \tag{$1$} \\ \mu^{(p+1)} & = \mu^{(p)} + h(\mu^\prime)^{(p)} \tag{$2$} \\ U^{(p+1)} & = U^{(p)} \exp \left(h B^{(p)} \right) \tag{$3$}\\ (\mu^\prime_k)^{(p+1)} & = (\mu^\prime_k)^{(p)} + \frac{h}{n} \left( \sum_{l = 1}^n \sum_{1 \leq i \leq l < j \leq n} f(\mu_{i \to j}^{(p)}) \: \partial_l f (\mu_{i \to j}^{(p)}) (b_{ij}^{(p)})^2 - n \sum_{1 \leq i \leq k < j \leq n} f(\mu_{i \to j}^{(p)}) \: \partial_k f (\mu_{i \to j}^{(p)}) (b_{ij}^{(p)})^2 \right) \quad \text{for } k \in \{1, \ldots, n\} \tag{$4$} \end{align} $$

We test the implementation with $f(\nu) = \frac14 |\nu|$ so that for all $k \in \{1, \ldots, n\}$ and $\nu \neq 0$, $\partial_k f(\nu) = \frac14 \frac{\nu_k}{|\nu|}$.

It is possible to change the expression of $f$, testing for instance $f(\nu) = \nu_1 + \ldots + \nu_n$.

We first define $f$ and its partial derivatives $\partial_k f$.

We then define

We carry on with the implementation of the numerical scheme allowing to compute $(\mu^{(p)}, U^{(p)}) \in \mathring{\Delta}(n) \times O(n)$.

The function geodStartnD takes as imput:

Thanks to equations $(1)$ to $(4)$, the function geodStartnD computes

The following function traceGeod allows to visualize a path $\gamma = (\mu, \nu)$, for instance obtained via the numerical computation above, in case $n = 3$. See examples below, corresponding to the numerical experiments displayed in the paper.

We compare the numerical geodesic obtained in Example 1 with the euclidean geodesic joining the same endpoints.