Dot Product

←Back to Tech Tree

inventorycoverage

Dot Product #

Linear AlgebraDifficulty: ★★☆☆☆Depth: 2Unlocks: 13

Sum of component products. Measures angle between vectors.

Interactive Visualization #

⏮◀◀▶▶STEP0.25x1xZOOM

t=0s

Core Concepts #

Key Symbols & Notation #

dot operator: '·' (binary operator between vectors)

Essential Relationships #

Prerequisites (1) #

Vectors Introduction6 atoms

Unlocks (4) #

Orthogonalitylvl 3Normslvl 2Projectionslvl 3Kernel Methodslvl 4

Advanced Learning Details

Graph Position #

17

Depth Cost

13

Fan-Out (ROI)

4

Bottleneck Score

2

Chain Length

Cognitive Load #

5

Atomic Elements

21

Total Elements

L0

Percentile Level

L3

Atomic Level

All Concepts (5) #

Teaching Strategy #

Self-serve tutorial - low prerequisites, straightforward concepts.

The dot product is the bridge between “lists of numbers” and “geometry.” It turns two vectors into a single scalar that tells you how aligned they are—crucial for angles, lengths, projections, and many ML similarity measures.

TL;DR:

For vectors a, b ∈ ℝⁿ, the dot product is a · b = ∑ᵢ aᵢbᵢ (a scalar). Geometrically, a · b = ‖a‖‖b‖cos θ, where θ is the angle between them. Positive means “mostly same direction,” zero means perpendicular, negative means “mostly opposite.”

What Is Dot Product? #

Why this concept exists (motivation) #

When you have two vectors a and b, you often want a single number that answers: “How similar are their directions?”

The dot product is designed to do exactly that, while still behaving nicely with algebra (linearity).

Algebraic definition (component-wise) #

For a = (a₁, a₂, …, aₙ) and b = (b₁, b₂, …, bₙ) in ℝⁿ, the dot product is

a · b = ∑ᵢ₌₁ⁿ aᵢ bᵢ

It is a scalar (a single number), not a vector.

To keep the pacing clear, here’s the 2D and 3D special cases:

Geometric definition (angle + lengths) #

If θ is the angle between nonzero vectors a and b, then

a · b = ‖a‖ ‖b‖ cos θ

This is powerful because it connects an algebraic computation (sum of products) to geometry (angles).

Interpreting the sign and magnitude #

From a · b = ‖a‖‖b‖cos θ:

So the dot product is a “direction agreement score,” scaled by how long the vectors are.

A useful mental model: shadow / projection #

Think of a · b as: “How much of a lies along b (or vice versa), times ‖b‖.”

More precisely, if b0, then

a · b = ‖b‖ · (signed length of the projection of a onto the direction of b)

We’ll make that precise later, but it’s a great intuition for what dot products mean.

Core Mechanic 1: Computing Dot Products (and the algebra you can trust) #

How to compute it reliably #

Given a, b ∈ ℝⁿ:

  1. 1)Pair up corresponding components (aᵢ with bᵢ).
  2. 2)Multiply each pair.
  3. 3)Sum the products.

Example structure:

a · b = a₁b₁ + a₂b₂ + … + aₙbₙ

Key properties (why we like dot product) #

These properties are the reason dot product becomes the default “inner product” in ℝⁿ.

1) Commutative #

a · b = b · a

Because multiplication of real numbers is commutative: aᵢbᵢ = bᵢaᵢ.

2) Distributive over addition #

a · (b + c) = a · b + a · c

Show it component-wise:

b + c = (b₁ + c₁, …, bₙ + cₙ)

Then

a · (b + c)

= ∑ᵢ aᵢ(bᵢ + cᵢ)

= ∑ᵢ (aᵢbᵢ + aᵢcᵢ)

= ∑ᵢ aᵢbᵢ + ∑ᵢ aᵢcᵢ

= a · b + a · c

This “linearity” is essential for projections and least squares later.

3) Homogeneous with scalars #

(ka) · b = k(a · b) and a · (kb) = k(a · b)

Component-wise:

(ka) · b = ∑ᵢ (kaᵢ)bᵢ = k∑ᵢ aᵢbᵢ = k(a · b)

4) Positive definiteness (dot with itself) #

a · a ≥ 0, and a · a = 0 ⇔ a = 0

