- Home
- Library
- Computational Quantum Field Theory
- From a Lagrangian to Executable Amplitudes
- Tensor and Index Algebra by Computer
Tensor and Index Algebra by Computer
If replacing a photon polarization by its momentum fails to give zero, is the physics wrong, or did the program contract the wrong indices? A useful symbolic calculation keeps enough information to distinguish those failures. The computer needs index spaces, variance, summation scope and multiplication order, not merely a string containing Greek letters.
Preparation: Lorentz contractions, tree Feynman rules and Compton gauge invariance. That linked example has an electron; this page uses a charged scalar, whose two-photon contact vertex is essential. We use the mostly-minus conventions in four dimensions.
Indices have types and scope
Represent a vector as , its covector as , and their contraction as . A Lorentz index and a color index belong to different vector spaces even when both are printed as . A valid contraction pairs compatible spaces and opposite variance; a free index occurs once in each term, while a dummy occurs twice. Renaming a dummy must not capture a free index or another summation.
For example,
These are the same expression. By contrast, replacing both dummy names by in the first expression is not a legal renaming: the resulting index would occur four times. Canonicalization chooses a representative of the legal equivalence class; it does not make an ill-formed contraction meaningful.
A minimal implementation with SymPy's abstract tensor objects is:
from sympy.tensor.tensor import (
TensorIndexType, TensorHead, tensor_indices,
)
L = TensorIndexType("Lorentz", dim=4, dummy_name="ell")
mu, nu = tensor_indices("mu nu", L)
P, Q = TensorHead("P", [L]), TensorHead("Q", [L])
expr = P(mu) * Q(nu) * L.metric(-mu, -nu)
reduced = expr.contract_metric(L.metric).canon_bp()
The minus on an index denotes lower variance, not a negative component. The declared symmetric metric alone does not choose Lorentzian signature. For a component check, supply explicitly. Then and give . A Euclidean array would describe a different contraction. The dimension is also separate: , whereas the sum of the four displayed diagonal entries of is . See the actual TensorIndexType, TensorIndex and array-replacement documentation.
Momentum identities are additional algebra
Dummy renaming and metric contraction know nothing about external mass shells. For scalar Compton scattering, define
with , and future-pointing momenta. Put , . The final scalar mass shell implies
One exact representation uses the basis and its Gram matrix:
Thus the dot product of vectors with coefficient columns is . Momentum conservation is the coefficient identity . These rules form an explicitly on-shell algebra. Applying the same Gram matrix to arbitrary off-shell vectors would change the problem.
Keep generic dimensionally regulated tensor identities separate from this four-component array calculation. Substituting for a regulated dimension before a pole multiplies it can lose a finite contribution; the Dirac and color article treats that distinction.
Build the scalar-QED tensor
Choose the representation charge in . Expanding the kinetic term gives
With scalar-line momenta following the charge arrow, the one-photon vertex is ; the two identical photon fields give . These are the charge-translated rules in Tong, §6.5.1, Eq. (6.585) and the following vertices; his cubic rule uses .
Define . The complete tree amplitude is
The last plus is the exchange minus divided by the negative denominator . Each exchange minus follows from in . The original scalar propagators have their Feynman boundary values; for this physical domain and no internal pole is encountered. The Lorentz product is bilinear even for complex polarization vectors. Conjugate the outgoing polarization once; do not conjugate every first argument of a dot product.
Reduce twice, then test the physics
Contract the incoming index using and :
For the outgoing index, and , hence
The accompanying calculation checks these two coefficient-vector identities in the Gram algebra. Separately, it constructs the full amplitude as a typed tensor expression, once with dummies and once with . After metric contraction and canonicalization the expressions agree exactly. A rational rotation and transverse boost of an exact event gives the same component contraction, . This array test exercises nonzero time components; it is not confined to a scalar-rest-frame gauge in which the exchange graphs happen to vanish.
The numerical scan uses , rest-frame cosines , two frames, two gauge representatives and all four pairs of real photon polarizations. Its selected absolute residuals are:
| Check | Largest residual |
|---|---|
| Either tensor Ward contraction | |
| Tensor versus separately contracted diagrams | |
| Diagrams versus the projected-polarization form | |
| Physical polarization sum versus analytic result |
There are 256 polarized amplitudes. The last test averages over the two incoming photon polarizations and sums over the two outgoing ones. In the scalar rest frame it gives . A contraction of the complete tensor with two covariant polarization sums agrees as well. Ward identities justify that replacement; individual diagrams do not define separate covariant probabilities.
Two deliberate failures distinguish the checks from a self-consistency test. Omitting the contact term leaves Ward vectors and . An off-shell input violates the assumed Gram relation and gives a nonzero Ward residual. Neither result is suppressed by loosening a tolerance.
Run the exact and numerical checks with:
python3 examples/computational-qft/symbolic-computation/tensor_index_checks.py
The readable kernel is scalar_compton.py; the selected output is tensor-index-results.json.
Products can carry an order
Scalar momentum components commute. Gamma matrices and color matrices generally do not. For example, , satisfy , so
whereas replacing by gives the wrong matrix. Store an ordered chain or use objects with declared noncommutative multiplication. Index contraction does not authorize reordering factors inside that chain. SymPy's TensorHead defaults to commuting tensors; its commutation group must be changed when the represented objects require it. Its canonicalizer handles declared permutation symmetries, not every possible multiterm identity. Those boundaries are explicit in the TensorHead and canon_bp documentation.
Summary
Typed indices prevent illegal contractions, canonicalization removes dummy-name ambiguity, and an explicitly declared momentum algebra supplies the mass-shell identities. Scalar Compton scattering checks all three layers: both exchange graphs and the contact graph are needed for the two Ward identities. The next step is numerical simplification, where exact equivalence alone does not guarantee accurate floating-point output.
Exercises
1. Rename without capturing a free index
For , explain why renaming to is illegal. Repair the renaming and evaluate for , , . Also evaluate .
Solution
The free labels the output vector. Reusing it as the scalar product's dummy makes it occur three times and changes its scope. A fresh name gives . With the mostly-minus metric, , so . For the trace, first contract one metric: . Setting and summing gives . The result counts dimensions, not the positive minus negative entries of a displayed metric matrix.
2. An incomplete amplitude that passes one test
Delete the seagull. Derive the incoming Ward residual. In the scalar rest frame take and an outgoing photon in the plane. Explain why the outgoing polarization can hide the error, and evaluate the residual with the in-plane polarization for , .
Solution
Since the complete tensor has zero contraction and the omitted term is , the incomplete tensor has . For , , so this particular longitudinal replacement gives zero even with the wrong graph set. For , . The amplitude residual is therefore . A vector Ward identity, or a sufficiently discriminating set of contractions, detects the missing term.
References
- SymPy 1.14 documentation, Tensor, TensorIndexType, TensorIndex, TensorHead, replace_with_arrays, contract_metric and canon_bp: API and examples.
- D. Tong, Quantum Field Theory, §6.5.1, Eq. (6.585) and scalar-QED vertices: HTML lecture notes.
Scrollable formula. Use Left and Right arrow keys to reveal hidden content.
Scrollable table. Use Left and Right arrow keys to reveal hidden columns.
Scrollable figure. Use Left and Right arrow keys to reveal hidden content.