# Finite XXX transfer algebra

This NumPy experiment checks the algebra behind the periodic spin-half XXX
Hamiltonian at N=3,4,5, and regular one-/two-magnon Bethe states through N=6.
It also verifies a complete basis of the N=4, two-down-spin sector with exact
Gaussian-rational arithmetic. The accompanying lessons and Library articles
supply the derivations. Small floating-point matrices test the implementation;
they do not prove the Yang–Baxter equation for all parameters, general Bethe
completeness, charge independence, or an infinite-chain limit.

## Reproduce

The recorded run used Python 3.9.6 and NumPy 2.0.2 with binary64 arithmetic and
complex128 matrices. Python 3.9–3.12 supports this pinned NumPy release. The
complete `/computations/xxx-algebra.zip` download preserves the files together.
For individual downloads, put
`experiment.py`, `inputs.json`, `results.json`, `requirements.txt` and this file
into one folder. In that folder:

```sh
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python experiment.py --check
```

On Windows use `.venv\Scripts\python.exe`. In the repository with NumPy already
installed, run:

```sh
python3 public/computations/xxx-algebra/experiment.py --check
```

Expected output:

```text
XXX algebra: YBE, RTT, transfer, Hamiltonian, B-state momentum, regular Bethe vectors, exceptional points, complete four-site sector and saved-result checks passed.
```

Running without flags prints fresh JSON; `--write` deliberately regenerates `results.json`
after all identity and negative-control checks pass. `--check` never writes
files, compares the complete input object exactly, then compares numerical
results with the declared roundoff tolerances. Required fields and array lengths
must match; Boolean and integer results are exact, and nonfinite numerical
results are rejected. Runtime version strings are
reported but are not required to match. Paths are relative to the script, so
downloaded copies work independently of the repository. Routine builds do not
execute this experiment. Change a separate copy when exploring different inputs.

## Tensor spaces and signs

Each tensor factor is C² with basis up=(1,0), down=(0,1). The first factor is
the leftmost binary digit. With one auxiliary space, the order is `(a,1,...,N)`;
for RTT it is `(a,b,1,...,N)`. `swap` acts directly on those bit labels. It does
not construct permutations from a spin identity that is later being tested.

Use ordinary, ungraded tensor products and

```text
R(u) = u I + i P
L_an(lambda) = R_an(lambda - i/2)
T_a(lambda) = L_aN(lambda) ... L_a1(lambda)
tau(lambda) = tr_a T_a(lambda).
```

The product acts rightmost first. `ordered_product` receives L1,...,LN and
left-multiplies successively, producing LN...L1. The partial trace is a reshaping
and contraction of the two auxiliary indices; it preserves physical matrix
order. The physical Hamiltonian is

```text
H = (J/2) sum_n (I - P_(n,n+1)),  J>0,
H = J*N*I/2 - (i*J/2) tau(i/2)^(-1) tau'(i/2).
```

Sites are periodic. N=2 is excluded because the periodic sum would count the
same unordered bond twice. This educational dense implementation is explicitly
bounded to N=3,4,5 for RTT and the algebra baseline. The regular Bethe-vector
extension also uses N=6; its auxiliary monodromy has dimension 128, matching
the largest RTT matrix already used. No thermodynamic extrapolation is made.

## What is independently checked

- **YBE and its defect.** For two complex pairs `(a,b)`, compare
  R12(a)R13(a+b)R23(b) and the reversed order. Then change the middle argument
  to z=a+b+0.25−0.1i. Their difference is checked against
  `(z-a-b)(P12 P13-P13 P12)`. The wrong argument gives a nonzero residual.
- **Local exchange and RTT.** Build L operators on two auxiliary factors and
  common physical sites, respecting their actual tensor locations. Check the
  local relation and complete RTT products, then separately form the two
  auxiliary traces and compare their products.
- **Exceptional spectral differences.** Take mu=0.25+0.125i and lambda=mu±i.
  These dyadic values represent the differences exactly in binary64. R(−i)
  has rank 1, R(i) rank 3, yet RTT and the transfer commutator still vanish.
  No inverse R is used in any numerical check. The polynomial-continuation
  argument in the article explains the general result at exceptional points.
- **Regularity and direction.** At lambda0=i/2 compare tau0 with i^N U. U is
  independently constructed by the bit rotation
  `|s1,...,sN> -> |sN,s1,...,s(N-1)>`, not by multiplying swap matrices.
  Every unit one-magnon plane wave has U eigenvalue exp(−ik). Reversing the
  monodromy order is checked against U inverse.
- **Actual Bethe state and momentum.** Extract the auxiliary upper-right block
  B(lambda) from the full monodromy and apply it to the all-up vacuum. For each
  N=3,4,5 take m=−1,+1 and lambda_B=(1/2)cot(pi*m/N). Compare every amplitude
  with the explicit formula below, then check its coordinate momentum, active
  U eigenvalue and energy under the independently constructed Pauli Hamiltonian.
  The opposite coordinate momentum deliberately passes the energy test but
  fails the translation and state comparisons.
- **Analytic differentiation.** One calculation propagates product and
  derivative together. A second explicitly sums the N products in which one
  L is omitted, since L'=I. No finite-difference derivative or matrix logarithm
  is used. At the regular point, solve a linear system for tau0 inverse times
  tau0 prime and compare it with `−i sum P`.
- **Independent Hamiltonian.** Assemble `J sum(1/4-S_n dot S_(n+1))` using
  explicit Pauli matrices, Kronecker products and S=sigma/2. This routine calls
  no swap or transfer helper. Compare it with the differentiated transfer
  Hamiltonian, check Hermiticity and its commutator with each generic tau.
- **Exact three-site formulas.** Multiply polynomials in z=lambda−i/2 before
  evaluating a spectral parameter, and compare every coefficient with
  `tau3=(2z^3+3iz^2)I-z(P12+P13+P23)-iU`. Independently diagonalize the Pauli
  Hamiltonian and compare its entire spectrum with 0 and 3J/2, four times each.

The generic spectral pairs are `(0.37+0.21i, -0.42+0.13i)` and
`(1.2-0.4i, -0.2+0.6i)`. These nonreal parameters avoid a test restricted to
accidentally Hermitian or real operators. The saved JSON lists every parameter,
size and residual, not just the largest value.

## One magnon: distinguish the two rapidity conventions

For the specified monodromy order and upper-right block, direct multiplication
gives the one-spin-down coefficient at site x=1,...,N:

```text
<x| B(lambda_B) |all up> = i*(lambda_B+i/2)^(N-x)*(lambda_B-i/2)^(x-1).
```

Thus adjacent coefficients have ratio `(lambda_B-i/2)/(lambda_B+i/2)`.
The coordinate lesson instead defines `z=(lambda_coord+i/2)/(lambda_coord-i/2)`
and a wave proportional to `z^x`. Matching the actual states requires
`lambda_coord=-lambda_B`, so `k_coord=-k_B`, where
`k_B=2*pi*m/N`. The comparison uses the unit coordinate vector
`exp(i*k_coord*(x-1))/sqrt(N)`; replacing x−1 by x changes only its global phase.
These statements establish the one-magnon dictionary. The experiment does not
assert a general multi-magnon wavefunction equivalence.

The active right shift is `U|x>=|x+1>` with periodic sites, so the B state has
eigenvalue `exp(+i*k_B)`, whereas a coordinate wave has `exp(-i*k_coord)`.
Its energy is `J*(1-cos(k_B))`. The sign of momentum is invisible in that energy.

For N=4 the code uses the exact dyadic values lambda_B=±1/2, independently
checks their cotangent relation, and compares the raw amplitudes to exact
Gaussian dyadic values. At lambda_B=+1/2 the site-ordered coefficients are

```text
(-1-i, -1+i, 1+i, 1-i)/4.
```

This state has `k_coord=-pi/2`, U eigenvalue `+i` and energy J. The opposite
coordinate momentum has U eigenvalue `-i` and the same energy J. Both signs
are tested. The saved `B_state_one_magnons` rows include rapidities, momenta,
expected translation eigenvalues, energies, raw coefficients, checks and
negative controls; complex values are stored as `[real, imaginary]`.

