Independent scholarship · Open accessThe monthly digest

Indexed text attachment

coherent-specialization-on-graalvm.tex

Source for Coherent Specialization on GraalVM

View paper · Download original file

Lines 343–442 of 803. Source text is displayed literally.

343$U(t+s)=U(t)U(s)$. Hamiltonians with different spectra induce different344families of specialization constants. The state is dynamic, so an345individual compiled evolution can be applied to any state of the required346dimension or repeatedly reused in a time-stepping loop.347 348The functor of restriction of scalars from complex to real vector spaces349sends $U=A+iB$ to350\[351  \mathcal R(U)=352  \begin{pmatrix} A&-B\\ B&A\end{pmatrix}.353\]354The ordered basis used by the code interleaves the real and imaginary355coordinates. The displayed block order and the stored order differ by a356permutation of coordinates. For $z=x+iy$,357$U z=(Ax-By)+i(Ay+Bx)$. This identity follows by bilinearity and358$i^2=-1$. It implies359$\mathcal R(UV)=\mathcal R(U)\mathcal R(V)$ and360$\mathcal R(U^*)=\mathcal R(U)^\top$. In particular realification361takes a unitary to an orthogonal operator. This algebraic property362justifies the translation from a complex map to paired real linear forms.363 364The compiler constructs a pair of term templates per row. For row $j$ the365two static parameter lists hold its $A_{jk}$ and $B_{jk}$. The real and366imaginary outputs are built from367\[368\begin{split}369    r_j(x,y)&=\sum_k(A_{jk}x_k-B_{jk}y_k),\\370    i_j(x,y)&=\sum_k(A_{jk}y_k+B_{jk}x_k).371\end{split}372\]373The specification uses a balanced sum with a fixed operation order. The374runtime binds the coefficients, producing $2\dim\mathcal H$ executable375roots. A guest callable vector step holds these roots and supplies the376same state to each. The method uses dense storage and arithmetic,377$O((\dim\mathcal H)^2)$ for a step after coefficient generation. The378precomputation of $U(t)$ is part of the respective domain compiler.379Changing $t$ binds new coefficients.380 381In binary64 this construction evaluates the arithmetic expression that382its source specifies. Orthogonality and group composition hold in exact383real arithmetic. Computing the coefficients, performing products and384sums, and applying many steps introduce rounding. We therefore measure385defects of norm preservation, inverse recovery, and composition and386compare both examples to separately computed dynamical references.387Both quantum examples also measure energy conservation.388 389\section{Compiling free-electron time evolution}390\label{sec:electron}391 392With $\hbar=1$, consider the spatial wavefunction of one free electron on a periodic grid with $N\ge3$ sites, spacing $a>0$, and mass $m>0$. The Hamiltonian is spin independent, so this evolution acts on either spin component. The input to each compiled evolution is a state $\psi\in\mathbb C^N$ with interleaved real and imaginary coordinates. The discretization uses the centered second difference on $\mathbb Z/N\mathbb Z$. Indices are cyclic and the Hamiltonian is393\[394(H\psi)_j=\frac{2\psi_j-\psi_{j-1}-\psi_{j+1}}{2ma^2}.395\]396The lattice evolution solves $i\partial_t\psi=H\psi$ in continuous time. The grid and finite volume specify the spatial model. In particular, for a fixed physical wavenumber $\kappa=2\pi k/(Na)$ along grids of fixed length, its dispersion approaches the continuum value $\kappa^2/(2m)$ with an error of order $a^2$ as $a\to0$.397 398The normalized Fourier basis diagonalizes every circulant operator \cite{strangdct}. For $\omega=\exp(2\pi i/N)$ and $v_k(j)=N^{-1/2}\omega^{jk}$, the two cyclic shifts multiply $v_k$ by $\omega^{k}$ and $\omega^{-k}$. This gives399\[400Hv_k=E_k v_k,\qquad E_k=\frac{2}{ma^2}\sin^2\!\left(\frac{\pi k}{N}\right).401\]402Let $F$ denote the unitary forward Fourier transform whose $k,j$ entry is $N^{-1/2}\omega^{-kj}$. Then403\begin{align*}404U(t)&=F^*\operatorname{diag}(e^{-itE_k})F,\\405U(t)_{j\ell}&=\frac1N\sum_{k=0}^{N-1}\omega^{k(j-\ell)}e^{-itE_k}.406\end{align*}407The first identity uses the scalar differential equation in each mode. The second gives a kernel depending only on the displacement $j-\ell$ modulo $N$. The compiler evaluates the $N$ displacement coefficients before binding the static parameters for time $t$.408 409Exactly, $U(0)=I$, $U(t+s)=U(t)U(s)$, and $U(t)^*=U(-t)$. These equalities follow by multiplying diagonal factors. They give a continuous functor $B(\mathbb R,+)\to B\mathrm U(N)$ between one-object topological categories. Passing to their nerves yields coherent composition of the time-indexed algorithms. The distinction between a static time setting and a dynamic state is visible in the family $\mathbb R\times\mathbb C^N\to\mathbb C^N$ with value $(t,\psi)\mapsto U(t)\psi$. It is the state argument that remains after specialization.410 411Writing $U=A+iB$, the real-linear image of $U$ sends $(x,y)$ to $(Ax-By,Bx+Ay)$. This realification preserves composition and sends the complex adjoint to the real transpose. Matrix entries are bound as binary64 static data, with one residual scalar kernel per real or imaginary output coordinate. This factorization separates the Fourier calculation of the operator from repeat invocation on different input states. The source emits a fixed order of floating-point operations. The exact functorial equalities belong to the mathematical operator, and the binary64 kernels approximate them to numerical tolerances on the measured inputs.412 413An independent reference path evolves a state by performing the forward transform, phase rotation in frequency space, and inverse transform directly. For a test with a nonconstant phase and a localized envelope, the generator supplies the normalized state414\[415\psi_j=C\exp\!\left(-\frac{d(j,c)^2}{4\sigma^2}\right)\omega^{p j},416\]417where $d(j,c)=\min(|j-c|,N-|j-c|)$, $c$ is its center, $\sigma>0$ is its width in sites, and $p$ is a carrier mode. The exact evolution preserves $\|\psi\|^2$ and $\langle\psi,H\psi\rangle$ since $U(t)$ is unitary and commutes with $H$. The energy can be checked in position space using the separate formula418\[419\langle\psi,H\psi\rangle=\frac{1}{2ma^2}420  \sum_{j=0}^{N-1}|\psi_{j+1}-\psi_j|^2.421\]422Expanding the squares and using cyclic indexing proves this identity. The direct energy computation and the reference Fourier calculation exercise different numerical routes through the model. Applying the negative-time operator gives a further check of reconstruction. The lattice calculation uses no temporal stepper, so discrepancies in these checks reflect floating-point effects or implementation defects.423 424\section{Interacting fermions on an open chain}425\label{sec:fermion-field}426 427The field compiler starts from a finite lattice Hamiltonian with $L$ spinless sites. The fermionic Fock space is $\bigoplus_{p=0}^L \bigwedge^p\mathbb C^L$. Occupation basis vectors are indexed by bit masks $m$, with the $j$th bit indicating whether site $j$ is occupied. Ordered creation operators fix the sign convention. Let $c_j$ annihilate a fermion at site $j$ and let $c_j^\dagger$ create one there. On a basis vector, an admissible action multiplies by $(-1)^{\sum_{k<j}m_k}$ before changing bit $j$. An inadmissible action yields zero \cite{fermionnotes}.428 429Write $n_j=c_j^\dagger c_j$. With real hopping $g$, interaction $v$, and onsite energies $\mu_j$, the open-chain Hamiltonian is430\begin{align*}431H={}&\sum_{j=0}^{L-1}\mu_j n_j432    + v\sum_{j=0}^{L-2}n_jn_{j+1} \\433   &-g\sum_{j=0}^{L-2}434       (c_{j+1}^\dagger c_j+c_j^\dagger c_{j+1}).435\end{align*}436The density-density term assigns energy to pairs of occupied adjacent sites and is quartic in the field operators. For an allowed hop from $j$ to $k$, the compiler computes the annihilation sign in the original occupation and the creation sign in the intermediate occupation. Both signs matter even though their product is positive for adjacent sites in this ordering. The onsite and interaction terms preserve occupation. Each hop removes one particle and adds one, so $H$ preserves every eigenspace of $\sum_j n_j$. On the $p$-particle sector $\mathcal H_p$, the matrix $H_p$ has dimension $\binom{L}{p}$ and is real symmetric. The inclusion $\iota_p:\mathcal H_p\hookrightarrow\mathcal F$ satisfies $H\iota_p=\iota_p H_p$. Taking powers and summing the exponential series proves437\[438e^{-i\tau H}\iota_p = \iota_p e^{-i\tau H_p}.439\]440The compiler therefore works in the chosen sector without approximating transitions to other particle numbers.441 442In exact arithmetic, $U_p(\tau)=\exp(-i\tau H_p)$ is a unitary evolution, with $U_p(0)=I$ and $U_p(\tau+\sigma)=U_p(\tau)U_p(\sigma)$. This is a functor from the one-object category of the additive time group to the category of finite-dimensional complex Hilbert spaces and linear maps. Realification sends a complex-linear operator to the real-linear operator on its real and imaginary coordinates and preserves composition and adjoints. If $U_p=A+iB$, its action in those coordinates is