Dot-product Instruction
   HOME

TheInfoList



OR:

In
mathematics Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
, the dot product or scalar productThe term ''scalar product'' means literally "product with a
scalar Scalar may refer to: *Scalar (mathematics), an element of a field, which is used to define a vector space, usually the field of real numbers * Scalar (physics), a physical quantity that can be described by a single element of a number field such ...
as a result". It is also used sometimes for other symmetric bilinear forms, for example in a pseudo-Euclidean space.
is an algebraic operation that takes two equal-length sequences of numbers (usually
coordinate vector In linear algebra, a coordinate vector is a representation of a vector as an ordered list of numbers (a tuple) that describes the vector in terms of a particular ordered basis. An easy example may be a position such as (5, 2, 1) in a 3-dimensiona ...
s), and returns a single number. In Euclidean geometry, the dot product of the
Cartesian coordinates A Cartesian coordinate system (, ) in a plane is a coordinate system that specifies each point uniquely by a pair of numerical coordinates, which are the signed distances to the point from two fixed perpendicular oriented lines, measured in t ...
of two vectors is widely used. It is often called the inner product (or rarely projection product) of Euclidean space, even though it is not the only inner product that can be defined on Euclidean space (see Inner product space for more). Algebraically, the dot product is the sum of the products of the corresponding entries of the two sequences of numbers. Geometrically, it is the product of the Euclidean magnitudes of the two vectors and the cosine of the angle between them. These definitions are equivalent when using Cartesian coordinates. In modern geometry, Euclidean spaces are often defined by using vector spaces. In this case, the dot product is used for defining lengths (the length of a vector is the square root of the dot product of the vector by itself) and angles (the cosine of the angle between two vectors is the quotient of their dot product by the product of their lengths). The name "dot product" is derived from the
centered dot An interpunct , also known as an interpoint, middle dot, middot and centered dot or centred dot, is a punctuation mark consisting of a vertically centered dot used for interword separation in ancient Latin script. (Word-separating spaces did no ...
" · " that is often used to designate this operation; the alternative name "scalar product" emphasizes that the result is a
scalar Scalar may refer to: *Scalar (mathematics), an element of a field, which is used to define a vector space, usually the field of real numbers * Scalar (physics), a physical quantity that can be described by a single element of a number field such ...
, rather than a vector, as is the case for the
vector product In mathematics, the cross product or vector product (occasionally directed area product, to emphasize its geometric significance) is a binary operation on two vectors in a three-dimensional oriented Euclidean vector space (named here E), and is d ...
in three-dimensional space.


Definition

The dot product may be defined algebraically or geometrically. The geometric definition is based on the notions of angle and distance (magnitude) of vectors. The equivalence of these two definitions relies on having a
Cartesian coordinate system A Cartesian coordinate system (, ) in a plane is a coordinate system that specifies each point uniquely by a pair of numerical coordinates, which are the signed distances to the point from two fixed perpendicular oriented lines, measured in t ...
for Euclidean space. In modern presentations of Euclidean geometry, the points of space are defined in terms of their
Cartesian coordinates A Cartesian coordinate system (, ) in a plane is a coordinate system that specifies each point uniquely by a pair of numerical coordinates, which are the signed distances to the point from two fixed perpendicular oriented lines, measured in t ...
, and Euclidean space itself is commonly identified with the
real coordinate space In mathematics, the real coordinate space of dimension , denoted ( ) or is the set of the -tuples of real numbers, that is the set of all sequences of real numbers. With component-wise addition and scalar multiplication, it is a real vector ...
R''n''. In such a presentation, the notions of length and angles are defined by means of the dot product. The length of a vector is defined as the square root of the dot product of the vector by itself, and the cosine of the (non oriented) angle between two vectors of length one is defined as their dot product. So the equivalence of the two definitions of the dot product is a part of the equivalence of the classical and the modern formulations of Euclidean geometry.


Coordinate definition

The dot product of two vectors and specified with respect to an orthonormal basis, is defined as: :\mathbf\cdot\mathbf=\sum_^n _i_i=_1_1+_2_2+\cdots+_n_n where Σ denotes
summation In mathematics, summation is the addition of a sequence of any kind of numbers, called ''addends'' or ''summands''; the result is their ''sum'' or ''total''. Beside numbers, other types of values can be summed as well: functions, vectors, mat ...
and ''n'' is the dimension of the vector space. For instance, in three-dimensional space, the dot product of vectors and is: : \begin \ [] \cdot [] &= ( \times ) + (\times) + (\times) \\ &= 4 - 6 + 5 \\ &= 3 \end Likewise, the dot product of the vector with itself is: : \begin \ [] \cdot [] &= ( \times ) + (\times) + (\times) \\ &= 1 + 9 + 25 \\ &= 35 \end If vectors are identified with row matrices, the dot product can also be written as a matrix product :\mathbf \cdot \mathbf = \mathbf\mathbf^\mathsf T, where \mathbf^\mathsf T denotes the transpose of \mathbf. Expressing the above example in this way, a 1 × 3 matrix ( row vector) is multiplied by a 3 × 1 matrix ( column vector) to get a 1 × 1 matrix that is identified with its unique entry: : \begin \color1 & \color3 & \color-5 \end \begin \color4 \\ \color-2 \\ \color-1 \end = \color3 .


Geometric definition

In Euclidean space, a Euclidean vector is a geometric object that possesses both a magnitude and a direction. A vector can be pictured as an arrow. Its magnitude is its length, and its direction is the direction to which the arrow points. The magnitude of a vector a is denoted by \left\, \mathbf \right\, . The dot product of two Euclidean vectors a and b is defined by :\mathbf\cdot\mathbf=\, \mathbf\, \ \, \mathbf\, \cos\theta , where is the angle between and . In particular, if the vectors and are
orthogonal In mathematics, orthogonality is the generalization of the geometric notion of ''perpendicularity''. By extension, orthogonality is also used to refer to the separation of specific features of a system. The term also has specialized meanings in ...
(i.e., their angle is or 90°), then \cos \frac \pi 2 = 0, which implies that :\mathbf a \cdot \mathbf b = 0 . At the other extreme, if they are codirectional, then the angle between them is zero with \cos 0 = 1 and :\mathbf a \cdot \mathbf b = \left\, \mathbf a \right\, \, \left\, \mathbf b \right\, This implies that the dot product of a vector a with itself is :\mathbf a \cdot \mathbf a = \left\, \mathbf a \right\, ^2 , which gives : \left\, \mathbf a \right\, = \sqrt , the formula for the
Euclidean length Euclidean space is the fundamental space of geometry, intended to represent physical space. Originally, that is, in Euclid's ''Elements'', it was the three-dimensional space of Euclidean geometry, but in modern mathematics there are Euclidean s ...
of the vector.


Scalar projection and first properties

The scalar projection (or scalar component) of a Euclidean vector a in the direction of a Euclidean vector b is given by : a_b = \left\, \mathbf a \right\, \cos \theta , where is the angle between a and b. In terms of the geometric definition of the dot product, this can be rewritten :a_b = \mathbf a \cdot \widehat , where \widehat = \mathbf b / \left\, \mathbf b \right\, is the unit vector in the direction of b. The dot product is thus characterized geometrically by : \mathbf a \cdot \mathbf b = a_b \left\, \mathbf \right\, = b_a \left\, \mathbf \right\, . The dot product, defined in this manner, is homogeneous under scaling in each variable, meaning that for any scalar ''α'', : ( \alpha \mathbf ) \cdot \mathbf b = \alpha ( \mathbf a \cdot \mathbf b ) = \mathbf a \cdot ( \alpha \mathbf b ) . It also satisfies a distributive law, meaning that : \mathbf a \cdot ( \mathbf b + \mathbf c ) = \mathbf a \cdot \mathbf b + \mathbf a \cdot \mathbf c . These properties may be summarized by saying that the dot product is a
bilinear form In mathematics, a bilinear form is a bilinear map on a vector space (the elements of which are called '' vectors'') over a field ''K'' (the elements of which are called ''scalars''). In other words, a bilinear form is a function that is linear i ...
. Moreover, this bilinear form is
positive definite In mathematics, positive definiteness is a property of any object to which a bilinear form or a sesquilinear form may be naturally associated, which is positive-definite. See, in particular: * Positive-definite bilinear form * Positive-definite f ...
, which means that \mathbf a \cdot \mathbf a is never negative, and is zero if and only if \mathbf a = \mathbf 0 —the zero vector. The dot product is thus equivalent to multiplying the norm (length) of b by the norm of the projection of a over b.


Equivalence of the definitions

If e1, ..., e''n'' are the standard basis vectors in R''n'', then we may write :\begin \mathbf a &= _1 , \dots , a_n= \sum_i a_i \mathbf e_i \\ \mathbf b &= _1 , \dots , b_n= \sum_i b_i \mathbf e_i. \end The vectors e''i'' are an orthonormal basis, which means that they have unit length and are at right angles to each other. Hence since these vectors have unit length : \mathbf e_i \cdot \mathbf e_i = 1 and since they form right angles with each other, if , : \mathbf e_i \cdot \mathbf e_j = 0 . Thus in general, we can say that: : \mathbf e_i \cdot \mathbf e_j = \delta_ . Where δ ij is the Kronecker delta. Also, by the geometric definition, for any vector e''i'' and a vector a, we note : \mathbf a \cdot \mathbf e_i = \left\, \mathbf a \right\, \, \left\, \mathbf e_i \right\, \cos \theta_i = \left\, \mathbf a \right\, \cos \theta_i = a_i , where ''a''''i'' is the component of vector a in the direction of e''i''. The last step in the equality can be seen from the figure. Now applying the distributivity of the geometric version of the dot product gives : \mathbf a \cdot \mathbf b = \mathbf a \cdot \sum_i b_i \mathbf e_i = \sum_i b_i ( \mathbf a \cdot \mathbf e_i ) = \sum_i b_i a_i= \sum_i a_i b_i , which is precisely the algebraic definition of the dot product. So the geometric dot product equals the algebraic dot product.


Properties

The dot product fulfills the following properties if a, b, and c are real vectors and ''r'' is a
scalar Scalar may refer to: *Scalar (mathematics), an element of a field, which is used to define a vector space, usually the field of real numbers * Scalar (physics), a physical quantity that can be described by a single element of a number field such ...
. # Commutative: #: \mathbf \cdot \mathbf = \mathbf \cdot \mathbf , #: which follows from the definition (''θ'' is the angle between a and b): #: \mathbf \cdot \mathbf = \left\, \mathbf \right\, \left\, \mathbf \right\, \cos \theta = \left\, \mathbf \right\, \left\, \mathbf \right\, \cos \theta = \mathbf \cdot \mathbf . # Distributive over vector addition: #: \mathbf \cdot (\mathbf + \mathbf) = \mathbf \cdot \mathbf + \mathbf \cdot \mathbf . # Bilinear: #: \mathbf \cdot ( r \mathbf + \mathbf ) = r ( \mathbf \cdot \mathbf ) + ( \mathbf \cdot \mathbf ) . # Scalar multiplication: #: ( c_1 \mathbf ) \cdot ( c_2 \mathbf ) = c_1 c_2 ( \mathbf \cdot \mathbf ) . # Not
associative In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement f ...
because the dot product between a scalar (a ⋅ b) and a vector (c) is not defined, which means that the expressions involved in the associative property, (a ⋅ b) ⋅ c or a ⋅ (b ⋅ c) are both ill-defined. Note however that the previously mentioned scalar multiplication property is sometimes called the "associative law for scalar and dot product" or one can say that "the dot product is associative with respect to scalar multiplication" because ''c'' (a ⋅ b) = (''c'' a) ⋅ b = a ⋅ (''c'' b). #
Orthogonal In mathematics, orthogonality is the generalization of the geometric notion of ''perpendicularity''. By extension, orthogonality is also used to refer to the separation of specific features of a system. The term also has specialized meanings in ...
: #: Two non-zero vectors a and b are ''orthogonal'' if and only if . # No cancellation: #: Unlike multiplication of ordinary numbers, where if , then ''b'' always equals ''c'' unless ''a'' is zero, the dot product does not obey the cancellation law: #: If and , then we can write: by the distributive law; the result above says this just means that a is perpendicular to , which still allows , and therefore allows . # Product rule: #: If a and b are (vector-valued) differentiable functions, then the derivative ( denoted by a prime ) of is given by the rule .


Application to the law of cosines

Given two vectors a and b separated by angle ''θ'' (see image right), they form a triangle with a third side . The dot product of this with itself is: : \begin \mathbf \cdot \mathbf & = ( \mathbf - \mathbf) \cdot ( \mathbf - \mathbf ) \\ & = \mathbf \cdot \mathbf - \mathbf \cdot \mathbf - \mathbf \cdot \mathbf + \mathbf \cdot \mathbf \\ & = \mathbf^2 - \mathbf \cdot \mathbf - \mathbf \cdot \mathbf + \mathbf^2 \\ & = \mathbf^2 - 2 \mathbf \cdot \mathbf + \mathbf^2 \\ \mathbf^2 & = \mathbf^2 + \mathbf^2 - 2 \mathbf \mathbf \cos \mathbf \\ \end which is the law of cosines.


Triple product

There are two ternary operations involving dot product and
cross product In mathematics, the cross product or vector product (occasionally directed area product, to emphasize its geometric significance) is a binary operation on two vectors in a three-dimensional oriented Euclidean vector space (named here E), and is ...
. The scalar triple product of three vectors is defined as : \mathbf \cdot ( \mathbf \times \mathbf ) = \mathbf \cdot ( \mathbf \times \mathbf )=\mathbf \cdot ( \mathbf \times \mathbf ). Its value is the determinant of the matrix whose columns are the
Cartesian coordinates A Cartesian coordinate system (, ) in a plane is a coordinate system that specifies each point uniquely by a pair of numerical coordinates, which are the signed distances to the point from two fixed perpendicular oriented lines, measured in t ...
of the three vectors. It is the signed volume of the
parallelepiped In geometry, a parallelepiped is a three-dimensional figure formed by six parallelograms (the term ''rhomboid'' is also sometimes used with this meaning). By analogy, it relates to a parallelogram just as a cube relates to a square. In Euclidea ...
defined by the three vectors, and is isomorphic to the three-dimensional special case of the exterior product of three vectors. The vector triple product is defined by : \mathbf \times ( \mathbf \times \mathbf ) = ( \mathbf \cdot \mathbf )\, \mathbf - ( \mathbf \cdot \mathbf )\, \mathbf . This identity, also known as ''Lagrange's formula'', may be remembered as "ACB minus ABC", keeping in mind which vectors are dotted together. This formula has applications in simplifying vector calculations in physics.


Physics

In physics, vector magnitude is a
scalar Scalar may refer to: *Scalar (mathematics), an element of a field, which is used to define a vector space, usually the field of real numbers * Scalar (physics), a physical quantity that can be described by a single element of a number field such ...
in the physical sense (i.e., a
physical quantity A physical quantity is a physical property of a material or system that can be quantified by measurement. A physical quantity can be expressed as a ''value'', which is the algebraic multiplication of a ' Numerical value ' and a ' Unit '. For examp ...
independent of the coordinate system), expressed as the product of a numerical value and a physical unit, not just a number. The dot product is also a scalar in this sense, given by the formula, independent of the coordinate system. For example: * Mechanical work is the dot product of
force In physics, a force is an influence that can change the motion of an object. A force can cause an object with mass to change its velocity (e.g. moving from a state of rest), i.e., to accelerate. Force can also be described intuitively as a p ...
and displacement vectors, * Power is the dot product of
force In physics, a force is an influence that can change the motion of an object. A force can cause an object with mass to change its velocity (e.g. moving from a state of rest), i.e., to accelerate. Force can also be described intuitively as a p ...
and velocity.


Generalizations


Complex vectors

For vectors with complex entries, using the given definition of the dot product would lead to quite different properties. For instance, the dot product of a vector with itself could be zero without the vector being the zero vector (e.g. this would happen with the vector a = i. This in turn would have consequences for notions like length and angle. Properties such as the positive-definite norm can be salvaged at the cost of giving up the symmetric and bilinear properties of the dot product, through the alternative definition : \mathbf \cdot \mathbf = \sum_i , where \overline is the complex conjugate of b_i. When vectors are represented by column vectors, the dot product can be expressed as a matrix product involving a conjugate transpose, denoted with the superscript H: : \mathbf \cdot \mathbf = \mathbf^\mathsf \mathbf . In the case of vectors with real components, this definition is the same as in the real case. The dot product of any vector with itself is a non-negative real number, and it is nonzero except for the zero vector. However, the complex dot product is sesquilinear rather than bilinear, as it is conjugate linear and not linear in a. The dot product is not symmetric, since : \mathbf \cdot \mathbf = \overline . The angle between two complex vectors is then given by : \cos \theta = \frac . The complex dot product leads to the notions of Hermitian forms and general inner product spaces, which are widely used in mathematics and physics. The self dot product of a complex vector \mathbf \cdot \mathbf = \mathbf^\mathsf \mathbf , involving the conjugate transpose of a row vector, is also known as the norm squared, \mathbf \cdot \mathbf = \, \mathbf\, ^2, after the
Euclidean norm Euclidean space is the fundamental space of geometry, intended to represent physical space. Originally, that is, in Euclid's ''Elements'', it was the three-dimensional space of Euclidean geometry, but in modern mathematics there are Euclidean s ...
; it is a vector generalization of the '' absolute square'' of a complex scalar (see also: squared Euclidean distance).


Inner product

The inner product generalizes the dot product to abstract vector spaces over a field of
scalars Scalar may refer to: *Scalar (mathematics), an element of a field, which is used to define a vector space, usually the field of real numbers *Scalar (physics), a physical quantity that can be described by a single element of a number field such a ...
, being either the field of real numbers \R or the field of complex numbers \Complex . It is usually denoted using
angular brackets A bracket is either of two tall fore- or back-facing punctuation marks commonly used to isolate a segment of text or data from its surroundings. Typically deployed in symmetric pairs, an individual bracket may be identified as a 'left' or 'r ...
by \left\langle \mathbf \, , \mathbf \right\rangle . The inner product of two vectors over the field of complex numbers is, in general, a complex number, and is sesquilinear instead of bilinear. An inner product space is a normed vector space, and the inner product of a vector with itself is real and positive-definite.


Functions

The dot product is defined for vectors that have a finite number of entries. Thus these vectors can be regarded as
discrete function In mathematics, a sequence is an enumerated collection of objects in which repetitions are allowed and order matters. Like a set, it contains members (also called ''elements'', or ''terms''). The number of elements (possibly infinite) is calle ...
s: a length- vector is, then, a function with
domain Domain may refer to: Mathematics *Domain of a function, the set of input values for which the (total) function is defined **Domain of definition of a partial function **Natural domain of a partial function **Domain of holomorphy of a function * Do ...
, and is a notation for the image of by the function/vector . This notion can be generalized to
continuous function In mathematics, a continuous function is a function such that a continuous variation (that is a change without jump) of the argument induces a continuous variation of the value of the function. This means that there are no abrupt changes in value ...
s: just as the inner product on vectors uses a sum over corresponding components, the inner product on functions is defined as an integral over some interval (also denoted ): : \left\langle u , v \right\rangle = \int_a^b u(x) v(x) d x Generalized further to
complex function Complex analysis, traditionally known as the theory of functions of a complex variable, is the branch of mathematical analysis that investigates functions of complex numbers. It is helpful in many branches of mathematics, including algebraic ...
s and , by analogy with the complex inner product above, gives : \left\langle \psi , \chi \right\rangle = \int_a^b \psi(x) \overline d x .


Weight function

Inner products can have a weight function (i.e., a function which weights each term of the inner product with a value). Explicitly, the inner product of functions u(x) and v(x) with respect to the weight function r(x)>0 is : \left\langle u , v \right\rangle = \int_a^b r(x) u(x) v(x) d x.


Dyadics and matrices

A double-dot product for matrices is the Frobenius inner product, which is analogous to the dot product on vectors. It is defined as the sum of the products of the corresponding components of two matrices A and B of the same size: : \mathbf : \mathbf = \sum_i \sum_j A_ \overline = \operatorname ( \mathbf^\mathsf \mathbf ) = \operatorname ( \mathbf \mathbf^\mathsf ) . : \mathbf : \mathbf = \sum_i \sum_j A_ B_ = \operatorname ( \mathbf^\mathsf \mathbf ) = \operatorname ( \mathbf \mathbf^\mathsf ) = \operatorname ( \mathbf^\mathsf \mathbf ) = \operatorname ( \mathbf \mathbf^\mathsf ) . (For real matrices) Writing a matrix as a
dyadic Dyadic describes the interaction between two things, and may refer to: *Dyad (sociology), interaction between a pair of individuals **The dyadic variation of Democratic peace theory *Dyadic counterpoint, the voice-against-voice conception of polyp ...
, we can define a different double-dot product (see ,) however it is not an inner product.


Tensors

The inner product between a tensor of order ''n'' and a tensor of order ''m'' is a tensor of order , see Tensor contraction for details.


Computation


Algorithms

The straightforward algorithm for calculating a floating-point dot product of vectors can suffer from
catastrophic cancellation In numerical analysis, catastrophic cancellation is the phenomenon that subtracting good approximations to two nearby numbers may yield a very bad approximation to the difference of the original numbers. For example, if there are two studs, one L_ ...
. To avoid this, approaches such as the
Kahan summation algorithm In numerical analysis, the Kahan summation algorithm, also known as compensated summation, significantly reduces the numerical error in the total obtained by adding a sequence of finite-precision floating-point numbers, compared to the obvious appro ...
are used.


Libraries

A dot product function is included in: * BLAS level 1 real SDOT, DDOT; complex CDOTU, ZDOTU = X^T * Y, CDOTC ZDOTC = X^H * Y * Julia as    * Matlab as    or    or    * GNU Octave as    * Intel oneAPI Math Kernel Library real p?dot dot = sub(x)'*sub(y); complex p?dotc dotc = conjg(sub(x)')*sub(y)


See also

*
Cauchy–Schwarz inequality The Cauchy–Schwarz inequality (also called Cauchy–Bunyakovsky–Schwarz inequality) is considered one of the most important and widely used inequalities in mathematics. The inequality for sums was published by . The corresponding inequality fo ...
*
Cross product In mathematics, the cross product or vector product (occasionally directed area product, to emphasize its geometric significance) is a binary operation on two vectors in a three-dimensional oriented Euclidean vector space (named here E), and is ...
*
Dot product representation of a graph A dot product representation of a simple graph is a method of representing a graph using vector spaces and the dot product from linear algebra. Every graph has a dot product representation.. Definition Let ''G'' be a graph with vertex set ''V''. ...
*
Euclidean norm Euclidean space is the fundamental space of geometry, intended to represent physical space. Originally, that is, in Euclid's ''Elements'', it was the three-dimensional space of Euclidean geometry, but in modern mathematics there are Euclidean s ...
, the square-root of the self dot product * Matrix multiplication *
Metric tensor In the mathematical field of differential geometry, a metric tensor (or simply metric) is an additional structure on a manifold (such as a surface) that allows defining distances and angles, just as the inner product on a Euclidean space allows ...
* Multiplication of vectors *
Outer product In linear algebra, the outer product of two coordinate vector In linear algebra, a coordinate vector is a representation of a vector as an ordered list of numbers (a tuple) that describes the vector in terms of a particular ordered basis. An ea ...


Notes


References


External links

*
Explanation of dot product including with complex vectors

"Dot Product"
by Bruce Torrence, Wolfram Demonstrations Project, 2007. {{tensors Articles containing proofs Bilinear forms Operations on vectors Analytic geometry Tensors Scalars