# SNEG quick reference SNEG is an open-source Mathematica package for second quantization and many-body calculations. This reference uses the GitHub release **SNEG 2.2.1** and covers fermionic operator algebra, Wick’s theorem, Hubbard model exact diagonalization, and a retarded Green’s function. ## Install and load SNEG With Mathematica 12.1 or newer, install the version used here. ```wl PacletInstall["https://github.com/rokzitko/sneg/releases/download/v2.2.1/SNEG.paclet"] ``` In a fresh kernel, evaluate the load and version check in successive cells. ```wl Needs["sneg`"] ``` ```wl $SnegVersion ``` The version check returns `"2.2.1"`. With Mathematica 14.0 or newer, open `paclet:SNEG/guide/SNEG` for the integrated help. For source installation and older Mathematica versions, see the [installation guide](https://github.com/rokzitko/sneg/blob/v2.2.1/README.md#installation). ## Operator notation - Declare an operator family with `snegfermionoperators[c]`. For a spinful level, `c[CR, i, UP]` creates an up-spin electron at level `i` and `c[AN, i, DO]` annihilates a down-spin electron. `c[i]` designates the level in constructors such as `number[c[i]]`. - Use `nc[a, b]` for noncommutative multiplication, ordinary multiplication for scalar prefactors, `pow[a, n]` for operator powers, and `conj[a]` for the Hermitian adjoint. `nc` applies the algebra and ordering rules for the declared operator families. - For fermions, `EMPTY` is the default reference state. `ordering[c] = SEA` selects the Fermi sea. `ordering[c] = NONE` keeps the input order of that family. See the [ordering reference](https://raw.githubusercontent.com/rokzitko/sneg/v2.2.1/doc/src/ref/ordering.md) for the contraction and mixed-family rules. ## Four worked recipes Start each recipe with a fresh kernel and evaluate the load cell before the recipe. Each block includes the operator and parameter declarations it needs. ### Fermionic anticommutators and normal ordering ```wl snegfermionoperators[c]; car = Table[antikomutator[c[AN, s], c[CR, r]], {s, {UP, DO}}, {r, {UP, DO}}]; normalOrderCheck = Expand[ nc[c[AN, UP], c[CR, UP]] + nc[c[CR, UP], c[AN, UP]]]; {car, normalOrderCheck} ``` The result is `{{{1, 0}, {0, 1}}, 1}`. The matrix encodes the two spin components of the canonical anticommutator. The last entry checks the sign and constant term in normal ordering. [First calculation with the Hubbard atom](https://raw.githubusercontent.com/rokzitko/sneg/v2.2.1/doc/src/tutorial/FirstCalculation.md) ### Wick’s theorem for a filled Fermi sea ```wl snegfermionoperators[c]; ordering[c] = SEA; snegfreeindexes[k1, k2, k3, k4]; fourPoint = SimplifyKD[vevwick[nc[ c[CR, k1, UP], c[CR, k2, UP], c[AN, k3, UP], c[AN, k4, UP]]]]; {fourPoint /. {k1 -> -1, k2 -> -2, k3 -> -2, k4 -> -1}, fourPoint /. {k1 -> -1, k2 -> -2, k3 -> -1, k4 -> -2}} ``` The result is `{1, -1}`. The first assignment selects the direct contraction and the second selects the exchange contraction for two distinct occupied levels. The signed label immediately after `CR` or `AN` is measured relative to the Fermi level. Negative labels have occupation `UnitStep[-k] = 1`. The step-function identities used by `SimplifyKD` assume nonzero arguments. [Wick theorem example](https://nrgljubljana.ijs.si/sneg/examples/wick-theorem/) · [SimplifyKD reference](https://raw.githubusercontent.com/rokzitko/sneg/v2.2.1/doc/src/ref/SimplifyKD.md) ### Exact diagonalization of the Hubbard dimer ```wl snegfermionoperators[c]; sites = {c[1], c[2]}; h = -hop[c[1], c[2]] + 4 Total[hubbard[sites]]; sectors = qszbasisvc[sites, 1/2]; states = First[Cases[sectors, {{0, 0}, statesInSector_} :> statesInSector]]; m = matrixrepresentationvcsparse[h, states]; {Dimensions[m], Min[Eigenvalues[Normal[m]]]} ``` This uses hopping `t = 1`, on-site repulsion `U = 4`, and the half-filled sector with `Q = N - 2 = 0` and `Sz = 0`. The matrix dimensions are `{4, 4}` and its ground-state energy is $2-2\sqrt{2}$. `qszbasisvc` sets `BASIS`, so construct the matrix while the basis for these sites is active. [Hubbard dimer example](https://nrgljubljana.ijs.si/sneg/examples/hubbard-dimer/) · [Occupation basis reference](https://raw.githubusercontent.com/rokzitko/sneg/v2.2.1/doc/src/ref/qszbasisvc.md) ### Retarded Green’s function of the Hubbard atom ```wl snegfermionoperators[d]; snegrealconstants[eps, U]; h = eps number[d[]] + U hubbard[d[]]; g = greensfunction[d[AN, UP], d[CR, UP], h, z]; expected = (1 - w)/(z - eps) + w/(z - eps - U); Together[(g /. avg[number[d[], DO]] -> w) - expected] ``` The result is `0`. Here `eps` is the level energy relative to the chemical potential, `Im[z] > 0` selects the retarded function, and `w` is the mean down-spin occupation. The poles at `eps` and `eps + U` have weights `1 - w` and `w`. The function takes both operators explicitly and leaves state averages symbolic by default. [Hubbard atom example](https://nrgljubljana.ijs.si/sneg/examples/atomic-propagator/) · [Green’s function reference](https://raw.githubusercontent.com/rokzitko/sneg/v2.2.1/doc/src/ref/greensfunction.md) ## Choose a method - **Periodic lattices and band structure.** Use `fourier` and `blochhamiltonian` for Bloch matrices, or `clusterhop` and `momentumbasis` for finite periodic clusters. [Momentum-space guide](https://github.com/rokzitko/sneg/blob/v2.2.1/README_momentum.md) · [SSH chain](https://nrgljubljana.ijs.si/sneg/examples/ssh/) - **Quantum spin models.** Use `snegspinoperators` and `spinclustermatrices` for spin Hamiltonians, or `jordanwigner` for the fermionic representation. [Spin guide](https://github.com/rokzitko/sneg/blob/v2.2.1/README_spin.md) · [XXZ chain](https://nrgljubljana.ijs.si/sneg/examples/xxz/) - **Pairing and quadratic Hamiltonians.** Use `bdghamiltonian` and `bogoliubov` for quadratic problems, or `meanfield` and `meanfieldsolve` for self-consistent decoupling. [Quadratic Hamiltonians guide](https://github.com/rokzitko/sneg/blob/v2.2.1/README_quadratic.md) · [Kitaev chain](https://nrgljubljana.ijs.si/sneg/examples/kitaev/) - **Low-energy effective models.** Use `schriefferwolff` with a specified low-energy projector and perturbative order. [Schrieffer–Wolff guide](https://github.com/rokzitko/sneg/blob/v2.2.1/README_schriefferwolff.md) · [Anderson model example](https://nrgljubljana.ijs.si/sneg/examples/anderson/) See the [worked examples](https://nrgljubljana.ijs.si/sneg/examples/) and the [SNEG manual](https://nrgljubljana.ijs.si/sneg/sneg-manual.pdf) for full calculations. Report documentation issues with the package version and a minimal Wolfram Language example. [GitHub Issues](https://github.com/rokzitko/sneg/issues) For published work, cite R. Žitko, *Computer Physics Communications* **182**, 2259–2264 (2011). [SNEG paper](https://doi.org/10.1016/j.cpc.2011.05.013) SNEG documentation project · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).