FermiWick All packages GitHub

FermiWick

Fermion operators, as symbols and as matrices

Wick's theorem, mean field, Gutzwiller projectors and exact diagonalisation for fermions, in the Wolfram Language

What it does

FermiWick lets you write fermion operators as on paper — ladder operators, a Hamiltonian, a product of any length, with sites and spins as symbols — and does the algebra for you: normal order, spin operators recognized in the result, expectation values by Wick's theorem in the state you assume, mean-field Hamiltonians, and the exact matrix of the same expression, to solve a small cluster.

  • Ladder operators as on paperc[i, s] and cDag[i, s], with sites and spins as symbols, or modes with any labels: orbitals, momenta, labels of your own; products, sums, "+ h.c.".
  • Normal order, spins recognizedProducts in normal order, the local operators (densities, spins, double occupancy) kept compact, and the operators on several sites recognized: , the chirality, operators of your own.
  • Wick's theorem in the state you assumeExpectation values of products of any length in a Gaussian state declared by its symmetries — spin rotations, charge, time reversal — or by rules, with normal and anomalous contractions.
  • Mean field of any orderThe Hartree–Fock–Bogoliubov Hamiltonian of an operator of four, six or more fermions, with its constant; Gutzwiller projectors, and projected expectation values in the Gutzwiller approximation.
  • Exact diagonalisationThe same expressions as sparse matrices on a Fock space or a symmetry sector: spectra, ground states, correlations, Green's functions. A Hubbard ring of twelve sites at half filling, 853 776 states, is written as a matrix in about four seconds.
  • LaTeXAny result, and Wick's theorem written out with its contractions drawn.

Sites and spins are symbols, so a result holds on any lattice; with numbers for the sites, the same expression is a matrix, and every symbolic result can be checked exactly.

Scope. Spin-½ fermions, and modes with any labels; exact symbolic expressions, and matrices on clusters of up to about a million states. Bosons and lattice symmetries (momentum, point group) are outside its scope.

A first example

One session, from the ladder operators to a solved model (the matrices are a module of their own):

Needs["FermiWick`"]; Needs["FermiWick`Fock`"]

Ladder operators. c[i, s] annihilates and cDag[i, s] creates a fermion on site i with spin s; ** multiplies in the order written, and NormalOrder brings the creators to the left:

NormalOrder[c[1, SpinUp] ** cDag[1, SpinUp]]

Spins. Products of ladder operators are read back as spins and densities, with the sites left as symbols:

ToSpinChargeBasis[1/2 Sum[cDag[i, s] ** c[i, r] ** cDag[j, r] ** c[j, s], {s, $Spins}, {r, $Spins}]]

A model, solved exactly. The Hubbard dimer, written as on paper (the interaction in the form symmetric about half filling, ), is a matrix on the sector of two electrons with ; its spectrum:

H = -t Sum[PlusHC[cDag[1, s] ** c[2, s]], {s, $Spins}] + U/2 Sum[(nTotOp[i] - 1)^2, {i, 2}];
Eigenvalues[Normal[FockMatrix[H, FockSector[FockSpace[{1, 2}], "N" -> 2, "Sz" -> 0]]]]

Expectation values. By Wick's theorem, in a Gaussian state, a state fixed by its contractions: SpinSingletState[] is the one invariant under spin rotations, with hopping amplitudes . The energy of the dimer in it:

WickVEV[H, SpinSingletState[]]

The state you assume. A state is declared by its symmetries, and they decide what survives: the scalar chirality , a product of six fermions, needs a state that breaks time reversal.

{WickVEV[SdotScrossS[1, 2, 3], GaussianState[{"SpinRotation", "Charge"}]],
 WickVEV[SdotScrossS[1, 2, 3], GaussianState[{"SpinRotation", "Charge", "TimeReversal"}]]}

Mean field. The Hartree–Fock–Bogoliubov Hamiltonian of any operator: the Hubbard interaction of a site, in a state with magnetization along .

magnetic = GaussianState[{"SpinRotationZ", "Charge"}, "Filling" -> 1/2, "Magnetization" -> m];
ToSpinChargeBasis[MeanField[U nOp[1, SpinUp] ** nOp[1, SpinDown], magnetic]]

LaTeX. Any result in LaTeX; WickTeX writes Wick's theorem out, with the contractions drawn:

WickTeX[cDag[1, SpinUp] ** cDag[2, SpinDown] ** c[3, SpinDown] ** c[4, SpinUp], SpinSingletState["Pairing" -> Δ]]

Next. The guided tour builds all this up step by step; the wiki has the recipes (writing operators, declaring a state, mean field, exact diagonalisation, LaTeX); the showcase goes through the physics, and the manual describes every function. ?FermiWick`* lists the functions and ?Name explains each one.

Installation

Install the paclet of the latest release once:

PacletInstall["https://github.com/n4sd4q/FermiWick/releases/download/v0.6.0/FermiWick-0.6.0.paclet"]

and load it in every session:

Needs["FermiWick`"]
Needs["FermiWick`Gutzwiller`"]   (* Gutzwiller projectors, when needed *)
Needs["FermiWick`Fock`"]         (* matrices and exact diagonalisation, when needed *)

There are no dependencies; the package needs Mathematica 13.0 or later. The guided tour, a notebook to run cell by cell, comes with the paclet:

NotebookOpen[PacletObject["FermiWick"]["AssetLocation", "Examples"]]

In a notebook the package looks for a newer release on GitHub once a day; $FermiWickUpdateCheck = False before Needs turns this off (SECURITY.md says more). Other ways to install, and updating: the wiki's Installation page.

Checks

The tests (math -script Tests/RunTests.wls, 101 tests) check the algebra and the states, and the symbolic engine against the matrices: WickVEV and MeanField give the exact values in random Gibbs states of quadratic Hamiltonians with pairing, and the matrices agree with the Jordan–Wigner construction and with exact solutions of Hubbard clusters. sh Development/check_docs.sh runs the code of the showcase, the manual, the guided tour, the README and the wiki again, in fresh kernels, and compares it with what they print.

Related software

SNEG (Žitko, Comput. Phys. Commun. 182, 2259 (2011)) is the closest relative: second quantization in Mathematica, with bosons, Majorana fermions, arbitrary spin and exact diagonalization; its Wick contractions are taken in the vacuum or in the Fermi sea. QuantumAlgebra.jl (Julia) handles equations of motion and cumulant expansions; wick&d, SeQuant, pdaggerq, drudge and SymPy's secondquant are built for the coupled-cluster equations of quantum chemistry. FermiWick adds Wick's theorem in a Gaussian state that you declare, with anomalous contractions, the mean field of any order, Gutzwiller projectors, and the same operators as exact matrices.

How to cite

If you use FermiWick in published work, please cite it (CITATION.cff):

@software{africani_fermiwick,
  author  = {Africani, Nazzareno},
  title   = {{FermiWick}: Wick's theorem, mean field, Gutzwiller projectors and exact diagonalisation for fermions in the Wolfram Language},
  version = {0.6.0},
  year    = {2026},
  url     = {https://github.com/n4sd4q/FermiWick}
}