Because

a · a = ∑ᵢ aᵢ²

A sum of squares can’t be negative, and it’s zero only if every aᵢ = 0.

Dot product and length (preview of norms) #

This property gives you Euclidean length:

a‖ = √(a · a)

Check quickly:

a · a = a₁² + … + aₙ²

So

a‖ = √(a₁² + … + aₙ²)

This connection is a big reason the dot product is everywhere: it defines the usual geometry of ℝⁿ.

Table: operations to keep straight #

ObjectExampleResult typeNotes
Scalar3numberno direction
Vectora = (1, 2)vectormagnitude + direction
Scalar multiply3avectorscales length
Vector adda + bvectorhead-to-tail
Dot producta · bscalarmeasures alignment

Takeaway: dot product is the main way we turn “two directions” into “one number.”

Core Mechanic 2: Geometry—Angles, Orthogonality, and Cosine #

Why geometry matters here #

The algebraic definition ∑ᵢ aᵢbᵢ is easy to compute, but it doesn’t look like an angle measure.

The geometric form

a · b = ‖a‖‖b‖cos θ

explains what the dot product is doing: it compares directions.

Deriving a practical angle formula #

If a0 and b0, you can solve for cos θ:

a · b = ‖a‖‖b‖cos θ

Divide both sides by ‖a‖‖b‖:

cos θ = (a · b) / (‖a‖‖b‖)

Then

θ = arccos( (a · b) / (‖a‖‖b‖) )

This is how you compute angles between vectors in any dimension.

Orthogonality criterion (the dot-product test) #

Two vectors are orthogonal (perpendicular) exactly when their dot product is zero:

aba · b = 0

Geometric reason:

a · b = ‖a‖‖b‖cos(π/2) = ‖a‖‖b‖·0 = 0

Algebraic usefulness: you don’t need to “draw” vectors to test perpendicularity.

Unit vectors and simplifying the dot product #

If you normalize vectors to unit length:

û = a / ‖a‖, v̂ = b / ‖b

Then

û · v̂ = cos θ

So for unit vectors, the dot product directly equals cosine similarity.

Cauchy–Schwarz inequality (why cosine stays in range) #

A critical fact (you’ll use it constantly later) is:

|a · b| ≤ ‖a‖‖b

This implies

-1 ≤ (a · b) / (‖a‖‖b‖) ≤ 1

So arccos is well-defined (up to floating-point errors in practice).

We won’t fully prove Cauchy–Schwarz here, but intuitively: the projection of one vector onto another can’t be longer than the original.

A “projection-flavored” identity to remember #

For b0, the scalar projection (signed) of a onto b is

comp_{b}(a) = (a · b) / ‖b

And the vector projection is

proj_{b}(a) = ((a · b) / (‖b‖²)) b

Notice how the dot product is the engine: it extracts the amount of alignment needed to scale b.

This is the gateway to the node Projections.

Application/Connection: Similarity, Projections, and Kernels #

1) Similarity in data (ML intuition) #

In machine learning and information retrieval, vectors often represent data:

The dot product a · b becomes a similarity score: larger means more aligned.

But there’s a catch: dot product depends on length. If one vector has huge magnitude, it can dominate the score.

That motivates cosine similarity:

cos θ = (a · b) / (‖a‖‖b‖)

This measures alignment independent of scale.

2) Projections and least squares (linear algebra intuition) #

Suppose you want the “part of a in the direction of b.” The projection formula

proj_{b}(a) = ((a · b) / (‖b‖²)) b

is fundamental for:

In least squares, the key condition is often: residual r is orthogonal to the subspace, meaning r · v = 0 for all basis vectors v in the subspace.

3) Norms and distances #

Because ‖a‖ = √(a · a), dot product defines Euclidean geometry.

A classic identity connects dot products and distances:

ab‖² = (ab) · (ab)

Expand:

(ab) · (ab)

= a · aa · bb · a + b · b

= ‖a‖² − 2(a · b) + ‖b‖²

This shows dot products are enough to compute squared distances.

4) Kernel methods: dot products in disguise #

Kernel methods (like SVMs with kernels) revolve around computing

ϕ(x) · ϕ(z)

without explicitly forming the feature map ϕ.

A kernel function K(x, z) is essentially a dot product in some (possibly huge) feature space:

