NRG Ljubljana home

SNEG

Symbolic second-quantization algebra in Mathematica.

Build operators, states, bases, and matrix representations with an open-source Wolfram Language package. SNEG handles noncommuting operators and sign-sensitive algebra, from normal ordering and Wick expansion to exact-diagonalization problems.

The canonical fermion identity c c† + c† c = 1, with a workflow from operators to bases and matrices.

Get started

The latest published release is SNEG 2.2.1 (29 November 2026). No compilation is required.

With Mathematica 12.1 or newer, install or update the latest release directly from a notebook:

PacletInstall[
  "https://github.com/rokzitko/sneg/releases/latest/download/SNEG.paclet"
]

Load the package and check its version:

Needs["sneg`"]
$SnegVersion

Both Needs["sneg`"] and Needs["Sneg`"] are supported. The integrated help requires Mathematica 14.0 or newer. See the installation guide for details.

Manual source installation

Download the 2.2.1 source (ZIP) and place the extracted contents in the directory returned by:

FileNameJoin[{$UserBaseDirectory, "Applications", "sneg"}]

Name the directory sneg, renaming sneg-2.2.1 if necessary. Load a manual installation with:

<< sneg`

A checkout at any location can also be loaded directly:

Get["/absolute/path/to/sneg/sneg.m"]

What’s new in SNEG 2.2

SNEG 2.2.1 keeps delta, step-function, and positivity rules within the package and updates the Mathematica help, manual, and Wick theorem example. See the 2.2.1 release notes and the 2.2.0 feature overview. Historical downloads are in the legacy archive.

From operator algebra to matrix elements

At the core of SNEG is nc, noncommutative multiplication that automatically orders operators according to their declared commutation or anticommutation rules.

Operator algebra

  • Fermionic, bosonic, Majorana, and spin operators, plus Grassmann variables and fermionic coherent states.
  • Normal and particle-hole ordering, including a no-reordering convention.
  • Conjugation, commutators, anticommutators, spin inversion, vacuum expectation values, and Wick expansion.
  • Symbolic sums, dummy-index renaming, and Kronecker-delta simplification.
  • Selected Baker–Campbell–Hausdorff identities and noncommutative power-series expansions.

States, bases, and matrices

  • Occupation-number states and efficient application of operator strings.
  • Symmetry-adapted bases for charge, spin, and isospin, with optional reflection parity.
  • Basis transformations, tensor products, merging, decomposition, and orthogonalization.
  • Dense and sparse operator matrices, with constructors for number, hopping, interactions, and projectors.
  • Dirac bra-ket notation and finite single- and multi-mode phonon spaces.

SNEG provides the symbolic foundation of NRG Ljubljana. It is also used for exact diagonalization of Hubbard clusters, perturbation theory, and teaching second-quantization methods.

Documentation and examples

Mathematica help

The SNEG 2.2 paclet includes searchable English function reference pages, tutorials, and evaluated examples in the Wolfram Documentation Center on Mathematica 14.0 or newer. Search for a SNEG function or click Documentation in the notebook startup message to open the SNEG guide (paclet:SNEG/guide/SNEG).

SNEG quick reference has installation instructions and four runnable Mathematica recipes for fermionic algebra, Wick’s theorem, exact diagonalization, and Green’s functions.

Manual and companion notebooks

Second Quantization with SNEG (PDF) is the 288-page tutorial and reference manual for SNEG 2.2. It includes a grouped function reference and exercises with solutions. Worked calculations cover electrons in crystals, electron–phonon coupling, correlated electrons, superconductivity, and magnetism.

The 15 companion Mathematica notebooks reproduce calculations from the manual, including the Hubbard dimer, the SSH chain, and the superconducting impurity.

Browse all 15 worked examples online with rendered equations, copyable Wolfram Language code, and Mathematica output.

To build the PDF locally, run wolframscript -file doc/manual/build-manual.wl from the repository root. The output is doc/manual/sneg-manual.pdf. See the manual build requirements.

Examples and legacy documentation

Worked notebooks from this site

These historical examples illustrate SNEG’s notation and applications. Open them in Mathematica with SNEG installed to evaluate the calculations.

Examples of SNEG notebook output: occupation-number states, operator expressions, bra-ket notation, and symbolic sums.
SNEG’s formatted notebook output keeps operators, states, and symbolic expressions readable.

Licence and citation

SNEG is free software, distributed under the GNU General Public License, version 2 or later.

The manual and its companion notebooks are licensed under Creative Commons Attribution 4.0 International.

When publishing work that uses SNEG, please cite:

R. Žitko, SNEG – Mathematica package for symbolic calculations with second-quantization-operator expressions, Computer Physics Communications 182, 2259–2264 (2011). Paper (PDF).

A citable historical software snapshot is also available: SNEG 2.0.0 on Zenodo (2022).

Help and feedback

Report bugs or suggest improvements through GitHub Issues. For other inquiries, contact rok.zitko@ijs.si.

Earlier news (2006–2022)

Browse archived SNEG releases.