liealgebra

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package liealgebra implements computational tools for Lie algebras and root systems using only the Go standard library.

The package is organised around a handful of small, self-contained numeric types and a large collection of genuinely distinct operations on them:

  • Dense real and complex matrices (Matrix, CMatrix) with the arithmetic needed for matrix Lie algebras: addition, multiplication, transpose, conjugate transpose, trace, Frobenius norm, LU based determinant, inverse and linear solve.

  • The Lie bracket (commutator) Bracket and anticommutator, the adjoint action AdjointAction, the Jacobi identity residual and test (JacobiResidual, SatisfiesJacobi), structure constants (StructureConstants), the Killing form (KillingForm, KillingFormValue) and the trace form, together with semisimplicity tests.

  • Concrete generators of the low dimensional Lie algebras: sl(2) with its standard E, F, H basis (SL2Generators), so(3) rotation generators (SO3Generators), su(2) via the Pauli matrices (SU2Generators, PauliMatrices), su(3) via the Gell-Mann matrices (GellMannMatrices), and arbitrary spin-j representations (SpinMatrices).

  • The exponential map for matrices (MatExp, CMatExp) implemented with scaling and squaring and a diagonal Padé approximant, plus integer powers and the leading Baker-Campbell-Hausdorff terms.

  • Root system combinatorics for the classical families A, B, C and D and the exceptional types: Cartan matrices (CartanMatrix), simple and positive roots (SimpleRoots, PositiveRoots), fundamental weights, Weyl group orders (WeylGroupOrder), Coxeter numbers, Dynkin diagram adjacency, Weyl reflections and the Weyl dimension and Casimir formulas.

All computation is deterministic. Operations that can fail (dimension mismatches, singular systems, unknown Dynkin types) return a sentinel error such as ErrDim, ErrSingular or ErrType; a few pure accessors panic on out-of-range indices.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrDim indicates a shape or dimension mismatch between operands.
	ErrDim = errors.New("liealgebra: dimension mismatch")
	// ErrNotSquare indicates that a square matrix was required.
	ErrNotSquare = errors.New("liealgebra: matrix is not square")
	// ErrSingular indicates a singular (non-invertible) linear system.
	ErrSingular = errors.New("liealgebra: singular matrix")
	// ErrRank indicates a rank-deficient or linearly dependent basis.
	ErrRank = errors.New("liealgebra: rank deficient basis")
	// ErrType indicates an unknown or unsupported Dynkin/Cartan type.
	ErrType = errors.New("liealgebra: unknown Dynkin type")
	// ErrRange indicates an out-of-range rank or index argument.
	ErrRange = errors.New("liealgebra: argument out of range")
)

Sentinel errors returned throughout the package.

Functions

func AdjointDimension

func AdjointDimension(family string, rank int) (int, error)

AdjointDimension returns the dimension of the adjoint representation, which equals the dimension of the Lie algebra itself.

func AllRoots

func AllRoots(family string, rank int) ([][]float64, error)

AllRoots returns all roots (positive together with their negatives) of a classical type as Euclidean coordinate vectors.

func CTraceForm

func CTraceForm(a, b *CMatrix) (complex128, error)

CTraceForm returns the complex trace form tr(AB) of two complex matrices.

func CartanInteger

func CartanInteger(alpha, beta []float64) (float64, error)

CartanInteger returns the Cartan integer ⟨α,β∨⟩ = 2(α,β)/(β,β) of two Euclidean root vectors.

func CartanMatrixDeterminant

func CartanMatrixDeterminant(family string, rank int) (float64, error)

CartanMatrixDeterminant returns the determinant of the Cartan matrix, an important invariant equal to the order of the center of the simply connected group (the index of the root lattice in the weight lattice).

func CasimirEigenvalue

func CasimirEigenvalue(family string, rank int, dynkin []int) (float64, error)

CasimirEigenvalue returns the eigenvalue of the quadratic Casimir operator on the irreducible representation with the given highest weight (Dynkin labels), computed as (λ, λ+2ρ) in the normalisation where the long roots have squared length 2. It returns ErrDim if the label count does not match the rank.

func CasimirSU2

func CasimirSU2(j float64) float64

CasimirSU2 returns the physics-convention quadratic Casimir eigenvalue j(j+1) of the spin-j irreducible representation of su(2).

func CasimirTraceNormalization

func CasimirTraceNormalization(basis []*Matrix) (float64, error)

CasimirTraceNormalization returns the constant c such that the Killing form equals c times the trace form on the defining representation, given a basis; it is computed as the ratio of the (0,0) entries of the two Gram matrices and returns ErrRange when the trace form entry is zero.

func Coroot

func Coroot(root []float64) ([]float64, error)

Coroot returns the coroot α∨ = 2α/(α,α) of a Euclidean root vector.