## Regular Bethe vectors and the off-shell identity

The new `regular_bethe` input object fixes three probe parameters,
`u=0.37+0.21i, -0.42+0.13i, i/2`, two generic off-shell cases and three exact
on-shell root recipes. All vectors are built by multiplying the **actual**
upper-right monodromy blocks into the all-up vacuum. No eigenvector from
diagonalization is substituted for the Bethe vector.

For one or two distinct regular roots define

```text
Phi = product_j B(lambda_j) |all up>
a(v)=(v+i/2)^N, d(v)=(v-i/2)^N
f(v)=(v-i)/v, h(v)=(v+i)/v
Lambda(u)=a(u)*product_j f(u-lambda_j)+d(u)*product_j h(u-lambda_j)
C_j=a(lambda_j)*product_(k!=j) f(lambda_j-lambda_k)
    -d(lambda_j)*product_(k!=j) h(lambda_j-lambda_k)
W_j(u)=i*C_j/(u-lambda_j).
```

The off-shell transfer action, before imposing root equations, is

```text
tau(u) Phi = Lambda(u) Phi
          + sum_j W_j(u) B(u) product_(k!=j) B(lambda_k) |all up>.
```

The code compares this expression with full tensor-matrix multiplication.
The unwanted coefficients vanish when `C_j=0`. We then separately test the
transfer eigenvalue equation, the independent Pauli Hamiltonian, and the active
bit-rotation U. The vector norm and its fixed magnon sector are always checked;
the product order of two B operators is reversed as another check.

The root/probe distance guard excludes lambda_j=±i/2, coincident roots,
differences ±i and u=lambda_j, with a minimum distance of 0.05 in these samples.
All raw vector norms must exceed 0.0001. These regularity restrictions are part
of this experiment, not a prescription for discarding singular physical states.
The separate singular-pair baseline is unchanged.

| Root recipe | Roots in the creation convention | E/J | Active U eigenvalue | Raw norm |
|---|---|---:|---|---:|
| N=4, one magnon | 1/2 | 1 | i | 0.707106781187 |
| N=5, two magnons | 1/2, −1/2 | 2 | 1 | 0.395284707521 |
| N=6, two magnons | (−sqrt(3)±sqrt(11))/8 | 5/2 | (1+i sqrt(3))/2 | 0.129172310655 |

The last pair is not invariant under sign reversal and has nontrivial total
translation phase. This prevents the symmetric-pair momentum blind spot. Its
coordinate total wave number is −pi/3 modulo 2pi. An independently specified
transfer polynomial is also compared at all three probes:

```text
Lambda_6(u)=2u^6+(5/2)u^4-sqrt(3)u^3+(11/8)u^2
            -(5sqrt(3)/4)u-9/32.
```

The N=5 pair supplies an exact rational check using only standard-library
`Fraction`. Polynomial division verifies

```text
Q(u)=u^2-1/4
(u+i/2)^5 Q(u-i)+(u-i/2)^5 Q(u+i)
    = (2u^5+3u^3+21u/8) Q(u)
```

with an exactly zero remainder. Its raw state has coefficient −1/8 on cyclic
nearest-neighbor down-spin pairs and +1/8 on the other pairs. Exact rational
bond actions give `H Phi/J=2 Phi` and `U Phi=Phi`; its norm squared is 5/32.
The independently constructed B product agrees with these dyadic coefficients
exactly in the recorded binary64 computation. The rational identities, rather
than that last floating-point zero alone, establish the exact finite example.

Generic off-shell cases use N=4 with root `0.27+0.17i`, and N=5 with roots
`0.21+0.17i, -0.61+0.13i`. Their full off-shell action holds, while dropping
the unwanted terms gives an order-one relative residual. Complex root-energy
and translation products in these rows are **formal scalars**, not claims of
physical energy or a unitary translation eigenphase.

### An energy-preserving wrong-root control

For the N=6 pair perturb its positive root by delta=0.01, calling the result a,
and choose

```text
b = -sqrt(1/[5-1/(a^2+1/4)]-1/4).
```

