Skip to content
QFT.org

Search QFT.org

Enter a word or phrase.

    You can also browse the main navigation and chapter contents.

    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 PμP^\mu, its covector as Pμ=ημνPνP_\mu=\eta_{\mu\nu}P^\nu, and their contraction as PμQμP^\mu Q_\mu. A Lorentz index and a color index belong to different vector spaces even when both are printed as ii. 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,

    PμQνημν=PρQσηρσ=PμQμ.P^\mu Q^\nu\eta_{\mu\nu} =P^\rho Q^\sigma\eta_{\rho\sigma} =P^\mu Q_\mu.

    These are the same expression. By contrast, replacing both dummy names by μ\mu 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 diag⁡(1,−1,−1,−1)\operatorname{diag}(1,-1,-1,-1) explicitly. Then P=(2,1,0,0)P=(2,1,0,0) and Q=(3,0,1,0)Q=(3,0,1,0) give P⋅Q=6P\cdot Q=6. A Euclidean array would describe a different contraction. The dimension is also separate: ημνηνμ=4\eta^{\mu\nu}\eta_{\nu\mu}=4, whereas the sum of the four displayed diagonal entries of η\eta is −2-2. 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

    ϕ(p)+γ(k,ε)⟶ϕ(p′)+γ(k′,ε′),p+k=p′+k′,\phi(p)+\gamma(k,\varepsilon)\longrightarrow \phi(p')+\gamma(k',\varepsilon'),\qquad p+k=p'+k',

    with p2=p′2=m2>0p^2=p'^2=m^2>0, k2=k′2=0k^2=k'^2=0 and future-pointing momenta. Put a=p⋅ka=p\cdot k, b=p⋅k′b=p\cdot k'. The final scalar mass shell implies

    k⋅k′=a−b,p′⋅k=b,p′⋅k′=a.k\cdot k'=a-b,\qquad p'\cdot k=b,\qquad p'\cdot k'=a.

    One exact representation uses the basis (p,k,k′)(p,k,k') and its Gram matrix:

    G=(m2aba0a−bba−b0).G= \begin{pmatrix} m^2&a&b\\ a&0&a-b\\ b&a-b&0 \end{pmatrix}.

    Thus the dot product of vectors with coefficient columns u,vu,v is uTGvu^TGv. Momentum conservation is the coefficient identity p′=p+k−k′p'=p+k-k'. 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 44 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 q=+eq=+e in Dμ=∂μ−ieAμD_\mu=\partial_\mu-ieA_\mu. Expanding the kinetic term gives

    Lint=ieAμ(ϕ∗∂μϕ−(∂μϕ∗)ϕ)+e2AμAμϕ∗ϕ.\mathcal L_{\rm int} =ieA_\mu\bigl(\phi^*\partial^\mu\phi -(\partial^\mu\phi^*)\phi\bigr) +e^2A_\mu A^\mu\phi^*\phi.

    With scalar-line momenta p,p′p,p' following the charge arrow, the one-photon vertex is +ie(p+p′)μ+ie(p+p')^\mu; the two identical photon fields give +2ie2ημν+2ie^2\eta^{\mu\nu}. These are the charge-translated rules in Tong, §6.5.1, Eq. (6.585) and the following vertices; his cubic rule uses q=−eq=-e.

    Define S=1+i(2π)4δ(4)(p+k−p′−k′)MS=1+i(2\pi)^4\delta^{(4)}(p+k-p'-k')\mathcal M. The complete tree amplitude is

    M=e2εμεν′∗Tμν,\mathcal M=e^2\varepsilon_\mu\varepsilon_\nu'^*T^{\mu\nu}, Tμν=2ημν−(2p+k)μ(2p′+k′)ν2a+(2p′−k)μ(2p−k′)ν2b.T^{\mu\nu} =2\eta^{\mu\nu} -\frac{(2p+k)^\mu(2p'+k')^\nu}{2a} +\frac{(2p'-k)^\mu(2p-k')^\nu}{2b}.

    The last plus is the exchange minus divided by the negative denominator −2b-2b. Each exchange minus follows from (ie)2i=−ie2(ie)^2i=-ie^2 in iMi\mathcal M. The original scalar propagators have their Feynman +i0+i0 boundary values; for this physical domain a,b>0a,b>0 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 k⋅(2p+k)=2ak\cdot(2p+k)=2a and k⋅(2p′−k)=2bk\cdot(2p'-k)=2b:

    kμTμν=2kν−(2p′+k′)ν+(2p−k′)ν=2(p+k−p′−k′)ν=0.k_\mu T^{\mu\nu} =2k^\nu-(2p'+k')^\nu+(2p-k')^\nu =2(p+k-p'-k')^\nu=0.

    For the outgoing index, k′⋅(2p′+k′)=2ak'\cdot(2p'+k')=2a and k′⋅(2p−k′)=2bk'\cdot(2p-k')=2b, hence

    Tμνkν′=2k′μ−(2p+k)μ+(2p′−k)μ=0.T^{\mu\nu}k'_\nu =2k'^\mu-(2p+k)^\mu+(2p'-k)^\mu=0.

    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 (μ,ν)(\mu,\nu) and once with (ρ,σ)(\rho,\sigma). After metric contraction and canonicalization the expressions agree exactly. A rational rotation and transverse boost of an exact event gives the same component contraction, M/e2=−6/5\mathcal M/e^2=-6/5. 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 ω/m=0.05,0.4,1,3\omega/m=0.05,0.4,1,3, rest-frame cosines −0.8,−0.2,0.4,0.8-0.8,-0.2,0.4,0.8, two frames, two gauge representatives and all four pairs of real photon polarizations. Its selected absolute residuals are:

    CheckLargest residual
    Either tensor Ward contraction8.0×10−158.0\times10^{-15}
    Tensor versus separately contracted diagrams3.4×10−143.4\times10^{-14}
    Diagrams versus the projected-polarization form2.9×10−142.9\times10^{-14}
    Physical polarization sum versus analytic result3.0×10−143.0\times10^{-14}

    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 ∣M∣2‾/e4=2(1+cos⁡2θ)\overline{|\mathcal M|^2}/e^4=2(1+\cos^2\theta). 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 −2k-2k and −2k′-2k'. 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, A=σxA=\sigma_x, B=σzB=\sigma_z satisfy AB=−BAAB=-BA, so

    (A+B)2=A2+AB+BA+B2=2I,(A+B)^2=A^2+AB+BA+B^2=2I,

    whereas replacing AB+BAAB+BA by 2AB2AB 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 Vν=(AμBμ)CνV^\nu=(A^\mu B_\mu)C^\nu, explain why renaming μ\mu to ν\nu is illegal. Repair the renaming and evaluate VV for A=(2,1,0,0)A=(2,1,0,0), B=(3,0,1,0)B=(3,0,1,0), C=(1,2,0,0)C=(1,2,0,0). Also evaluate ημνηνμ\eta^{\mu\nu}\eta_{\nu\mu}.

    Solution

    The free ν\nu 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 Vν=(AρBρ)CνV^\nu=(A^\rho B_\rho)C^\nu. With the mostly-minus metric, A⋅B=2(3)−1(0)=6A\cdot B=2(3)-1(0)=6, so V=(6,12,0,0)V=(6,12,0,0). For the trace, first contract one metric: ημνηνρ=δμρ\eta^{\mu\nu}\eta_{\nu\rho}=\delta^\mu{}_\rho. Setting ρ=μ\rho=\mu and summing gives 44. 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 k=ω(1,0,0,1)k=\omega(1,0,0,1) and an outgoing photon in the xzxz plane. Explain why the outgoing yy polarization can hide the error, and evaluate the residual with the in-plane polarization for ω=0.7\omega=0.7, sin⁡θ=0.8\sin\theta=0.8.

    Solution

    Since the complete tensor has zero contraction and the omitted term is 2ημν2\eta^{\mu\nu}, the incomplete tensor has kμTincompleteμν=−2kνk_\mu T_{\rm incomplete}^{\mu\nu}=-2k^\nu. For εy′=(0,0,1,0)\varepsilon'_y=(0,0,1,0), k⋅εy′=0k\cdot\varepsilon'_y=0, so this particular longitudinal replacement gives zero even with the wrong graph set. For ε∥′=(0,cos⁡θ,0,−sin⁡θ)\varepsilon'_\parallel=(0,\cos\theta,0,-\sin\theta), k⋅ε∥′=ωsin⁡θk\cdot\varepsilon'_\parallel=\omega\sin\theta. The amplitude residual is therefore −2e2ωsin⁡θ=−1.12e2-2e^2\omega\sin\theta=-1.12e^2. 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.