func CoxeterNumber

func CoxeterNumber(family string, rank int) (int, error)

CoxeterNumber returns the Coxeter number h of the given Dynkin type, equal to (number of roots)/rank and to one plus the height of the highest root.

func Det

func Det(m *Matrix) (float64, error)

Det returns the determinant of a square matrix.

func DimensionSLn

func DimensionSLn(n int) (int, error)

DimensionSLn returns the dimension n^2-1 of the Lie algebra sl(n) = A_{n-1}.

func DimensionSOn

func DimensionSOn(n int) (int, error)

DimensionSOn returns the dimension n(n-1)/2 of the Lie algebra so(n).

func DimensionSPn

func DimensionSPn(n int) (int, error)

DimensionSPn returns the dimension n(2n+1) of the Lie algebra sp(2n) = C_n.

func DimensionSU2

func DimensionSU2(j float64) (int, error)

DimensionSU2 returns the dimension 2j+1 of the spin-j representation of su(2). It returns ErrRange if 2j is not a nonnegative integer.

func DimensionSUn

func DimensionSUn(n int) (int, error)

DimensionSUn returns the dimension n^2-1 of the Lie algebra su(n).

func DualCoxeterFromRoots

func DualCoxeterFromRoots(family string, rank int) (int, error)

DualCoxeterFromRoots returns the dual Coxeter number computed as 1 + (ρ, θ∨) where θ is the highest root; provided as an independent cross-check of DualCoxeterNumber for classical and exceptional types.

func DualCoxeterNumber

func DualCoxeterNumber(family string, rank int) (int, error)

DualCoxeterNumber returns the dual Coxeter number h∨ of the given Dynkin type.

func FundamentalWeightsRootBasis

func FundamentalWeightsRootBasis(family string, rank int) ([][]float64, error)

FundamentalWeightsRootBasis returns the fundamental weights expressed in the basis of simple roots; row i is ω_i. They are the rows of the inverse Cartan matrix.

func HighestRootLabel

func HighestRootLabel(family string, rank int) ([]int, error)

HighestRootLabel returns the coefficient vector (in the simple-root basis) of the highest root, the unique positive root of maximal height.

func IsAbelian

func IsAbelian(basis []*Matrix, tol float64) bool

IsAbelian reports whether every pair of basis elements commutes to within tolerance tol, i.e. whether the spanned Lie algebra is abelian.

func IsClosedUnderBracket

func IsClosedUnderBracket(basis []*Matrix, tol float64) bool

IsClosedUnderBracket reports whether the bracket of every pair of basis elements lies in the span of the basis to within tolerance tol, i.e. whether the basis spans a Lie subalgebra.

func IsNilpotentMatrix

func IsNilpotentMatrix(m *Matrix, tol float64) (bool, error)

IsNilpotentMatrix reports whether the square matrix m is nilpotent, i.e. some power m^k (k up to its dimension) vanishes to within tolerance tol.

func IsSemisimple

func IsSemisimple(basis []*Matrix, tol float64) (bool, error)

