Overview
Overview
The DiracMatrix package (Github link) constructs Dirac gamma matrices that satisfy the Clifford anticommutation relation for an arbitrary real symmetric metric in any dimension. It uses the Brauer–Weyl (Pauli–Kronecker) construction in flat space and extends to curved/non-flat metrics through a vielbein decomposition. It also exposes basis transformations into the Dirac and Weyl/chiral representations and two implementations of the canonical graded Clifford operator basis.
The package source lives at Kernel/DiracMatrix.wl. The exported public symbols are GammaMatrices, EuclideanGammaMatrices, FlatMetric, RandomCurvedMetric, MetricVielbein, ToDiracBasis, ToWeylBasis, NumericZeroQ, CliffordCanonicalBasis, and CliffordBasis.
Mathematical background
Mathematical background
Clifford relation
Clifford relation
The defining property of the Dirac gamma matrices is the Clifford anticommutation relation:
{,}=+=2
μ
γ
ν
γ
μ
γ
ν
γ
ν
γ
μ
γ
μν
η
N
where N = 2^Floor[n/2] is the spinor dimension for an n-dimensional spacetime.
Brauer-Weyl (Pauli-Kronecker) representation
Brauer-Weyl (Pauli-Kronecker) representation
For n = 2m or n = 2m + 1, a flat-space realisation in terms of Pauli matrices σ_j is:
2k-1
Γ
⊗(k-1)
σ
1
⊗(m-k)
σ
3
2k
Γ
⊗(k-1)
σ
2
⊗(m-k)
σ
3
and, for odd n, an additional
2m+1
Γ
⊗m
σ
3
Signed-diagonal metric
Signed-diagonal metric
For a flat metric = diag(+1, ..., +1, -1, ..., -1) with p positive entries and q negative entries, the gamma matrices are:
η
μν
μ
γ
μ
Γ
μμ
η
μ
γ
μ
Γ
μμ
η
The resulting algebra is Cl(p, q).
Vielbein construction for general metrics
Vielbein construction for general metrics
For a general real symmetric metric g, a vielbein (x) is computed such that = (equivalently g = · η · e), and:
a
e
μ
g
μν
a
e
μ
b
e
ν
η
ab
T
e
μ
γ
μ
e
a
a
Γ
where η is the signature matrix and Γ^a are the flat-space gamma matrices in the orthonormal frame.
Loading the package
Loading the package
PacletDirectoryLoad["path/DiracMatrixPackage"];Needs["DiracMatrix`"]
Function reference
Function reference
List of public symbols:
In[]:=
?DiracMatrix`*
Out[]=
Selected usage messages:
In[]:=
?GammaMatrices
Out[]=
In[]:=
?EuclideanGammaMatrices
Out[]=
In[]:=
?FlatMetric
Out[]=
In[]:=
?RandomCurvedMetric
Out[]=
In[]:=
?MetricVielbein
Out[]=
In[]:=
?ToDiracBasis
Out[]=
In[]:=
?ToWeylBasis
Out[]=
In[]:=
?CliffordBasis
Out[]=
In[]:=
?CliffordCanonicalBasis
Out[]=
In[]:=
?NumericZeroQ
Out[]=
Examples
Examples
Euclidean space (n = 4)
Euclidean space (n = 4)
In Euclidean space the metric is the identity and the gamma matrices coincide with the flat-space Γ matrices.
In[]:=
MatrixForm/@GammaMatrices[4]
Out[]=
,
,
,
0 | 0 | 1 | 0 |
0 | 0 | 0 | -1 |
1 | 0 | 0 | 0 |
0 | -1 | 0 | 0 |
0 | 0 | - | 0 |
0 | 0 | 0 | |
| 0 | 0 | 0 |
0 | - | 0 | 0 |
0 | 1 | 0 | 0 |
1 | 0 | 0 | 0 |
0 | 0 | 0 | 1 |
0 | 0 | 1 | 0 |
0 | - | 0 | 0 |
| 0 | 0 | 0 |
0 | 0 | 0 | - |
0 | 0 | | 0 |
Minkowski space (1, 3)
Minkowski space (1, 3)
The mostly-minus Minkowski metric. By default the result is in the Brauer-Weyl basis.
In[]:=
MatrixForm@FlatMetric[1,3]
Out[]//MatrixForm=
1 | 0 | 0 | 0 |
0 | -1 | 0 | 0 |
0 | 0 | -1 | 0 |
0 | 0 | 0 | -1 |
In[]:=
MatrixForm/@GammaMatrices[ηMink]
Out[]=
GammaMatrices[ηMink]
Split signature (2, 2)
Split signature (2, 2)
Used in twistor theory and some lower-dimensional supersymmetric models.
In[]:=
MatrixForm/@GammaMatrices[FlatMetric[2,2]]
Out[]=
,
,
,
0 | 0 | 1 | 0 |
0 | 0 | 0 | -1 |
1 | 0 | 0 | 0 |
0 | -1 | 0 | 0 |
0 | 0 | - | 0 |
0 | 0 | 0 | |
| 0 | 0 | 0 |
0 | - | 0 | 0 |
0 | | 0 | 0 |
| 0 | 0 | 0 |
0 | 0 | 0 | |
0 | 0 | | 0 |
0 | 1 | 0 | 0 |
-1 | 0 | 0 | 0 |
0 | 0 | 0 | 1 |
0 | 0 | -1 | 0 |
Six-dimensional Euclidean
Six-dimensional Euclidean
The construction extends to any dimension; for n = 6 we obtain six 8x8 matrices.
Schwarzschild metric at r = 3M
Schwarzschild metric at r = 3M
Evaluate the Schwarzschild metric components on the equatorial plane at r = 3M, giving diag(-1/3, 3, 9, 9).
FLRW metric with scale factor a = 2
FLRW metric with scale factor a = 2
A spatially-flat FLRW slice with a = 2.
Random non-diagonal metric
Random non-diagonal metric
A random real symmetric non-diagonal metric of signature (2, 2). The vielbein decomposition handles the general case.
Basis transformations
Basis transformations
Brauer-Weyl basis (default output of GammaMatrices)
Brauer-Weyl basis (default output of GammaMatrices)
In[]:=
MatrixForm /@ GammaMatrices[FlatMetric[1, 3]]
Dirac basis
Dirac basis
Weyl/chiral basis
Weyl/chiral basis
The Weyl basis block-diagonalises the chirality operator.
For odd dimension there is no Weyl/chiral decomposition; the function emits a message and returns the Dirac basis instead.
Verification of standard identities
Verification of standard identities
Each test below evaluates to True if the identity is satisfied for the listed range. For non-flat metrics, equality is checked numerically with NumericZeroQ.
Number of matrices and spinor dimension
Number of matrices and spinor dimension
There are n gamma matrices, each of size 2^Floor[n/2] x 2^Floor[n/2].
Tracelessness
Tracelessness
Anticommutator (Clifford relation)
Anticommutator (Clifford relation)
Square of a single gamma
Square of a single gamma
Trace of two gammas
Trace of two gammas
Trace of four gammas
Trace of four gammas
Contraction identities
Contraction identities
Commutator identity
Commutator identity
Chirality (even dimension)
Chirality (even dimension)
It is Hermitian, squares to the identity, and anticommutes with every gamma.
Non-flat metrics
Non-flat metrics
The same identities hold for arbitrary real symmetric metrics; numerical equality is checked with NumericZeroQ.
Canonical Clifford operator basis
Canonical Clifford operator basis
The grade-k element of the canonical Clifford operator basis is the antisymmetrised product
Direct evaluation
Direct evaluation
CliffordCanonicalBasis is a literal transcription of the formula above. It is pedagogically transparent but combinatorially expensive, and on non-flat metrics it can lose precision at high grades because of cancellations between terms of widely different magnitudes.
Antisymmetric recursion (production-ready)
Antisymmetric recursion (production-ready)
CliffordBasis grows the basis grade-by-grade using the recursion
This avoids the explicit antisymmetrisation sum and is much more numerically stable. For flat metrics it agrees with CliffordCanonicalBasis at all grades.
Drift on non-flat metrics at high grade
Drift on non-flat metrics at high grade
For random non-flat metrics the two implementations agree at low grades but the explicit antisymmetrisation accumulates error at grades ≥ 4.
The mismatch at higher grades reflects numerical cancellation in the explicit-sum implementation, not an algebraic disagreement; prefer CliffordBasis in production.
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Dirac matrices in a curved spacetime
by Mohammad Bahrami
Wolfram Community, STAFF PICKS, May 2, 2026
https://community.wolfram.com/groups/-/m/t/3710334
by Mohammad Bahrami
Wolfram Community, STAFF PICKS, May 2, 2026
https://community.wolfram.com/groups/-/m/t/3710334