{
  "id": "tensor-contraction",
  "title": "Tensor Contraction",
  "lang": "en",
  "source_lang": "en",
  "summary": "Tensor contraction pairs compatible tensor indices and sums over them, generalizing evaluation, matrix trace, and matrix multiplication.",
  "category": "mathematics",
  "subcategory": "algebra",
  "type": "concept",
  "aliases": [
    "Contraction of tensors",
    "Index contraction"
  ],
  "generated_at": "2026-10-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/tensor-contraction/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/tensor-contraction/",
      "json": "https://aiwiki.page/zh/tensor-contraction.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "Tensor contraction is an operation on a tensor that pairs a vector-space factor with a corresponding dual-space factor, removing both through evaluation. In coordinates, it identifies two compatible indices and sums over their common range. It generalizes familiar operations in linear algebra, including matrix trace and matrix multiplication. In numerical computing, the term also denotes multiplying multidimensional arrays and summing over specified matching axes. (elliptic.space)"
    },
    {
      "heading": "Coordinate-free definition",
      "text": "Let \\(V\\) be a finite-dimensional vector space over a field \\(\\mathbb F\\). Its dual space \\(V^*\\) consists of linear functionals \\(\\alpha:V\\to\\mathbb F\\). The canonical evaluation pairing induces a linear map\n\n\\[C:V^*\\otimes V\\longrightarrow\\mathbb F, \\qquad C(\\alpha\\otimes v)=\\alpha(v).\\]\n\nIts existence follows from the universal property of the tensor product: evaluation is bilinear, so it extends uniquely to a linear map on the product space. No metric or choice of coordinates is required. (elliptic.space)\n\nFor a mixed tensor\n\n\\[T\\in V^{\\otimes p}\\otimes(V^*)^{\\otimes q},\\]\n\ncontracting one \\(V\\) factor with one \\(V^*\\) factor produces a tensor of type \\((p-1,q-1)\\). On an elementary tensor, the selected vector and functional are replaced by the scalar obtained by evaluation; the remaining factors retain their order. Extending linearly defines the operation for arbitrary tensors. Each such contraction therefore reduces total tensor order by two. Here “order,” sometimes called tensor rank, counts factors and must not be confused with matrix rank. (maths.ed.ac.uk)"
    },
    {
      "heading": "Index notation and invariance",
      "text": "Choose a basis \\(e_1,\\ldots,e_n\\) and its dual basis \\(e^1,\\ldots,e^n\\), satisfying \\(e^i(e_j)=\\delta^i_j\\). A type-\\((2,2)\\) tensor has components \\(T^{ab}{}_{cd}\\). Contracting its second upper index with its first lower index gives\n\n\\[S^a{}_d=\\sum_{i=1}^{n}T^{ai}{}_{id}.\\]\n\nThe indices \\(a,d\\) are free indices, describing the output; \\(i\\) is a dummy index used only for summation. Renaming a dummy index does not alter the result. (maths.ed.ac.uk)\n\nUnder the Einstein summation convention, the summation sign is omitted when an index occurs once upstairs and once downstairs. The opposite transformation laws of these two indices cancel when they are paired, ensuring that contraction is independent of the chosen basis. An expression with free indices remains a tensor, while a fully contracted expression is a scalar. Coordinate independence does not imply that the components of a partially contracted tensor remain numerically unchanged under a basis transformation. (maths.ed.ac.uk)"
    },
    {
      "heading": "Familiar examples",
      "text": "Evaluation of a covector on a vector is the simplest example:\n\n\\[\\alpha(v)=\\alpha_i v^i.\\]\n\nFor an endomorphism \\(A:V\\to V\\), contracting its two indices gives the matrix trace,\n\n\\[\\operatorname{tr}A=A^i{}_i.\\]\n\nThus trace is intrinsically an operation on a linear operator, not merely a rule for adding diagonal entries of a displayed matrix. (elliptic.space)\n\nMatrix multiplication is a contraction of a tensor product:\n\n\\[(AB)^i{}_k=\\sum_j A^i{}_jB^j{}_k.\\]\n\nThe shared index \\(j\\) disappears, while \\(i,k\\) remain. Similarly, multiplying a matrix by a vector contracts the matrix’s input index with the vector index. These examples distinguish contraction from an outer product, which retains all input indices, and from componentwise multiplication, which alone performs no summation. (elliptic.space)"
    },
    {
      "heading": "Contraction with a metric",
      "text": "Canonical contraction pairs opposite index types. Pairing two upper indices, or two lower indices, requires additional structure. A nondegenerate metric tensor \\(g\\) identifies vectors with covectors, permitting indices to be lowered or raised. For vectors \\(u,v\\),\n\n\\[g(u,v)=g_{ij}u^iv^j.\\]\n\nFor a covariant two-tensor \\(A_{ij}\\), its metric trace is\n\n\\[g^{ij}A_{ij},\\]\n\nwhere \\(g^{ij}\\) represents the inverse metric. These expressions combine metric insertion with canonical contractions. (damtp.cam.ac.uk)\n\nIn a real inner-product space with an orthonormal basis, \\(g_{ij}=\\delta_{ij}\\), making metric contraction look like ordinary matching-index summation. This simplification is basis-dependent. In differential geometry, contraction acts pointwise on tensor fields. The Ricci tensor is obtained by contracting the Riemann curvature tensor, and contracting the Ricci tensor with the inverse metric gives scalar curvature. Both constructions enter general relativity. (damtp.cam.ac.uk)"
    },
    {
      "heading": "Arrays and computational notation",
      "text": "Array libraries generally encode axis lengths rather than geometric distinctions between covariant and contravariant indices. For arrays \\(A_{ijk}\\) and \\(B_{jkl}\\), a two-axis contraction is\n\n\\[C_{il}=\\sum_{j,k}A_{ijk}B_{jkl}.\\]\n\nEach paired axis must have matching length. If the operands have orders \\(r,s\\) and \\(m\\) axis pairs are contracted, the output has order \\(r+s-2m\\). These array operations implement coordinate formulas; their geometric meaning depends on how the arrays represent tensors. (numpy.org)\n\nNumPy’s einsum expresses the example as einsum('ijk,jkl->il', A, B). Its notation also distinguishes a trace, 'ii->', from diagonal extraction, 'ii->i': repeated labels do not necessarily imply summation when explicitly retained in the output. (numpy.org)"
    },
    {
      "heading": "Tensor networks and contraction order",
      "text": "A tensor network represents tensors as nodes and contracted indices as connecting edges. Unconnected edges correspond to free output indices; a network without free edges evaluates to a scalar. Such representations support calculations of wave-function norms and observable expectation values in quantum mechanics. Classical statistical mechanics also uses network contractions to evaluate partition functions. (arxiv.org)\n\nAlthough exact arithmetic gives the same result for equivalent contraction orders, intermediate tensor sizes and operation counts can differ substantially. Choosing which tensors to combine first is therefore an important algorithmic problem. Large networks may require approximate contraction, replacing growing intermediate tensors with compressed representations. Such approximations introduce truncation error, distinct from the exact contraction operation itself. (arxiv.org)"
    }
  ],
  "links": [
    "tensor",
    "linear-algebra",
    "vector-space",
    "field-mathematics",
    "dual-space",
    "linear-functional",
    "linear-map",
    "universal-property",
    "tensor-product",
    "matrix-rank",
    "basis-linear-algebra",
    "einstein-summation-convention",
    "matrix-trace",
    "matrix",
    "metric-tensor",
    "inner-product",
    "orthonormal-basis",
    "differential-geometry",
    "tensor-field",
    "riemann-curvature-tensor",
    "general-relativity",
    "tensor-network",
    "quantum-mechanics",
    "statistical-mechanics",
    "partition-function",
    "algorithm"
  ],
  "sources": [
    {
      "title": "Linear Algebra and Quantum Information, Section 9.4: Contractions and Trace",
      "url": "https://elliptic.space/book/linalgqi0_8.pdf"
    },
    {
      "title": "Riemannian Manifolds: An Introduction to Curvature",
      "url": "https://www.maths.ed.ac.uk/~v1ranick/papers/leeriemm.pdf"
    },
    {
      "title": "Lecture 3: Tensors Continued",
      "url": "https://ocw.mit.edu/courses/8-962-general-relativity-spring-2020/resources/lecture-3-tensors-continued/"
    },
    {
      "title": "numpy.einsum — NumPy v2.1 Manual",
      "url": "https://numpy.org/doc/2.1/reference/generated/numpy.einsum.html"
    },
    {
      "title": "numpy.tensordot — NumPy Manual",
      "url": "https://numpy.org/doc/stable/reference/generated/numpy.tensordot.html?highlight=tensordot"
    },
    {
      "title": "A Practical Introduction to Tensor Networks: Matrix Product States and Projected Entangled Pair States",
      "url": "https://arxiv.org/abs/1306.2164"
    },
    {
      "title": "Lecture Notes of Tensor Network Contractions",
      "url": "https://arxiv.org/abs/1708.09213"
    }
  ],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}