IsSemisimple reports whether the Killing form of the given basis is nondegenerate (Cartan's criterion), tested by |det K| > tol.

func IsSimplyLaced

func IsSimplyLaced(family string, rank int) (bool, error)

IsSimplyLaced reports whether the Dynkin type is simply laced, i.e. all bonds are single (types A, D, E).

func JacobiResidualConstants

func JacobiResidualConstants(c [][][]float64) float64

JacobiResidualConstants returns the maximum absolute value of the Jacobi identity applied to structure constants: Σ_m ( c[m][i][j] c[n][m][k] + c[m][j][k] c[n][m][i] + c[m][k][i] c[n][m][j] ). It is zero for a genuine Lie algebra and provides a coordinate-space Jacobi check independent of the matrix realisation.

func KillingFormRank

func KillingFormRank(basis []*Matrix, tol float64) (int, error)

KillingFormRank returns the rank of the Killing form of a basis. It equals the dimension of the algebra for a semisimple Lie algebra and is smaller when the radical is nonzero.

func KillingFormValue

func KillingFormValue(basis []*Matrix, x, y []float64) (float64, error)

KillingFormValue returns the Killing form value K(X,Y) = tr(ad_X ad_Y) for two elements X and Y given by their coordinate vectors in the supplied basis.

func LieAlgebraDimension

func LieAlgebraDimension(family string, rank int) (int, error)

LieAlgebraDimension returns the dimension of the semisimple Lie algebra of the given type, equal to rank + number of roots.

func LieAlgebraName

func LieAlgebraName(family string, rank int) (string, error)

LieAlgebraName returns a human-readable classical name for the given Dynkin type, such as "sl(4)" for A_3 or "so(7)" for B_3.

func NumPositiveRoots

func NumPositiveRoots(family string, rank int) (int, error)

NumPositiveRoots returns the number of positive roots of the given type.

func NumRoots

func NumRoots(family string, rank int) (int, error)

NumRoots returns the total number of roots (positive and negative).

func PositiveRootLabels

func PositiveRootLabels(family string, rank int) ([][]int, error)

PositiveRootLabels returns every positive root of the given type expressed as an integer coefficient vector in the basis of simple roots. The algorithm is the standard height-by-height root-string construction driven by the Cartan matrix and works uniformly for classical and exceptional types.

func PositiveRoots

func PositiveRoots(family string, rank int) ([][]float64, error)

PositiveRoots returns the positive roots of a classical type as Euclidean coordinate vectors. It returns ErrType for exceptional types.

func Rank

func Rank(m *Matrix, tol float64) int

Rank returns the numerical rank of a matrix using Gaussian elimination with the given tolerance for treating a pivot as zero.

func RootInnerProduct

func RootInnerProduct(b *Matrix, x, y []float64) (float64, error)

RootInnerProduct returns the inner product of two vectors expressed in the simple-root basis using the bilinear form B (see RootBilinearForm).

func SO3ToVector

func SO3ToVector(m *Matrix) ([]float64, error)

SO3ToVector maps a 3x3 antisymmetric matrix to its axial vector (w) such that the matrix acts as w×. It returns ErrDim if the matrix is not 3x3.

func SatisfiesJacobi

func SatisfiesJacobi(a, b, c *Matrix, tol float64) bool

SatisfiesJacobi reports whether the Jacobi identity holds for A, B, C to within tolerance tol (measured by the max absolute entry of the residual).

func SimpleRoots

func SimpleRoots(family string, rank int) ([][]float64, error)

SimpleRoots returns the simple roots of a classical type (A, B, C or D) as Euclidean coordinate vectors. Type A_n lives in R^(n+1) with α_i = e_i-e_{i+1}; types B_n, C_n and D_n live in R^n. It returns ErrType for exceptional types (use PositiveRootLabels for those).

func Solve

func Solve(a *Matrix, b []float64) ([]float64, error)

Solve solves the linear system A x = b for a square A. It returns ErrSingular if A is not invertible and ErrDim on a length mismatch.

func SolveLeastSquares

func SolveLeastSquares(a *Matrix, b []float64) ([]float64, error)

SolveLeastSquares solves the (possibly overdetermined) system A x = b in the least-squares sense via the normal equations AᵀA x = Aᵀb. It requires A to have full column rank and returns ErrRank otherwise.

func SpectralRadiusBound

func SpectralRadiusBound(m *Matrix) float64

SpectralRadiusBound returns an upper bound on the spectral radius of a real matrix via the maximum absolute row sum (an induced ∞-norm).

func StructureConstants

func StructureConstants(basis []*Matrix) ([][][]float64, error)

StructureConstants computes the structure constants c[k][i][j] of a matrix Lie algebra with the given basis, defined by [e_i, e_j] = Σ_k c[k][i][j] e_k. The basis matrices must be square, of equal size and linearly independent; otherwise ErrRank or ErrDim is returned. The bracket of any two basis elements must lie in the span of the basis (a genuine subalgebra).

func TraceForm

func TraceForm(a, b *Matrix) (float64, error)

TraceForm returns the trace form tr(AB) of two square matrices. For many matrix Lie algebras this is proportional to the Killing form.

func VecAdd

func VecAdd(a, b []float64) ([]float64, error)

VecAdd returns a+b, or ErrDim on a length mismatch.

func VecDot

func VecDot(a, b []float64) (float64, error)

VecDot returns the Euclidean dot product of two equal-length vectors, or ErrDim on a length mismatch.

func VecEqual

func VecEqual(a, b []float64, tol float64) bool

VecEqual reports whether two vectors are equal to within tolerance tol.

func VecNorm

func VecNorm(a []float64) float64

VecNorm returns the Euclidean norm of a vector.

func VecNormSquared

func VecNormSquared(a []float64) float64

VecNormSquared returns the squared Euclidean norm of a vector.

func VecScale

func VecScale(a []float64, s float64) []float64

VecScale returns the vector scaled by s.

func VecSub

func VecSub(a, b []float64) ([]float64, error)

VecSub returns a-b, or ErrDim on a length mismatch.

func WeylDimension

func WeylDimension(family string, rank int, dynkin []int) (int, error)

WeylDimension returns the dimension of the irreducible representation of the given Dynkin type with highest weight specified by nonnegative Dynkin labels (a_1,...,a_rank), via the Weyl dimension formula

dim = Π_{α>0} (λ+ρ, α) / (ρ, α).

The result is rounded to the nearest integer. It returns ErrDim if the number of labels does not match the rank.

Example

ExampleWeylDimension prints the dimension of the adjoint representation of su(3), whose highest weight has Dynkin labels (1,1).

dim, _ := WeylDimension("A", 2, []int{1, 1})
fmt.Println(dim)
Output:
8

func WeylGroupOrder

func WeylGroupOrder(family string, rank int) (*big.Int, error)

WeylGroupOrder returns the order of the Weyl group of the given Dynkin type as an arbitrary-precision integer.

Example

ExampleWeylGroupOrder prints the order of the Weyl group of E8.

w, _ := WeylGroupOrder("E", 8)
fmt.Println(w.String())
Output:
696729600

func WeylOrbit

func WeylOrbit(simple [][]float64, v []float64, tol float64) ([][]float64, error)

WeylOrbit returns the orbit of a Euclidean vector v under the Weyl group generated by reflections in the given simple roots. It repeatedly applies all simple reflections until the orbit stabilises (finite for a genuine root system) and returns the distinct vectors within tolerance tol.

func WeylReflection

func WeylReflection(root, v []float64) ([]float64, error)

WeylReflection returns the reflection of the vector v across the hyperplane orthogonal to root, s_root(v) = v - 2(v,root)/(root,root) root, in Euclidean coordinates. It returns ErrDim on a length mismatch or a zero root.

func WeylVectorRootBasis

func WeylVectorRootBasis(family string, rank int) ([]float64, error)

WeylVectorRootBasis returns the Weyl vector ρ (the sum of the fundamental weights, equivalently half the sum of the positive roots) expressed in the simple-root basis.

Types

type CMatrix

type CMatrix struct {
	Rows int
	Cols int
	Data []complex128
}

CMatrix is a dense complex matrix stored in row-major order. Complex matrices are needed for the unitary Lie algebras su(n), whose generators are naturally complex. The zero value is not usable; construct with NewCMatrix.

func CAnticommutator

func CAnticommutator(a, b *CMatrix) (*CMatrix, error)

CAnticommutator returns {A,B} = AB + BA of two complex matrices.

func CBracket

func CBracket(a, b *CMatrix) (*CMatrix, error)

CBracket returns the Lie bracket [A,B] = AB - BA of two complex matrices.

func CMatExp

func CMatExp(a *CMatrix) (*CMatrix, error)

CMatExp returns the matrix exponential exp(A) of a square complex matrix by scaling and squaring with a truncated Taylor series.

func CMatPow

func CMatPow(a *CMatrix, p int) (*CMatrix, error)

CMatPow returns a complex matrix raised to a nonnegative integer power.

func DiagCMatrix

func DiagCMatrix(d []complex128) *CMatrix

DiagCMatrix returns the square complex matrix with the given diagonal.

func GellMannMatrices

func GellMannMatrices() []*CMatrix

GellMannMatrices returns all eight Gell-Mann matrices λ_1..λ_8.

func GellMannMatrix

func GellMannMatrix(i int) *CMatrix

GellMannMatrix returns the i-th Gell-Mann matrix, i in 1..8. These are the eight Hermitian traceless generators of su(3). It panics if i is out of range.

func IdentityCMatrix

func IdentityCMatrix(n int) *CMatrix

IdentityCMatrix returns the n-by-n complex identity matrix.

func NewCMatrix

func NewCMatrix(rows, cols int) *CMatrix

NewCMatrix returns a rows-by-cols zero complex matrix.

func NewCMatrixFromRows

func NewCMatrixFromRows(rows [][]complex128) (*CMatrix, error)

NewCMatrixFromRows builds a complex matrix from equal-length rows, returning ErrDim if the rows are ragged.

func PauliMatrices

func PauliMatrices() (sx, sy, sz *CMatrix)

PauliMatrices returns the three Pauli matrices (σ_x, σ_y, σ_z). They are Hermitian, traceless, unitary and satisfy σ_iσ_j = δ_ij I + i ε_ijk σ_k.

func PauliX

func PauliX() *CMatrix

PauliX returns the Pauli matrix σ_x = [[0,1],[1,0]].

func PauliY

func PauliY() *CMatrix

PauliY returns the Pauli matrix σ_y = [[0,-i],[i,0]].

func PauliZ

func PauliZ() *CMatrix

PauliZ returns the Pauli matrix σ_z = [[1,0],[0,-1]].

func RealToComplex

func RealToComplex(m *Matrix) *CMatrix

RealToComplex promotes a real matrix to a complex matrix.

func SU2Generators

func SU2Generators() (t1, t2, t3 *CMatrix)

SU2Generators returns the anti-Hermitian generators of su(2) given by T_i = -i σ_i / 2, satisfying [T_i, T_j] = ε_ijk T_k. These are the generators for which the exponential map lands in SU(2).

func SU2SpinMatrices

func SU2SpinMatrices() (sx, sy, sz *CMatrix)

SU2SpinMatrices returns the Hermitian spin-1/2 operators (S_x, S_y, S_z) = (σ_x, σ_y, σ_z)/2 satisfying [S_i,S_j] = i ε_ijk S_k.

func SU3Generators

func SU3Generators() []*CMatrix

SU3Generators returns the anti-Hermitian su(3) generators T_a = -i λ_a / 2 for a in 1..8.

func SpinJz

func SpinJz(j float64) (*CMatrix, error)

SpinJz returns the diagonal Jz operator for spin j.

func SpinLowering

func SpinLowering(j float64) (*CMatrix, error)

SpinLowering returns the lowering operator J- for spin j.

func SpinMatrices

func SpinMatrices(j float64) (jx, jy, jz *CMatrix, err error)

SpinMatrices returns the (2j+1)-dimensional Hermitian angular-momentum operators (Jx, Jy, Jz) for spin/quantum number j (a nonnegative half-integer such as 0.5, 1, 1.5, ...). They satisfy [Ji,Jj] = i ε_ijk Jk. It returns ErrRange if 2j is not a nonnegative integer.

func SpinRaising

func SpinRaising(j float64) (*CMatrix, error)

SpinRaising returns the raising operator J+ for spin j.

func (*CMatrix) Add

func (m *CMatrix) Add(b *CMatrix) (*CMatrix, error)

Add returns m+b or ErrDim.

func (*CMatrix) AntiHermitianPart

func (m *CMatrix) AntiHermitianPart() (*CMatrix, error)

AntiHermitianPart returns (m-mᴴ)/2, the anti-Hermitian part.

func (*CMatrix) ApproxEqual

func (m *CMatrix) ApproxEqual(b *CMatrix, tol float64) bool

ApproxEqual reports shape equality with every entry agreeing to within tol in complex modulus.

func (*CMatrix) At

func (m *CMatrix) At(i, j int) complex128

At returns element (i,j), panicking on an out-of-range index.

func (*CMatrix) Clone

func (m *CMatrix) Clone() *CMatrix

Clone returns a deep copy.

func (*CMatrix) Conjugate

func (m *CMatrix) Conjugate() *CMatrix

Conjugate returns the entrywise complex conjugate.

func (*CMatrix) ConjugateTranspose

func (m *CMatrix) ConjugateTranspose() *CMatrix

ConjugateTranspose returns the Hermitian conjugate (dagger) mᴴ.

func (*CMatrix) Dagger

func (m *CMatrix) Dagger() *CMatrix

Dagger is an alias for CMatrix.ConjugateTranspose.

func (*CMatrix) Dims

func (m *CMatrix) Dims() (int, int)

Dims returns the number of rows and columns.

func (*CMatrix) Equal

func (m *CMatrix) Equal(b *CMatrix) bool

Equal reports exact equality of shape and entries.

func (*CMatrix) FrobeniusNorm

func (m *CMatrix) FrobeniusNorm() float64

FrobeniusNorm returns the square root of the sum of squared moduli.

func (*CMatrix) HermitianPart

func (m *CMatrix) HermitianPart() (*CMatrix, error)

HermitianPart returns (m+mᴴ)/2, the Hermitian part of a square complex matrix.

func (*CMatrix) Imag

func (m *CMatrix) Imag() *Matrix

Imag returns the imaginary part of each entry as a real matrix.

func (*CMatrix) IsAntiHermitian

func (m *CMatrix) IsAntiHermitian(tol float64) bool

IsAntiHermitian reports whether m equals the negative of its conjugate transpose within tol (a skew-Hermitian matrix, as in su(n)).

func (*CMatrix) IsHermitian

func (m *CMatrix) IsHermitian(tol float64) bool

IsHermitian reports whether m equals its conjugate transpose within tol.

func (*CMatrix) IsSquare

func (m *CMatrix) IsSquare() bool

IsSquare reports whether the matrix is square.

func (*CMatrix) IsTraceless

func (m *CMatrix) IsTraceless(tol float64) bool

IsTraceless reports whether the trace is zero within tol.

func (*CMatrix) IsUnitary

func (m *CMatrix) IsUnitary(tol float64) bool

IsUnitary reports whether mᴴm is the identity within tol.

func (*CMatrix) Kronecker

func (m *CMatrix) Kronecker(b *CMatrix) *CMatrix

Kronecker returns the Kronecker (tensor) product m ⊗ b of complex matrices.

func (*CMatrix) MaxAbs

func (m *CMatrix) MaxAbs() float64

MaxAbs returns the largest entry modulus.

func (*CMatrix) Mul

func (m *CMatrix) Mul(b *CMatrix) (*CMatrix, error)

Mul returns the matrix product m*b or ErrDim.

func (*CMatrix) Neg

func (m *CMatrix) Neg() *CMatrix

Neg returns the additive inverse.

func (*CMatrix) Real

func (m *CMatrix) Real() *Matrix

Real returns the real part of each entry as a real matrix.

func (*CMatrix) Scale

func (m *CMatrix) Scale(s complex128) *CMatrix

Scale returns the matrix times the complex scalar s.

func (*CMatrix) Set

func (m *CMatrix) Set(i, j int, v complex128)

Set assigns v to element (i,j), panicking on an out-of-range index.

func (*CMatrix) Sub

func (m *CMatrix) Sub(b *CMatrix) (*CMatrix, error)

Sub returns m-b or ErrDim.

func (*CMatrix) Trace

func (m *CMatrix) Trace() (complex128, error)

Trace returns the sum of diagonal entries, or ErrNotSquare.

func (*CMatrix) Transpose

func (m *CMatrix) Transpose() *CMatrix

Transpose returns the (unconjugated) transpose.

type Matrix

type Matrix struct {
	Rows int
	Cols int
	Data []float64 // len == Rows*Cols, element (i,j) at Data[i*Cols+j]
}

Matrix is a dense real matrix stored in row-major order. The zero value is not usable; construct matrices with NewMatrix and the related helpers.

func AdjointAction

func AdjointAction(x, y *Matrix) (*Matrix, error)

AdjointAction returns ad_X(Y) = [X,Y], the action of X in the adjoint representation on the matrix Y.

func AdjointMatrix

func AdjointMatrix(basis []*Matrix, index int) (*Matrix, error)

AdjointMatrix returns the matrix of ad_{e_index} in the given basis: the d-by-d matrix M with M[k][j] = c[k][index][j] where c are the structure constants. Column j is the coordinate vector of [e_index, e_j].

func Anticommutator

func Anticommutator(a, b *Matrix) (*Matrix, error)

Anticommutator returns {A,B} = AB + BA of two square real matrices.

func BCHApprox

func BCHApprox(x, y *Matrix) (*Matrix, error)

BCHApprox returns the second-order Baker-Campbell-Hausdorff approximation to log(exp(X)exp(Y)):

X + Y + ½[X,Y] + (1/12)([X,[X,Y]] + [Y,[Y,X]]).

It is exact through third order in X and Y and is the standard truncation for small elements of a matrix Lie algebra.

func Bracket

func Bracket(a, b *Matrix) (*Matrix, error)

Bracket returns the Lie bracket (commutator) [A,B] = AB - BA of two square real matrices. It returns ErrDim if the shapes are incompatible.

Example

ExampleBracket demonstrates the sl(2) commutation relation [E,F]=H.

e, f, h := SL2Generators()
br, _ := Bracket(e, f)
fmt.Println(br.Equal(h))
Output:
true

func CartanMatrix

func CartanMatrix(family string, rank int) (*Matrix, error)

CartanMatrix returns the Cartan matrix of the Lie algebra of the given Dynkin type. The family is one of "A","B","C","D" (classical) or "E","F","G" (exceptional); rank must be admissible. Entry A[i][j] equals 2(α_i,α_j)/(α_j,α_j) in the Bourbaki convention.

func CartanMatrixA

func CartanMatrixA(n int) (*Matrix, error)

CartanMatrixA returns the Cartan matrix of type A_n (the Lie algebra sl(n+1)).

func CartanMatrixB

func CartanMatrixB(n int) (*Matrix, error)

CartanMatrixB returns the Cartan matrix of type B_n (the Lie algebra so(2n+1)).

func CartanMatrixC

func CartanMatrixC(n int) (*Matrix, error)

CartanMatrixC returns the Cartan matrix of type C_n (the Lie algebra sp(2n)).

func CartanMatrixD

func CartanMatrixD(n int) (*Matrix, error)

CartanMatrixD returns the Cartan matrix of type D_n (the Lie algebra so(2n)).

func CartanMatrixFromRoots

func CartanMatrixFromRoots(simple [][]float64) (*Matrix, error)

CartanMatrixFromRoots builds the Cartan matrix A[i][j] = 2(α_i,α_j)/(α_j,α_j) from a list of simple roots given as Euclidean coordinate vectors. It returns ErrDim if any root is zero or the coordinate lengths disagree.

func DiagMatrix

func DiagMatrix(d []float64) *Matrix

DiagMatrix returns the square matrix with the given diagonal entries.

func DynkinBondMatrix

func DynkinBondMatrix(family string, rank int) (*Matrix, error)

DynkinBondMatrix returns the matrix B[i][j] = A[i][j]*A[j][i], whose value (0,1,2,3) counts the number of bonds between nodes i and j in the Dynkin diagram.

func DynkinDiagramAdjacency

func DynkinDiagramAdjacency(family string, rank int) (*Matrix, error)

DynkinDiagramAdjacency returns the 0/1 adjacency matrix of the Dynkin diagram: nodes i and j are adjacent when the Cartan entry A[i][j] is nonzero.

func ExpBracketSeries

func ExpBracketSeries(x, y *Matrix, terms int) (*Matrix, error)

ExpBracketSeries returns the truncated series for Ad_{exp(X)}(Y) = exp(ad_X)(Y) = Σ_{k≥0} (1/k!) ad_X^k(Y), summed to the given number of terms (terms>=1). This is the finite version of the identity exp(X)Y exp(-X).

func ExpMap

func ExpMap(a *Matrix) (*Matrix, error)

ExpMap is an alias for MatExp; for a Lie-algebra element X it returns the corresponding group element exp(X).

func HeisenbergGenerators

func HeisenbergGenerators() (x, y, z *Matrix)

HeisenbergGenerators returns the three matrices (X, Y, Z) generating the 3-dimensional Heisenberg Lie algebra of strictly upper-triangular 3x3 real matrices, satisfying [X,Y]=Z and [X,Z]=[Y,Z]=0.

func IdentityMatrix

func IdentityMatrix(n int) *Matrix

IdentityMatrix returns the n-by-n identity matrix.

func Inverse

func Inverse(m *Matrix) (*Matrix, error)

Inverse returns the matrix inverse, or ErrSingular if the matrix is not invertible.

func InverseCartanMatrix

func InverseCartanMatrix(family string, rank int) (*Matrix, error)

InverseCartanMatrix returns the inverse of the Cartan matrix. Its rows give the fundamental weights expressed in the basis of simple roots.

func JacobiResidual

func JacobiResidual(a, b, c *Matrix) (*Matrix, error)

JacobiResidual returns [[A,B],C] + [[B,C],A] + [[C,A],B], which is identically the zero matrix for any associative product and hence for matrix Lie algebras. It is a convenient numerical check of the Jacobi identity.

func KillingForm

func KillingForm(basis []*Matrix) (*Matrix, error)

KillingForm returns the Killing form matrix K of a Lie algebra given by a basis, with entries K[i][j] = tr(ad_{e_i} ad_{e_j}). The result is symmetric.

func MatExp

func MatExp(a *Matrix) (*Matrix, error)

MatExp returns the matrix exponential exp(A) of a square real matrix, computed by scaling and squaring with a truncated Taylor series. It returns ErrNotSquare for non-square input.

func MatPow

func MatPow(a *Matrix, p int) (*Matrix, error)

MatPow returns A raised to a nonnegative integer power using exponentiation by squaring; A^0 is the identity. It returns ErrNotSquare for non-square input and ErrRange for a negative power.

func NestedBracket

func NestedBracket(xs ...*Matrix) (*Matrix, error)

NestedBracket returns the left-nested bracket [x0,[x1,[...,xk]...]] for a list of matrices. An empty list returns ErrDim; a single element returns it.

func NewMatrix

func NewMatrix(rows, cols int) *Matrix

NewMatrix returns a rows-by-cols zero matrix.

func NewMatrixFromRows

func NewMatrixFromRows(rows [][]float64) (*Matrix, error)

NewMatrixFromRows builds a matrix from a slice of equal-length rows. It returns ErrDim if the rows are ragged.

func RootBilinearForm

func RootBilinearForm(family string, rank int) (*Matrix, error)

RootBilinearForm returns the symmetric matrix B with B[i][j] = (α_i,α_j), the inner products of the simple roots normalised so that the longest roots have squared length 2. It is derived from the Cartan matrix and underlies the Weyl dimension and Casimir formulas.

func SL2CartanH

func SL2CartanH() *Matrix

SL2CartanH returns the Cartan generator H of sl(2).

func SL2Generators

func SL2Generators() (e, f, h *Matrix)

SL2Generators returns the standard basis (E, F, H) of the Lie algebra sl(2) of traceless 2x2 real matrices, satisfying [H,E]=2E, [H,F]=-2F and [E,F]=H.

E = [[0,1],[0,0]], F = [[0,0],[1,0]], H = [[1,0],[0,-1]].

func SL2LoweringF

func SL2LoweringF() *Matrix

SL2LoweringF returns the lowering generator F of sl(2).

func SL2RaisingE

func SL2RaisingE() *Matrix

SL2RaisingE returns the raising generator E of sl(2).

func SO3FromVector

func SO3FromVector(w []float64) (*Matrix, error)

SO3FromVector returns the 3x3 antisymmetric matrix [w]_× representing the cross product w×(·). It returns ErrDim unless w has length 3.

func SO3Generators

func SO3Generators() (lx, ly, lz *Matrix)

SO3Generators returns the three real antisymmetric generators (Lx, Ly, Lz) of the rotation algebra so(3), satisfying [Lx,Ly]=Lz and cyclic permutations. Each Li is (L_i)_{jk} = -ε_{ijk}.

func WeylReflectionMatrix

func WeylReflectionMatrix(root []float64) (*Matrix, error)

WeylReflectionMatrix returns the orthogonal matrix of the reflection across the hyperplane orthogonal to the given root in Euclidean coordinates.

func ZeroMatrix

func ZeroMatrix(n int) *Matrix

ZeroMatrix returns an n-by-n zero matrix.

func (*Matrix) Add

func (m *Matrix) Add(b *Matrix) (*Matrix, error)

Add returns m+b or ErrDim on a shape mismatch.

func (*Matrix) AntiSymmetrize

func (m *Matrix) AntiSymmetrize() (*Matrix, error)

AntiSymmetrize returns (m-mᵀ)/2, the antisymmetric part of a square matrix.

func (*Matrix) ApproxEqual

func (m *Matrix) ApproxEqual(b *Matrix, tol float64) bool

ApproxEqual reports whether a and b have the same shape and every entry agrees to within absolute tolerance tol.

func (*Matrix) At

func (m *Matrix) At(i, j int) float64

At returns element (i,j). It panics if the index is out of range.

func (*Matrix) Clone

func (m *Matrix) Clone() *Matrix

Clone returns a deep copy of the matrix.

func (*Matrix) Col

func (m *Matrix) Col(j int) []float64

Col returns a copy of column j.

func (*Matrix) Dims

func (m *Matrix) Dims() (int, int)

Dims returns the number of rows and columns.

func (*Matrix) Equal

func (m *Matrix) Equal(b *Matrix) bool

Equal reports whether a and b have the same shape and identical entries.

func (*Matrix) FrobeniusNorm

func (m *Matrix) FrobeniusNorm() float64

FrobeniusNorm returns the square root of the sum of squared entries.

func (*Matrix) IsAntisymmetric

func (m *Matrix) IsAntisymmetric(tol float64) bool

IsAntisymmetric reports whether m equals the negative of its transpose within tolerance tol (a real antisymmetric/skew matrix).

func (*Matrix) IsDiagonal

func (m *Matrix) IsDiagonal(tol float64) bool

IsDiagonal reports whether all off-diagonal entries vanish within tol.

func (*Matrix) IsSquare

func (m *Matrix) IsSquare() bool

IsSquare reports whether the matrix has equal row and column counts.

func (*Matrix) IsSymmetric

func (m *Matrix) IsSymmetric(tol float64) bool

IsSymmetric reports whether m equals its transpose within tolerance tol.

func (*Matrix) IsTraceless

func (m *Matrix) IsTraceless(tol float64) bool

IsTraceless reports whether the trace is zero within tolerance tol.

func (*Matrix) Kronecker

func (m *Matrix) Kronecker(b *Matrix) *Matrix

Kronecker returns the Kronecker (tensor) product m ⊗ b.

func (*Matrix) MatVec

func (m *Matrix) MatVec(x []float64) ([]float64, error)

MatVec returns the matrix-vector product m*x or ErrDim on a mismatch.

func (*Matrix) MaxAbs

func (m *Matrix) MaxAbs() float64

MaxAbs returns the largest absolute entry, or 0 for an empty matrix.

func (*Matrix) Mul

func (m *Matrix) Mul(b *Matrix) (*Matrix, error)

Mul returns the matrix product m*b or ErrDim if the inner dimensions disagree.

func (*Matrix) Neg

func (m *Matrix) Neg() *Matrix

Neg returns the additive inverse of the matrix.

func (*Matrix) Row

func (m *Matrix) Row(i int) []float64

Row returns a copy of row i.

func (*Matrix) Scale

func (m *Matrix) Scale(s float64) *Matrix

Scale returns the matrix multiplied by the scalar s.

func (*Matrix) Set

func (m *Matrix) Set(i, j int, v float64)

Set assigns v to element (i,j). It panics if the index is out of range.

func (*Matrix) Sub

func (m *Matrix) Sub(b *Matrix) (*Matrix, error)

Sub returns m-b or ErrDim on a shape mismatch.

func (*Matrix) Symmetrize

func (m *Matrix) Symmetrize() (*Matrix, error)

Symmetrize returns (m+mᵀ)/2, the symmetric part of a square matrix.

func (*Matrix) Trace

func (m *Matrix) Trace() (float64, error)

Trace returns the sum of the diagonal entries. It returns ErrNotSquare for a non-square matrix.

func (*Matrix) Transpose

func (m *Matrix) Transpose() *Matrix

Transpose returns the transpose of the matrix.

func (*Matrix) Vec

func (m *Matrix) Vec() []float64

Vec flattens the matrix into a single row-major slice (a fresh copy).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL