{
  "id": "dot-product",
  "title": "Dot product",
  "lang": "en",
  "source_lang": "en",
  "summary": "The dot product multiplies two Euclidean vectors to produce a scalar encoding their lengths, relative direction, and orthogonality.",
  "category": "mathematics",
  "subcategory": "algebra",
  "type": "concept",
  "aliases": [
    "Scalar product",
    "Euclidean inner product",
    "Standard inner product"
  ],
  "generated_at": "2026-11-02",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/dot-product/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/dot-product/",
      "json": "https://aiwiki.page/zh/dot-product.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "The dot product is an operation that takes two vectors in Euclidean space and returns a real number. In Cartesian coordinates, it is the sum of the products of corresponding components:\n\n\\[\\mathbf a\\cdot\\mathbf b=\\sum_{i=1}^{n}a_i b_i.\\]\n\nGeometrically, the same operation satisfies\n\n\\[\\mathbf a\\cdot\\mathbf b=\\|\\mathbf a\\|\\,\\|\\mathbf b\\|\\cos\\theta,\\]\n\nwhere \\(\\theta\\) is the angle between two nonzero vectors. These equivalent descriptions connect coordinate calculation with length, angle, and perpendicularity.\n\nThe dot product is fundamental to linear algebra, geometry, and physics. It determines projections and distances, expresses mechanical work, and underlies least-squares fitting, statistical correlation, and many machine-learning calculations. It is also the standard example of an inner product, a broader mathematical structure that extends Euclidean ideas to abstract vector spaces and spaces of functions."
    },
    {
      "heading": "Definition, notation, and historical development",
      "text": "For vectors \\(\\mathbf a=(a_1,\\ldots,a_n)\\) and \\(\\mathbf b=(b_1,\\ldots,b_n)\\) in \\(\\mathbb R^n\\), their dot product is\n\n\\[\\mathbf a\\cdot\\mathbf b=a_1b_1+\\cdots+a_nb_n.\\]\n\nEach component is a real number, and the output is also real. The vectors must belong to the same coordinate space: the formula pairs each component of one vector with the corresponding component of the other. For example,\n\n\\[(2,-1,3)\\cdot(4,5,-2)=8-5-6=-3.\\]\n\nThe negative result describes a geometric relationship between the vectors; it does not indicate a negative length. In one dimension, the dot product reduces to ordinary multiplication.\n\nThe word scalar distinguishes the output from a vector. This is different from scalar multiplication, in which a number multiplies a vector to produce another vector. It also distinguishes the dot product from the cross product, whose familiar three-dimensional form produces a vector perpendicular to its two inputs. The dot product exists in every finite dimension and does not require an orientation of space. Common notations include \\(\\mathbf a\\cdot\\mathbf b\\), \\(\\langle\\mathbf a,\\mathbf b\\rangle\\), and, when vectors are columns, \\(\\mathbf a^{\\mathsf T}\\mathbf b\\). Angle brackets are especially common when discussing general inner products.\n\nThe geometric ideas behind the operation predate modern vector notation. The Pythagorean theorem and the cosine rule already express relationships that can be rewritten using dot products. For a triangle whose sides include vectors \\(\\mathbf a\\) and \\(\\mathbf b\\), the cosine rule gives\n\n\\[\\|\\mathbf a-\\mathbf b\\|^2 =\\|\\mathbf a\\|^2+\\|\\mathbf b\\|^2 -2\\|\\mathbf a\\|\\,\\|\\mathbf b\\|\\cos\\theta.\\]\n\nExpanding the left side in Cartesian coordinates produces the coordinate formula for the dot product. This establishes the equivalence of its algebraic and geometric definitions rather than treating them as unrelated rules.\n\nModern vector algebra emerged during the nineteenth century. William Rowan Hamilton introduced quaternions in 1843, and Hermann Grassmann published his extensive algebra in 1844. For pure vector quaternions, Hamilton’s multiplication combines the operations now separated as dot and cross products:\n\n\\[\\mathbf a\\mathbf b=-\\mathbf a\\cdot\\mathbf b+\\mathbf a\\times\\mathbf b.\\]\n\nIn the late nineteenth century, Josiah Willard Gibbs and Oliver Heaviside developed vector methods that separated scalar and vector products for physical applications. Edwin Bidwell Wilson’s 1901 textbook, based on Gibbs’s lectures, helped disseminate this notation and approach. The modern dot product thus belongs to a broader transition from geometric and quaternionic calculation to the vector analysis used in contemporary mathematics and physics."
    },
    {
      "heading": "Algebraic properties and fundamental identities",
      "text": "The dot product is symmetric:\n\n\\[\\mathbf a\\cdot\\mathbf b=\\mathbf b\\cdot\\mathbf a.\\]\n\nIt is also linear in each argument. For real scalars \\(\\alpha,\\beta\\),\n\n\\[(\\alpha\\mathbf a+\\beta\\mathbf b)\\cdot\\mathbf c =\\alpha(\\mathbf a\\cdot\\mathbf c) +\\beta(\\mathbf b\\cdot\\mathbf c),\\]\n\nand an analogous identity holds in the second argument. Together these properties make it a symmetric bilinear operation. They allow an expression involving sums of vectors to be expanded much like a product of polynomials, although the output of each dot product is a scalar.\n\nIts crucial additional property is positive definiteness:\n\n\\[\\mathbf a\\cdot\\mathbf a=\\sum_{i=1}^{n}a_i^2\\geq0,\\]\n\nwith equality exactly when \\(\\mathbf a=\\mathbf0\\). Consequently, the dot product determines the Euclidean norm:\n\n\\[\\|\\mathbf a\\|=\\sqrt{\\mathbf a\\cdot\\mathbf a}.\\]\n\nExpanding the squared norm of a sum gives\n\n\\[\\|\\mathbf a+\\mathbf b\\|^2 =\\|\\mathbf a\\|^2+2\\mathbf a\\cdot\\mathbf b+\\|\\mathbf b\\|^2.\\]\n\nChanging the sign of \\(\\mathbf b\\) and combining the resulting equations yields the parallelogram identity,\n\n\\[\\|\\mathbf a+\\mathbf b\\|^2+\\|\\mathbf a-\\mathbf b\\|^2 =2\\|\\mathbf a\\|^2+2\\|\\mathbf b\\|^2.\\]\n\nThe real polarization identity recovers the dot product from lengths alone:\n\n\\[\\mathbf a\\cdot\\mathbf b =\\frac14\\left(\\|\\mathbf a+\\mathbf b\\|^2 -\\|\\mathbf a-\\mathbf b\\|^2\\right).\\]\n\nThus the Euclidean norm and dot product encode the same geometric information.\n\nThe Cauchy–Schwarz inequality states\n\n\\[|\\mathbf a\\cdot\\mathbf b|\\leq\\|\\mathbf a\\|\\,\\|\\mathbf b\\|.\\]\n\nFor nonzero vectors, equality holds exactly when they are linearly dependent. One proof considers the nonnegative expression\n\n\\[\\|\\mathbf a-t\\mathbf b\\|^2 =\\|\\mathbf a\\|^2-2t(\\mathbf a\\cdot\\mathbf b) +t^2\\|\\mathbf b\\|^2\\]\n\nand minimizes it over real \\(t\\). When \\(\\mathbf b\\neq\\mathbf0\\), the minimizing value is \\(t=(\\mathbf a\\cdot\\mathbf b)/\\|\\mathbf b\\|^2\\); substituting it gives the inequality. Cauchy–Schwarz in turn yields the triangle inequality for the Euclidean norm.\n\nDespite its familiar multiplication symbol, the dot product is not an associative product on vectors. The expression \\((\\mathbf a\\cdot\\mathbf b)\\cdot\\mathbf c\\) is not defined as a dot product because \\(\\mathbf a\\cdot\\mathbf b\\) is a scalar. Even if the second operation is interpreted as scalar multiplication, the resulting vectors need not agree under different groupings. Nor does a zero dot product imply a zero factor: \\((1,0)\\cdot(0,1)=0\\), although both vectors are nonzero. These distinctions are essential when manipulating vector equations."
    },
    {
      "heading": "Angles, orthogonality, and projections",
      "text": "For nonzero vectors, the dot product determines an angle in the interval \\([0,\\pi]\\):\n\n\\[\\theta=\\arccos\\left( \\frac{\\mathbf a\\cdot\\mathbf b}{\\|\\mathbf a\\|\\,\\|\\mathbf b\\|} \\right).\\]\n\nCauchy–Schwarz ensures that the argument lies between \\(-1\\) and \\(1\\). A positive dot product corresponds to an acute angle, zero to a right angle, and a negative value to an obtuse angle. Positive scalar multiples have angle zero, while negative scalar multiples have angle \\(\\pi\\). The zero vector has zero dot product with every vector, but no angle involving it is defined by this formula.\n\nVectors are orthogonal when their dot product is zero. This extends perpendicularity beyond two or three dimensions. For example, \\((1,2,-1)\\) and \\((2,0,2)\\) are orthogonal because \\(2+0-2=0\\). If \\(\\mathbf u\\) and \\(\\mathbf v\\) are orthogonal, expansion of the squared norm gives\n\n\\[\\|\\mathbf u+\\mathbf v\\|^2 =\\|\\mathbf u\\|^2+\\|\\mathbf v\\|^2.\\]\n\nThis is the vector form of the Pythagorean theorem. The set of vectors orthogonal to every vector in a given subspace is its orthogonal complement, a central construction in decomposing Euclidean spaces.\n\nThe signed scalar component of \\(\\mathbf a\\) in the direction of a nonzero vector \\(\\mathbf b\\) is\n\n\\[\\operatorname{comp}_{\\mathbf b}\\mathbf a =\\frac{\\mathbf a\\cdot\\mathbf b}{\\|\\mathbf b\\|}.\\]\n\nThe corresponding orthogonal projection is the vector\n\n\\[\\operatorname{proj}_{\\mathbf b}\\mathbf a =\\frac{\\mathbf a\\cdot\\mathbf b}{\\mathbf b\\cdot\\mathbf b}\\mathbf b.\\]\n\nFor instance, projecting \\((3,4)\\) onto the direction \\((1,1)\\) gives \\((7/2,7/2)\\). The residual is \\((-1/2,1/2)\\), which is orthogonal to \\((1,1)\\). Every vector therefore splits uniquely into a component along a chosen nonzero direction and a component perpendicular to it.\n\nProjection also has a distance-minimizing interpretation. If \\(\\mathbf p\\) is the projection of \\(\\mathbf a\\) onto a subspace and \\(\\mathbf z\\) is any vector in that subspace, then\n\n\\[\\|\\mathbf a-\\mathbf z\\|^2 =\\|\\mathbf a-\\mathbf p\\|^2+\\|\\mathbf p-\\mathbf z\\|^2.\\]\n\nThe second term is nonnegative, so \\(\\mathbf p\\) is the closest point. For a hyperplane defined by \\(\\mathbf n\\cdot\\mathbf x=c\\), where \\(\\mathbf n\\neq\\mathbf0\\), this geometry gives the distance from \\(\\mathbf x_0\\):\n\n\\[\\frac{|\\mathbf n\\cdot\\mathbf x_0-c|}{\\|\\mathbf n\\|}.\\]\n\nThe sign of \\(\\mathbf n\\cdot\\mathbf x_0-c\\) also identifies which side of the hyperplane contains the point."
    },
    {
      "heading": "Coordinate systems and invariance",
      "text": "The component formula \\(\\sum_i a_i b_i\\) assumes that the coordinates are measured in an orthonormal basis: the basis vectors have unit length and are mutually orthogonal. If \\(\\mathbf e_1,\\ldots,\\mathbf e_n\\) is such a basis, then\n\n\\[\\mathbf e_i\\cdot\\mathbf e_j=\\delta_{ij},\\]\n\nwhere \\(\\delta_{ij}\\) is \\(1\\) when \\(i=j\\) and \\(0\\) otherwise. Writing \\(\\mathbf a=\\sum_i a_i\\mathbf e_i\\) and \\(\\mathbf b=\\sum_j b_j\\mathbf e_j\\), bilinearity eliminates all terms with unequal indices and leaves precisely the standard coordinate formula.\n\nThe numerical value of a dot product does not depend on which orthonormal coordinate system is used. If a coordinate change is represented by an orthogonal matrix \\(Q\\), then \\(Q^{\\mathsf T}Q=I\\), and\n\n\\[(Q\\mathbf a)^{\\mathsf T}(Q\\mathbf b) =\\mathbf a^{\\mathsf T}Q^{\\mathsf T}Q\\mathbf b =\\mathbf a^{\\mathsf T}\\mathbf b.\\]\n\nThis covers rotations and reflections. A general invertible transformation does not have this property: stretching one axis changes angles and lengths unless the metric representation is changed as well. Dot-product preservation is therefore more restrictive than invertibility.\n\nIn a nonorthonormal basis \\(\\mathbf e_1,\\ldots,\\mathbf e_n\\), let\n\n\\[G_{ij}=\\mathbf e_i\\cdot\\mathbf e_j.\\]\n\nThe resulting Gram matrix \\(G\\) records the lengths and mutual angles of the basis vectors. If \\(a_i,b_i\\) now denote coordinates in this basis, then\n\n\\[\\mathbf a\\cdot\\mathbf b =\\sum_{i,j}a_iG_{ij}b_j =\\mathbf a^{\\mathsf T}G\\mathbf b.\\]\n\nFor example, take \\(\\mathbf e_1=(1,0)\\) and \\(\\mathbf e_2=(1,1)\\). Their Gram matrix is\n\n\\[G=\\begin{pmatrix}1&1\\\\1&2\\end{pmatrix}.\\]\n\nThe vector with basis coordinates \\((0,1)\\) has squared length \\(2\\), not \\(1\\). Applying the unweighted component formula to those coordinates would describe a different geometry.\n\nThis distinction extends to curvilinear coordinates and differential geometry. At a point, a metric tensor records the inner products of coordinate tangent vectors. In plane polar coordinates, the Euclidean squared line element is\n\n\\[ds^2=dr^2+r^2\\,d\\phi^2,\\]\n\nso coordinate components in the angular direction acquire a factor of \\(r^2\\). The coordinate basis in that direction is not a unit vector. By contrast, components expressed in a local orthonormal radial–angular frame use the ordinary sum-of-products formula. This is why the meaning of “components” matters: a coordinate basis and an orthonormal frame can describe the same geometry while requiring different component formulas."
    },
    {
      "heading": "Matrices, linear maps, and least squares",
      "text": "With vectors represented as columns, the dot product becomes a special case of matrix multiplication:\n\n\\[\\mathbf a\\cdot\\mathbf b=\\mathbf a^{\\mathsf T}\\mathbf b,\\]\n\nwhere \\({}^{\\mathsf T}\\) denotes transpose. More generally, each entry of a product \\(AB\\) is the dot product of a row of \\(A\\) with a column of \\(B\\). This places the operation at the computational core of matrix algebra. It also explains why dimensional conventions matter: \\(\\mathbf a^{\\mathsf T}\\mathbf b\\) is a scalar, whereas \\(\\mathbf a\\mathbf b^{\\mathsf T}\\) is an outer-product matrix.\n\nThe transpose describes how a linear map moves between the arguments of a dot product:\n\n\\[(A\\mathbf x)\\cdot\\mathbf y =\\mathbf x\\cdot(A^{\\mathsf T}\\mathbf y).\\]\n\nThus \\(A^{\\mathsf T}\\) represents the adjoint with respect to standard Euclidean inner products. A real symmetric matrix satisfies \\(A^{\\mathsf T}=A\\), so it can be transferred between the two arguments without changing its representation. The spectral theorem states that such a matrix has an orthonormal basis of eigenvectors. In these directions, its action is described by independent real scale factors, providing a direct connection between dot-product geometry and matrix structure.\n\nFor vectors \\(\\mathbf v_1,\\ldots,\\mathbf v_k\\), the matrix with entries \\(G_{ij}=\\mathbf v_i\\cdot\\mathbf v_j\\) is positive semidefinite because\n\n\\[\\mathbf c^{\\mathsf T}G\\mathbf c =\\left\\|\\sum_i c_i\\mathbf v_i\\right\\|^2\\geq0.\\]\n\nIt is positive definite exactly when the vectors are linearly independent. If those vectors are the columns of a matrix \\(A\\), then \\(G=A^{\\mathsf T}A\\). This identity explains why the rank of a Gram matrix equals the dimension spanned by its generating vectors. It also turns questions about geometric dependence into questions about matrix invertibility.\n\nIn ordinary least squares, a coefficient vector \\(\\mathbf x\\) is chosen to minimize\n\n\\[\\|A\\mathbf x-\\mathbf b\\|^2.\\]\n\nAt a minimizer, the residual \\(\\mathbf r=\\mathbf b-A\\mathbf x\\) is orthogonal to every column of \\(A\\). Therefore\n\n\\[A^{\\mathsf T}(A\\mathbf x-\\mathbf b)=\\mathbf0,\\]\n\nthe normal equations. If the columns are independent, they determine a unique solution. Numerically, however, forming \\(A^{\\mathsf T}A\\) can magnify conditioning problems; QR decomposition instead constructs an orthonormal basis for the column space. The Gram–Schmidt process does this by repeatedly subtracting dot-product projections. For an orthonormal basis \\(\\mathbf q_1,\\ldots,\\mathbf q_k\\), the projection of \\(\\mathbf b\\) is simply \\(\\sum_i(\\mathbf q_i\\cdot\\mathbf b)\\mathbf q_i\\), with each coefficient obtained by one dot product."
    },
    {
      "heading": "Inner products and related generalizations",
      "text": "The Euclidean dot product is one particular inner product on a real vector space. An abstract real inner product is symmetric, bilinear, and positive definite, but its vectors need not be coordinate tuples. On \\(\\mathbb R^n\\), every such inner product has a representation\n\n\\[\\langle\\mathbf x,\\mathbf y\\rangle_M =\\mathbf x^{\\mathsf T}M\\mathbf y\\]\n\nfor a symmetric positive-definite matrix \\(M\\). A diagonal \\(M\\) assigns positive weights to coordinates; off-diagonal entries also couple different coordinates. These products alter which directions are orthogonal and which vectors have equal length.\n\nOver the complex numbers, the unmodified formula \\(\\sum_i z_iw_i\\) is not positive definite. For example, the nonzero vector \\((1,i)\\) has \\(1+i^2=0\\) when paired with itself by that formula. The standard Hermitian inner product instead conjugates one argument:\n\n\\[\\langle\\mathbf z,\\mathbf w\\rangle =\\sum_i\\overline{z_i}w_i.\\]\n\nUnder this convention it is conjugate-linear in the first argument and linear in the second, with\n\n\\[\\langle\\mathbf w,\\mathbf z\\rangle =\\overline{\\langle\\mathbf z,\\mathbf w\\rangle}.\\]\n\nSome disciplines reverse which argument is conjugated. Matrix notation replaces transpose with conjugate transpose, giving \\(\\mathbf z^*\\mathbf w\\). The convention must be fixed before transferring real dot-product identities to complex spaces.\n\nFinite sums also generalize to integrals. For real square-integrable functions,\n\n\\[\\langle f,g\\rangle=\\int_a^b f(t)g(t)\\,dt,\\]\n\nand for complex-valued functions one factor is conjugated. In an \\(L^2\\) space, functions that agree almost everywhere represent the same vector, making the induced norm positive definite on those equivalence classes. Complete inner-product spaces are called Hilbert spaces. Orthogonality there supports expansions such as Fourier series, in which coefficients are inner products with sine, cosine, or complex exponential basis functions. The finite-dimensional rule “take a dot product to extract a component” survives in this setting, although convergence requires additional analysis.\n\nNot every scalar-valued pairing is an inner product. The natural pairing between a vector space and its dual space evaluates a linear functional on a vector; it requires neither a norm nor an angle. Likewise, the contraction \\(a_i b^i\\), written using the Einstein summation convention, pairs covariant and contravariant components. A metric is needed to identify an arbitrary vector with a corresponding covector. Indefinite forms provide another contrast: the spacetime interval in relativity can assign a negative or zero squared value to a nonzero vector. Such forms are bilinear and geometrically meaningful, but they do not satisfy positive definiteness and therefore do not define Euclidean lengths or the ordinary Cauchy–Schwarz inequality."
    },
    {
      "heading": "Physical interpretation and vector calculus",
      "text": "In mechanics, the dot product expresses the contribution of a force along a displacement. For a constant force \\(\\mathbf F\\) acting through displacement \\(\\Delta\\mathbf r\\), the work is\n\n\\[W=\\mathbf F\\cdot\\Delta\\mathbf r.\\]\n\nOnly the component of force parallel to the displacement contributes. A force perpendicular to the displacement does no work; a force opposing the displacement does negative work. A force of \\(10\\) newtons acting at \\(60^\\circ\\) to a displacement of \\(3\\) metres does \\(15\\) joules of work. The dot product supplies the directional factor, while the units come from force multiplied by distance.\n\nFor a position-dependent force along a curve \\(C\\), work is the line integral\n\n\\[W=\\int_C\\mathbf F\\cdot d\\mathbf r.\\]\n\nIf the motion is parametrized by time, \\(d\\mathbf r=\\mathbf v\\,dt\\), so the instantaneous power is\n\n\\[P=\\mathbf F\\cdot\\mathbf v.\\]\n\nThe same structure appears in kinetic energy:\n\n\\[T=\\frac12m\\,\\mathbf v\\cdot\\mathbf v.\\]\n\nThese expressions are invariant under rotations of spatial coordinates. Their geometric form prevents a change of axes from changing a physical prediction.\n\nDot products also select normal components in flux calculations. If \\(\\mathbf J\\) is a flux density and \\(\\mathbf n\\) a unit normal to a surface, the flux through an oriented area element is \\(\\mathbf J\\cdot\\mathbf n\\,dS\\). Integrating gives the surface integral\n\n\\[\\Phi=\\int_S\\mathbf J\\cdot\\mathbf n\\,dS.\\]\n\nA field tangent to the surface contributes zero, while reversing the normal reverses the sign. The divergence theorem relates total outward flux through a closed surface to the integral of divergence over the enclosed volume. In electromagnetism, the magnetic force on a charged particle is perpendicular to its velocity, so its dot product with velocity is zero: the magnetic part of the Lorentz force does not change the particle’s kinetic energy.\n\nIn multivariable calculus, the gradient is characterized by its dot product with a direction. For a differentiable scalar function \\(f\\) and a unit vector \\(\\mathbf u\\), the directional derivative is\n\n\\[D_{\\mathbf u}f(\\mathbf x)=\\nabla f(\\mathbf x)\\cdot\\mathbf u.\\]\n\nCauchy–Schwarz shows that the maximum directional derivative is \\(\\|\\nabla f\\|\\), attained in the gradient direction when the gradient is nonzero. Consequently, gradients are normal to regular level surfaces. This identification uses the Euclidean inner product: with a weighted inner product \\(\\langle\\mathbf x,\\mathbf y\\rangle_M\\), the gradient representing the same differential becomes \\(M^{-1}\\nabla f\\). Thus even the familiar notion of steepest increase depends on the chosen geometry."
    },
    {
      "heading": "Statistics, similarity, and machine learning",
      "text": "Dot products give a geometric interpretation to covariance and correlation. Given paired observations \\(x_i,y_i\\), form centered vectors\n\n\\[\\mathbf x_c=(x_i-\\bar x)_{i=1}^{n}, \\qquad \\mathbf y_c=(y_i-\\bar y)_{i=1}^{n}.\\]\n\nThe usual sample covariance is\n\n\\[s_{xy}=\\frac{\\mathbf x_c\\cdot\\mathbf y_c}{n-1}.\\]\n\nFor samples with nonzero variance, Pearson’s correlation coefficient is\n\n\\[r=\\frac{\\mathbf x_c\\cdot\\mathbf y_c} {\\|\\mathbf x_c\\|\\,\\|\\mathbf y_c\\|}.\\]\n\nIt is therefore the cosine of the angle between the centered data vectors. Perfect positive or negative correlation corresponds to collinearity after centering, while zero correlation corresponds to orthogonality.\n\nThe uncentered normalized dot product is cosine similarity:\n\n\\[s(\\mathbf x,\\mathbf y) =\\frac{\\mathbf x\\cdot\\mathbf y}{\\|\\mathbf x\\|\\,\\|\\mathbf y\\|}.\\]\n\nIt measures directional alignment rather than magnitude. For example, vectors \\((1,2)\\) and \\((10,20)\\) have cosine similarity \\(1\\), despite their different lengths. This is useful when magnitude reflects document length or another scale factor that is not the desired basis of comparison. For unit vectors, squared Euclidean distance and cosine similarity are related by\n\n\\[\\|\\mathbf x-\\mathbf y\\|^2=2-2\\,\\mathbf x\\cdot\\mathbf y.\\]\n\nThus maximizing the dot product between normalized vectors is equivalent to minimizing their Euclidean distance.\n\nIn linear regression, prediction has the form \\(\\hat y=\\mathbf w\\cdot\\mathbf x+b\\). The same linear score appears in classification, where \\(\\mathbf w\\cdot\\mathbf x+b=0\\) defines a decision hyperplane. A neuron in an artificial neural network typically applies a nonlinear activation to such a weighted sum. Dot products also compare query and key vectors in attention mechanisms. Scaled dot-product attention forms the matrix\n\n\\[\\frac{QK^{\\mathsf T}}{\\sqrt{d_k}}\\]\n\nbefore applying the softmax function and combining value vectors. Under an idealized model of independent, zero-mean, unit-variance components, an unscaled query–key dot product has variance \\(d_k\\); division by \\(\\sqrt{d_k}\\) offsets that growth.\n\nThe meaning of similarity nevertheless depends on representation. Changing a feature’s units changes its contribution to an ordinary dot product, and a raw dot product rewards large magnitudes as well as alignment. Centering, normalization, and feature scaling therefore define different geometries rather than merely different implementations. In principal component analysis, centered observations are projected onto orthonormal directions selected by variance. A related construction uses a covariance matrix \\(\\Sigma\\) to define the weighted product \\(\\mathbf x^{\\mathsf T}\\Sigma^{-1}\\mathbf y\\), when \\(\\Sigma\\) is positive definite. Whitening transforms this weighted geometry into an ordinary Euclidean one, accounting simultaneously for feature scales and correlations."
    },
    {
      "heading": "Numerical computation and accuracy",
      "text": "A straightforward length-\\(n\\) dot product requires \\(n\\) multiplications and \\(n-1\\) additions, giving arithmetic complexity \\(O(n)\\). It can be evaluated in one pass with constant auxiliary storage. High-performance implementations use vector instructions, unrolling, and multiple accumulators to exploit hardware parallelism. Dot products are basic operations in numerical libraries, including the Level 1 Basic Linear Algebra Subprograms, and appear repeatedly inside matrix multiplication, iterative equation solvers, and large-scale model evaluation. Their computational simplicity does not imply that all implementations return identical numerical results.\n\nIn floating-point arithmetic, products and sums are rounded. Under a standard model, with unit roundoff \\(u\\), no overflow or underflow, and \\(nu<1\\), a conventional evaluation satisfies a bound of the form\n\n\\[|\\widehat s-\\mathbf a\\cdot\\mathbf b| \\leq\\gamma_n\\sum_{i=1}^{n}|a_i b_i|, \\qquad \\gamma_n=\\frac{nu}{1-nu}.\\]\n\nThis controls absolute error relative to the total magnitude of the terms. It does not ensure small error relative to the final answer. If large positive and negative contributions nearly cancel, the exact dot product may be much smaller than the intermediate sums.\n\nFor example, the exact dot product of \\((10^{16},1,-10^{16})\\) with \\((1,1,1)\\) is \\(1\\). In binary64 arithmetic, adding the terms from left to right can lose the unit contribution when it is added to \\(10^{16}\\), producing \\(0\\). Adding the two large opposing terms first and then adding \\(1\\) produces \\(1\\). The sensitivity of relative accuracy is described by the cancellation factor\n\n\\[\\kappa_{\\mathrm{dot}} =\\frac{\\sum_i|a_i b_i|}{|\\mathbf a\\cdot\\mathbf b|},\\]\n\nwhen the denominator is nonzero. A large factor signals that small errors in individual contributions can be large compared with the final result. This connects dot-product evaluation to numerical stability and conditioning.\n\nSeveral techniques improve accuracy. Pairwise summation combines terms in a tree, shortening the longest accumulation path from linear to logarithmic depth. Compensated summation tracks information lost during addition. A fused multiply–add computes a product plus an accumulator with one final rounding rather than separately rounding the multiplication and addition. Higher-precision or exact accumulators can provide stronger guarantees, although their costs differ by hardware and implementation. Parallel reduction changes the grouping of additions, so thread counts or processor layouts can alter the last few bits unless a reproducible reduction scheme is used.\n\nFor sparse vectors, only indices where both vectors are nonzero contribute; sorted index lists can be merged without scanning every ambient coordinate. Computing angles adds further numerical issues: a rounded normalized dot product may lie slightly outside \\([-1,1]\\), and \\(\\arccos\\) is sensitive near its endpoints. In three dimensions, the equivalent formula\n\n\\[\\theta=\\operatorname{atan2} \\left(\\|\\mathbf a\\times\\mathbf b\\|,\\mathbf a\\cdot\\mathbf b\\right)\\]\n\noften behaves better near parallel or antiparallel directions. Reliable implementations must also control overflow and underflow in norms and intermediate products, for example through appropriate scaling."
    }
  ],
  "links": [
    "euclidean-space",
    "linear-algebra",
    "geometry",
    "physics",
    "inner-product",
    "real-number",
    "cross-product",
    "pythagorean-theorem",
    "norm-mathematics",
    "cauchy-schwarz-inequality",
    "triangle-inequality",
    "orthogonal-complement",
    "orthogonal-projection",
    "hyperplane",
    "orthonormal-basis",
    "orthogonal-matrix",
    "basis-linear-algebra",
    "gram-matrix",
    "differential-geometry",
    "metric-tensor",
    "matrix-multiplication",
    "matrix-transpose",
    "linear-map",
    "spectral-theorem",
    "matrix-rank",
    "ordinary-least-squares",
    "qr-decomposition",
    "gram-schmidt-process",
    "vector-space",
    "positive-definite-matrix",
    "complex-number",
    "conjugate-transpose",
    "hilbert-space",
    "fourier-series",
    "dual-space",
    "tensor-contraction",
    "einstein-summation-convention",
    "line-integral",
    "divergence-theorem",
    "gradient",
    "directional-derivative",
    "covariance",
    "correlation",
    "cosine-similarity",
    "euclidean-distance",
    "linear-regression",
    "artificial-neural-network",
    "softmax-function",
    "principal-component-analysis",
    "covariance-matrix",
    "floating-point-arithmetic",
    "numerical-stability",
    "condition-number"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}