The formal sum `1/[2(a^2+1/4)]+1/[2(b^2+1/4)]` still equals 5/2.
This is deliberately insufficient evidence: the energy formula is an
eigenvalue formula only after the appropriate state and Bethe equations have
been established. The perturbed roots are approximately
`(0.20807174784831534, -0.6154289528195204)`. Their vector has Rayleigh energy
2.49752913693, normalized H residual 0.0713467510, largest transfer-eigenstate
residual 0.1036851913 and largest unwanted-coefficient residual 0.1061674786.
The complete off-shell action nevertheless remains correct to roundoff.

## A complete four-site sector

The additional `four_site_sector` input and result objects concern exactly N=4
and M=2, in pair order `(12,13,14,23,24,34)`. They are separate from the prior
algebra and regular-vector records, whose numerical values are retained.
The corresponding [Library proof](https://integrable.org/quantum-integrability/four-site-xxx-completeness/)
explains the finite spanning argument and its scope.

The six normalized states, listed in the order used by the JSON, are:

| State | Normalized coefficients in pair order | E/J | Active U | Total spin |
|---|---|---:|---|---:|
| Twice-lowered vacuum | `(1,1,1,1,1,1)/sqrt(6)` | 0 | 1 | 2 |
| Lowered one magnon, k=pi/2 | `(exp(ikx)+exp(iky))/(2 sqrt(2))` | 1 | -i | 1 |
| Lowered one magnon, k=pi | Same formula | 2 | -1 | 1 |
| Lowered one magnon, k=3pi/2 | Same formula | 1 | i | 1 |
| Physical singular singlet | `(1,0,-1,-1,0,1)/2` | 1 | -1 | 0 |
| Regular singlet | `(1,-2,1,1,-2,1)/sqrt(12)` | 3 | 1 | 0 |

Here x<y are the occupied sites in a row of the pair basis. The three
descendants use **the same unscaled numerator formula**, whose squared norm
is 8 in every case, including k=pi. Their raw coefficients are Gaussian
integers, since exp(ikx) takes values among 1,i,-1,-i. The complete list of
raw squared norms is `6,8,8,8,4,12`. Total-spin labels are checked through
the eigenvalues `s(s+1)=6,2,2,2,0,0` of the full physical spin-squared operator.

The exact part represents each complex number as a pair of `Fraction` values.
It builds H/J from local unequal-bond actions and U from a cyclic site map,
then verifies all six raw eigenvector equations and every inner product.
The normalized projectors can be formed without square roots:

```text
P_j = v_j v_j^dagger / (v_j^dagger v_j),
sum_j P_j = I_6.
```

Every entry of that identity is checked with Gaussian-rational arithmetic,
and exact elimination gives rank six. The JSON stores all six raw vectors
as `[real, imaginary]` rational strings, their exact norms and the exact-check
results. This is an explicit completeness result for this six-dimensional
sector, not a count inferred from distinct energies or a theorem at general N.

The floating-point part independently restricts the existing Pauli-tensor
Hamiltonian and bit-rotation translation to the same sector. It compares
them with the exact bond/site constructions, checks the normalized Gram matrix
and projector sum, and obtains the spectrum with multiplicities:

```text
E/J = [0, 1, 1, 1, 2, 3].
```

It constructs total S-minus from local spin matrices, verifies `[H,S-minus]=0`
and `[U,S-minus]=0`, and lowers the actual normalized one-magnon plane waves.
Their lowered norm squared is 2. Lowering the vacuum twice gives norm squared
24; division by `2 sqrt(6)` produces the constant state. Expanding the actual
local L factors as polynomials also gives a zero degree-four B coefficient
and degree-three coefficient exactly `i S-minus` in the recorded arithmetic.
This checks `B(u)=i u^3 S-minus+O(u^2)` by coefficient extraction rather than
evaluation at a large but finite parameter.

The regular state is checked against the actual creation blocks:

```text
B(1/(2 sqrt(3))) B(-1/(2 sqrt(3))) |0>
  = (2/27) (1,-2,1,1,-2,1),
raw norm squared = 16/243.
```

The radicals are evaluated in binary64 in this comparison; their exact target
and the sector proof are separate. The raw singular product
`B(i/2) B(-i/2)|0>` is zero and cannot be normalized. The nonzero singular
column above is the physical limiting state derived in the separate
singular-state case study; this extension verifies its sector equations and
contribution to the basis, without rerunning that regularization experiment.

Two deliberately incomplete lists retain correct equations for every column:

| Control | Columns | Exact rank | Gram Frobenius error | Projector-sum Frobenius error |
|---|---:|---:|---:|---:|
| Omit the singular state | 5 | 5 | Roundoff | 1 |
| Replace the singular state with another copy of the regular state | 6 | 5 | sqrt(2) | sqrt(2) |

Both still contain the distinct energy values 0,1,2,3. For the omission,
`I-sum P_j` is exactly the singular rank-one projector. For the duplicate,
`sum P_j-I=P_regular-P_singular`. The code verifies these defects exactly,
and both lists have zero projection onto the missing singular direction.
Thus passing all retained eigenvector equations, counting six columns or
retaining every distinct energy is insufficient evidence of completeness.

The four-site result uses absolute Euclidean vector errors and absolute
Frobenius matrix errors; H is divided by J before comparison. The actual
regular B coefficient error divides by the nonzero exact target's norm,
and the normalized state comparison minimizes over a global phase.
The largest accepted four-site discrepancy in the saved run is
`8.881784197001252e-16`; normalized Gram and projector errors are
`4.2005566648082894e-16` and `5.102575794795066e-16`. The actual regular
B coefficient relative error is `3.057568955049956e-16`. Exact rational
identities and these floating-point discrepancies have different meanings.

The top-level `summary` continues to summarize the preceding algebra and
regular-vector checks; `four_site_sector.summary` summarizes this added block.
Both blocks must pass the same equation tolerance and negative-control
threshold before `--check` or `--write` succeeds. The input section is required;
deleting it does not silently skip the new checks.

## Norms, tolerances and recorded results

For dimensionless matrices use

```text
rho(A,B) = ||A-B||_F / max(1, ||A||_F, ||B||_F),
||A||_F = sqrt(sum_ij abs(A_ij)^2).
```

For a commutator this means rho(AB,BA), not its absolute norm. Hamiltonian
discrepancy is `||H_transfer-H_spin||_F/max(J,||H_spin||_F)`. The unit-vector
translation residual uses the Euclidean norm. Three-site spectral differences
are divided by J. All reported residuals are dimensionless; a Frobenius norm
is not the operator norm. Exact zeros below mean equality in the recorded
floating-point calculation, not independent mathematical proof.

The raw B-state coefficient discrepancy is `||b-b_formula||_2/||b_formula||_2`.
For unit states, phase-aligned error is `min_|c|=1 ||b_unit-c*wave||_2`.
Translation error is `||U*b_unit-u_expected*b_unit||_2`; Hamiltonian error is
`||H*b_unit/J-(E/J)*b_unit||_2`. The opposite-momentum wave is also normalized.
Adjacent-ratio and rapidity-ratio errors are absolute complex moduli. The
outside-sector diagnostic is the norm of components outside the one-spin-down
sector divided by the full B-state norm. The extra four-site dyadic check is
the maximum absolute coefficient difference.

For the regular Bethe extension, write `L=tau(u)Phi` and let Phi_j denote the
replacement vector with B(u) in slot j. The off-shell residual is

```text
||L-Lambda*Phi-sum W_j*Phi_j||_2 /
max(||L||_2, abs(Lambda)*||Phi||_2 + sum abs(W_j)*||Phi_j||_2).
```

The wanted-only and unwanted-sum residuals use denominator
`max(||L||_2, abs(Lambda)*||Phi||_2)`. A coefficient residual is
`abs(A_j-D_j)/(abs(A_j)+abs(D_j))`, where A_j and D_j are the two terms of C_j.
H residual is `||H Phi-E_formal Phi||_2/(J||Phi||_2)`, and U residual divides
by `||Phi||_2`. These relative norms do not hide a small raw Bethe vector behind
a denominator of one. The raw norm, its square, denominator separations,
formal scalars, Rayleigh value and every probe result are retained in JSON.

| Check | Largest recorded discrepancy |
|---|---:|
| Yang–Baxter equation | 8.18e−17 |
| Local exchange | 1.23e−16 |
| Generic RTT | 2.20e−16 |
| Generic transfer commutativity | 2.03e−16 |
| Exceptional RTT and transfer commutativity | 0 |
| Regularity and logarithmic derivative | 0 |
| Independent Hamiltonian | 0 |
| N=3 polynomial coefficients | 0 |
| N=3 spectrum, in units J | 5.56e−17 |
| Actual B-state coefficient formula | 8.41e−17 |
| B state versus coordinate wave, up to phase | 2.87e−16 |
| B-state active translation eigenvalue | 4.78e−16 |
| B-state independent Pauli energy | 4.08e−16 |
| Opposite-momentum wave with the same energy | 3.34e−16 |
| Regular Bethe full off-shell action, all cases | 6.36e−16 |
| On-shell unwanted coefficient residual | 3.70e−16 |
| On-shell transfer eigenstate residual | 1.02e−15 |
| On-shell independent H and U residuals | 3.83e−16 |
| Original algebra and regular-vector checks, including plane-wave phases | 1.19e−15 |

Rounded positive entries in this table are upper bounds at the shown precision.
The equation tolerance is 2e−12. Saved numerical comparison uses absolute
tolerance 2e−12 and relative tolerance 1e−9, allowing small platform-dependent
roundoff. Input objects must match exactly, so a small parameter edit cannot
silently pass the saved-data comparison. A successful check also requires all
negative-control residuals to exceed 0.001.

## Negative controls and the partial trace

The wrong middle YBE argument has residual at least 0.157. Omitting the closing
Hamiltonian bond has relative discrepancy at least 0.316. Comparing regularity
with the wrong translation direction has residual at least 1.22. These controls
exercise different conventions rather than repeating the same identity.

For the actual B state, using the opposite momentum gives translation residual
`2*abs(sin(2*pi*m/N))`: about 1.73205, 2 and 1.90211 for N=3,4,5. Its
phase-aligned state error is sqrt(2), since the two momenta are orthogonal on
these rings. The wrong-momentum wave nevertheless passes the independent
Hamiltonian test at the same energy. This is why the momentum audit uses the
state and translation operator, not just a matching energy.

For a concrete failure of unrestricted partial-trace cyclicity, let
`A=|0><1|_a tensor sigma_x` and `B=|1><0|_a tensor sigma_z`. Then
`tr_a(AB)=sigma_x sigma_z` and `tr_a(BA)=sigma_z sigma_x`. Their normalized
discrepancy is 2.0 even though their full traces agree. This does not contradict
the cyclic operation used in the RTT proof: an auxiliary-only numerical R
commutes with physical matrix entries, whereas A and B here do not.

## Source and claim limits

L. D. Faddeev, *How Algebraic Bethe Ansatz works for integrable model*,
arXiv:hep-th/9605187v1 (1996), §3, equations (31)–(39), (42)–(48), (49)–(60),
(61)–(65); §4, equations (66)–(79), (82)–(97), (106)–(108) for the triangular vacuum,
Bethe-vector action and translation phase. [Version record](https://arxiv.org/abs/hep-th/9605187v1),
[open PDF](https://arxiv.org/pdf/hep-th/9605187v1). The site's Hamiltonian is
`H_site=−J H_Faddeev`; the source and the site use the same shifted L operator.
Equation locators avoid confusing PDF positions with printed page labels.
The four-site extension additionally uses §3, equation (45), and §4,
equations (98)–(105), for the leading monodromy coefficient, spin symmetry and
highest-weight framework. The six-state completeness proof is checked directly
in its declared finite sector.

The code and negative controls are original implementations of the stated
finite-dimensional identities. The site supplies proofs for arbitrary N and
the hypotheses of the trace argument. This experiment makes no claim about
general Bethe completeness, independence or locality of all higher charges, arbitrary
open boundaries, graded tensor products, or a thermodynamic limit.