K(x, z) = ϕ(x) · ϕ(z)

So understanding dot products deeply is a prerequisite for the “kernel trick” intuition: learning with geometry in feature space while doing computations in input space.

Where this node points next #

Worked Examples (3) #

Compute a dot product and interpret the sign #

Let a = (2, −1, 3) and b = (4, 0, −2). Compute a · b and interpret what it suggests about their directions.

  1. Write the component-wise formula:

    a · b = a₁b₁ + a₂b₂ + a₃b₃

  2. Substitute values:

    a · b = (2)(4) + (−1)(0) + (3)(−2)

  3. Compute each product:

    (2)(4) = 8

    (−1)(0) = 0

    (3)(−2) = −6

  4. Sum:

    a · b = 8 + 0 − 6 = 2

Insight: The dot product is positive (2), so the angle θ between a and b is acute (θ < π/2). They are somewhat aligned, but not strongly—if they were strongly aligned, the dot product would be large relative to ‖a‖‖b‖.

Find the angle between two vectors #

Let a = (1, 2) and b = (2, 1). Find the angle θ between them.

  1. Compute the dot product:

    a · b = (1)(2) + (2)(1) = 2 + 2 = 4

  2. Compute lengths:

    a‖ = √(a · a) = √(1² + 2²) = √5

    b‖ = √(b · b) = √(2² + 1²) = √5

  3. Use cos θ = (a · b) / (‖a‖‖b‖):

    cos θ = 4 / (√5 · √5) = 4 / 5

  4. Solve for θ:

    θ = arccos(4/5)

    ≈ 0.6435 radians

    ≈ 36.87°

Insight: Even in 2D, the dot product gives an angle formula that generalizes perfectly to ℝⁿ. The computation used only ∑ᵢ aᵢbᵢ and square roots.

Use dot product to compute a projection onto a direction #

Project a = (3, 4) onto b = (1, 0).

  1. Compute a · b:

    a · b = (3)(1) + (4)(0) = 3

  2. Compute ‖b‖²:

    b‖² = b · b = 1² + 0² = 1

  3. Apply projection formula:

    proj_{b}(a) = ((a · b) / (‖b‖²)) b

  4. Substitute:

    proj_{b}(a) = (3/1)(1, 0) = (3, 0)

Insight: Since b points along the x-axis, the projection should be “keep the x part, drop the y part.” The dot product extracts exactly that aligned amount.

Key Takeaways #

Common Mistakes #

Practice #

easy

Compute a · b for a = (−2, 5, 1) and b = (3, 1, 4).

Hint: Multiply corresponding components and sum: (−2)(3) + 5(1) + 1(4).

Show solution

a · b = (−2)(3) + (5)(1) + (1)(4)

= −6 + 5 + 4

= 3

medium

Find a nonzero vector x in ℝ² that is orthogonal to a = (3, −6).

Hint: Solve a · x = 0. Let x = (x₁, x₂) and enforce 3x₁ + (−6)x₂ = 0.

Show solution

Let x = (x₁, x₂). Orthogonality means:

a · x = 0

(3, −6) · (x₁, x₂) = 3x₁ − 6x₂ = 0

So 3x₁ = 6x₂ ⇒ x₁ = 2x₂.

Choose x₂ = 1 ⇒ x₁ = 2.

One valid answer is x = (2, 1). (Any nonzero scalar multiple also works.)

hard

Let a = (1, 2, 2) and b = (2, 0, 1). Compute cos θ between them and decide whether the angle is acute, right, or obtuse.

Hint: Compute a · b, then ‖a‖ and ‖b‖, then cos θ = (a · b) / (‖a‖‖b‖). The sign of cos θ tells acute/obtuse.

Show solution

Compute dot product:

a · b = (1)(2) + (2)(0) + (2)(1) = 2 + 0 + 2 = 4

Compute norms:

a‖ = √(1² + 2² + 2²) = √(1 + 4 + 4) = √9 = 3

b‖ = √(2² + 0² + 1²) = √(4 + 0 + 1) = √5

Compute cosine:

cos θ = 4 / (3√5)

Since 4 / (3√5) > 0, the angle is acute (θ < π/2).

Connections #

Next nodes you can unlock:

Quality: A (4.5/5)

← back to treebrowse all →