and the operator $M\in GL(L^2(I,\mathbb{R}^{2n}))$ given by $(Mu)(t)=\Psi(t)u(t)$, $t\in I$. Then, as $\mathcal{D}(\mathcal{A}^{\delta_0}_\lambda)=\mathcal{D}(\mathcal{A}_\lambda)$, $M^T\mathcal{A}^{\delta_0}_\lambda M$ is defined on the domain

$$\begin{aligned}
\mathcal{D}(M^T\mathcal{A}^{\delta_0}_\lambda M)&=M^{-1}(\mathcal{D}(\mathcal{A}^{\delta_0}_\lambda))=\{\Psi(\cdot)^{-1}u\in H^1(I,\mathbb{R}^{2n}):u(0)\in\gamma_1(\lambda),\, u(1)\in\gamma_2(\lambda)\}\\
&=\{v\in H^1(I,\mathbb{R}^{2n}):\, v(0)\in\gamma_1(\lambda), v(1)\in\Psi(1)^{-1}\gamma_2(\lambda)\}\end{aligned}$$

and given by

$$\begin{aligned}
(M^T\mathcal{A}^{\delta_0}_\lambda Mu)(t)&=M^T(J\Psi'(t)u(t)+J\Psi(t)u'(t)+\delta_0\Psi(t)u(t))\\
&=M^T(-\delta_0\Psi(t)u(t)+J\Psi(t)u'(t)+\delta_0\Psi(t)u(t))=\Psi(t)^TJ\Psi(t)u'(t)=Ju'(t).\end{aligned}$$

As $\Psi(t)=\exp(\delta_0 Jt)$, $t\in I$, we see that $\Psi(1)^{-1}=\exp(-\delta_0 J)$. Finally, if $\delta_0>0$ is sufficiently small, we obtain by Step 1, Proposition \[prop-continuity\] and the definition of the Maslov index for non-admissible paths in Section \[section-Maslov\],

$$\operatorname{sf}(\mathcal{A})=\operatorname{sf}(\mathcal{A}^{\delta_0})=\mu_{Mas}(\gamma_1,e^{-\delta_0 J}\gamma_2)=\mu_{Mas}(\gamma_1,\gamma_2),$$ which proves Theorem \[main\] in the general case.

A Spectral Flow Formula for Hamiltonian Systems
===============================================

Let $\gamma_1,\gamma_2:I\rightarrow\Lambda(n)$ be two paths of Lagrangian subspaces in $\mathbb{R}^{2n}$. We note for later reference the following two standard properties of the Maslov index (see e.g. [@RobbinMaslov])

1.  If $\Psi:I\rightarrow\operatorname{Sp}(2n,\mathbb{R})$ is a path of symplectic matrices, then

    $$\begin{aligned}
    \label{sympinv}
    \mu_{Mas}(\Psi\gamma_1,\Psi \gamma_2)=\mu_{Mas}(\gamma_1,\gamma_2).\end{aligned}$$

2.  If $\gamma'_1,\gamma'_2:I\rightarrow\Lambda(n)$ denote the reverse paths defined by $\gamma'_1(\lambda)=\gamma_1(1-\lambda)$ and $\gamma'_2(\lambda)=\gamma_2(1-\lambda)$, then

    $$\begin{aligned}
    \label{reverse}
    \mu_{Mas}(\gamma'_1,\gamma'_2)=-\mu_{Mas}(\gamma_1,\gamma_2).\end{aligned}$$

Moreover, we need below the following homotopy invariance property which is an immediate consequence of (iii’) in Section \[section-Maslov\] and the definition of the Maslov index for non-admissible pairs of paths:

1.  $\mu_{Mas}(\gamma_1,\gamma_2)=\mu_{Mas}(\gamma_3,\gamma_4)$ if $\gamma_1\simeq\gamma_3$ and $\gamma_2\simeq\gamma_4$ are homotopic by homotopies with fixed endpoints.

Let now $S:I\times I\rightarrow M(2n,\mathbb{R})$ be a two parameter 