Search

Search papers and lessons

Bilinear Form

Level 2 · 10 min read

A bilinear form takes two vectors and returns one number, and it is linear in each vector when the other is held fixed; a matrix describes it completely.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • ReadReady to readNot yet

TL;DR

A bilinear form is a rule that takes two vectors and returns a single number. It is linear in each vector separately, so doubling either input doubles the output, and adding to either input adds to the output. Every bilinear form on ordinary coordinates is a matrix sandwiched between the two vectors, which makes it easy to compute and to study.

Builds on: linear maps, Matrix Multiplication, Matrix Transpose · Leads to: quadratic forms, positive definite matrices, and the dot product as a special case

Where it's used

Measuring angles and lengths in physics. The dot product is a bilinear form, and it gives lengths and angles in ordinary space. In general relativity the metric plays the same role in four-dimensional spacetime, and it is a bilinear form that can take negative values. That sign change is why distances in spacetime behave differently from distances on a map.

Covariance in statistics. The covariance of two random variables is linear in each of them: scaling one scales the covariance, and adding a variable adds to it. A covariance matrix therefore encodes a bilinear form on the space of linear combinations of variables.

Scoring pairs in machine learning. A recommender can score a user and an item by a bilinear form uTWvu^{\mathsf T} W v, where uu is the user's vector, vv the item's vector, and WW a learned matrix. Some tensor-based knowledge-graph models score facts the same way. Attention in transformers also compares a query and a key through a bilinear product.

How it works

Take two vectors in the plane, x=(1,2)x = (1, 2) and y=(3,1)y = (3, 1), and a 2×22 \times 2 matrix

A=(1203).A = \begin{pmatrix} 1 & 2 \\ 0 & 3 \end{pmatrix}.

The bilinear form is B(x,y)=xTA yB(x, y) = x^{\mathsf T} A\, y. Compute it one step at a time.

  1. Apply the matrix to yy. Ay=(1⋅3+2⋅1,  0⋅3+3⋅1)=(5,3)Ay = (1 \cdot 3 + 2 \cdot 1,\; 0 \cdot 3 + 3 \cdot 1) = (5, 3). Check: the first entry is 3+2=53 + 2 = 5, and the second is 0+3=30 + 3 = 3.

  2. Take the dot product with xx. x⋅Ay=1⋅5+2⋅3=11x \cdot Ay = 1 \cdot 5 + 2 \cdot 3 = 11. Check: the two steps used one matrix and two vectors, and the result is one number.

  3. Test linearity in the first slot. Replace xx with 2x=(2,4)2x = (2, 4). Then B(2x,y)B(2x, y) is 2⋅5+4⋅3=222 \cdot 5 + 4 \cdot 3 = 22, which is 2×112 \times 11. Check: doubling the first input doubled the output.

  4. Test linearity in the second slot. Replace yy with y+zy + z for z=(0,1)z = (0, 1), so y+z=(3,2)y + z = (3, 2). Then A(y+z)=(7,6)A(y + z) = (7, 6) and x⋅(7,6)=7+12=19x \cdot (7, 6) = 7 + 12 = 19. Also B(x,z)=1⋅2+2⋅3=8B(x, z) = 1 \cdot 2 + 2 \cdot 3 = 8 and 11+8=1911 + 8 = 19. Check: the output for the sum equals the sum of the outputs.

The flow of the computation is:

flowchart LR
  y["Vector y"] --> A["Multiply by matrix A"]
  A --> d["Dot product with x"]
  x["Vector x"] --> d
  d --> out["One number B(x, y)"]

The math

Definition

Definition: Bilinear form

Let VV be a vector space over the real numbers. A bilinear form on VV is a function B:V×V→RB : V \times V \to \mathbb{R} such that for all vectors x,x′,y,y′∈Vx, x', y, y' \in V and all real numbers cc,

B(x+x′,y)=B(x,y)+B(x′,y),B(cx,y)=c B(x,y),B(x + x', y) = B(x, y) + B(x', y), \qquad B(cx, y) = c\,B(x, y),B(x,y+y′)=B(x,y)+B(x,y′),B(x,cy)=c B(x,y).B(x, y + y') = B(x, y) + B(x, y'), \qquad B(x, cy) = c\,B(x, y).

In words: fix one input and the output is a linear function of the other.

Note that B(x+x′,y+y′)B(x + x', y + y') is not in general B(x,y)+B(x′,y′)B(x, y) + B(x', y'). The form is linear in each slot separately, not in both at once.

Defining the matrix

In coordinates, write x=∑ixieix = \sum_i x_i e_i and y=∑jyjejy = \sum_j y_j e_j with eie_i the standard basis vectors. Linearity in each slot lets you expand:

B(x,y)=∑i∑jxi yj B(ei,ej).B(x, y) = \sum_{i}\sum_{j} x_i\, y_j\, B(e_i, e_j).

Define Aij=B(ei,ej)A_{ij} = B(e_i, e_j). Then B(x,y)=xTA yB(x, y) = x^{\mathsf T} A\, y. In the walkthrough, A12=2A_{12} = 2 is the entry in row 1, column 2, and it multiplies x1y2x_1 y_2.

Step 1 in symbols: the matrix applied to y

The product AyA y is the matrix times vector with entries (Ay)i=∑jAijyj(Ay)_i = \sum_j A_{ij} y_j. This is the first part of the expansion above, with the sum over jj taken first.

Step 2 in symbols: the dot product

The final step is xT(Ay)=∑ixi(Ay)ix^{\mathsf T}(Ay) = \sum_i x_i (Ay)_i. This is a dot product of xx with the vector AyAy. Doubling xx doubles every term, and the same holds for yy through AyAy, which is why the form is linear in both slots.

The special cases

If AA is the identity matrix, B(x,y)=x⋅yB(x, y) = x \cdot y, the ordinary dot product. If AA is symmetric, then B(x,y)=B(y,x)B(x, y) = B(y, x) for all xx and yy. Setting y=xy = x gives the quadratic form xTAxx^{\mathsf T} A x.

Worked examples

Example
1. Entry by entry (tiny case)

Use the matrix A=(1203)A = \begin{pmatrix} 1 & 2 \\ 0 & 3 \end{pmatrix}, x=(1,2)x = (1, 2) and y=(3,1)y = (3, 1).

  1. The four terms xiAijyjx_i A_{ij} y_j are: x1A11y1=1⋅1⋅3=3x_1 A_{11} y_1 = 1 \cdot 1 \cdot 3 = 3; x1A12y2=1⋅2⋅1=2x_1 A_{12} y_2 = 1 \cdot 2 \cdot 1 = 2; x2A21y1=2⋅0⋅3=0x_2 A_{21} y_1 = 2 \cdot 0 \cdot 3 = 0; x2A22y2=2⋅3⋅1=6x_2 A_{22} y_2 = 2 \cdot 3 \cdot 1 = 6.
  2. Add them: 3+2+0+6=113 + 2 + 0 + 6 = 11.
  3. Compare with the walkthrough: B(x,y)=11B(x, y) = 11, which matches.

Answer: B(x,y)=11B(x, y) = 11. The sum over all index pairs gives the same number as the matrix-vector route.

Example
2. A symmetric matrix and its quadratic form (standard case)

Use A=(2112)A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}, which is symmetric, and x=(1,2)x = (1, 2).

  1. Compute Ax=(2⋅1+1⋅2,  1⋅1+2⋅2)=(4,5)Ax = (2 \cdot 1 + 1 \cdot 2,\; 1 \cdot 1 + 2 \cdot 2) = (4, 5).
  2. Compute the dot product x⋅Ax=1⋅4+2⋅5=14x \cdot Ax = 1 \cdot 4 + 2 \cdot 5 = 14.
  3. This is B(x,x)B(x, x), the quadratic form at xx.
  4. Check by expanding: B(x,x)=2x12+2x1x2+2x22B(x, x) = 2x_1^2 + 2x_1 x_2 + 2 x_2^2 with x1=1x_1 = 1, x2=2x_2 = 2 gives 2+4+8=142 + 4 + 8 = 14.

Answer: B(x,x)=14B(x, x) = 14. Both routes agree, and the symmetric matrix gives the same value for B(x,y)B(x, y) and B(y,x)B(y, x).

Example
3. Scoring a user and an item (realistic case)

A recommender represents a user by u=(2,1)u = (2, 1) and an item by v=(3,5)v = (3, 5). It scores the pair with B(u,v)=uTWvB(u, v) = u^{\mathsf T} W v, where the learned matrix is W=(0.5001)W = \begin{pmatrix} 0.5 & 0 \\ 0 & 1 \end{pmatrix}.

  1. Apply WW to vv: Wv=(0.5⋅3+0⋅5,  0⋅3+1⋅5)=(1.5,5)Wv = (0.5 \cdot 3 + 0 \cdot 5,\; 0 \cdot 3 + 1 \cdot 5) = (1.5, 5).
  2. Take the dot product with uu: u⋅Wv=2⋅1.5+1⋅5=3+5=8u \cdot Wv = 2 \cdot 1.5 + 1 \cdot 5 = 3 + 5 = 8.
  3. The score is 88. A larger score means the model expects the user to like the item more.
  4. Check the linearity: if the user vector doubles to (4,2)(4, 2), the score doubles to 1616.

Answer: the score is 88, and doubling the user's vector doubles it.

Try it: Use the same WW and u=(2,1)u = (2, 1), but a new item v′=(1,0)v' = (1, 0). What is B(u,v′)B(u, v')? Answer: Wv′=(0.5,0)Wv' = (0.5, 0), and u⋅Wv′=2⋅0.5+1⋅0=1u \cdot Wv' = 2 \cdot 0.5 + 1 \cdot 0 = 1. The score is 11.

Common mistakes and tradeoffs

It is tempting to think a bilinear form is linear in both inputs at once, so B(x+x′,y+y′)=B(x,y)+B(x′,y′)B(x + x', y + y') = B(x, y) + B(x', y'). In fact it is linear in each slot separately, and the expansion of the sum produces four terms, and two of them are cross terms, B(x,y′)B(x, y') and B(x′,y)B(x', y).

It is tempting to think every bilinear form must be symmetric, so that B(x,y)=B(y,x)B(x, y) = B(y, x). In fact symmetry is an extra property. The matrix A=(1203)A = \begin{pmatrix} 1 & 2 \\ 0 & 3 \end{pmatrix} from the walkthrough is not symmetric, and B(y,x)B(y, x) gives a different number.

It is tempting to think the matrix AA is a fixed property of the form. In fact it depends on the basis. If you change basis with an invertible matrix PP, the matrix becomes PTAPP^{\mathsf T} A P. The form itself does not change, only its coordinates do.

Use a bilinear form when you want to compare two vectors in a way that is linear in each, such as covariance, a dot product in a changed geometry, or a learned score for a pair. Do not use it when you only need to transform one vector, where a linear map is the right tool. Alternatives include a plain dot product, when the geometry is standard, and a quadratic form, when you only ever compare a vector with itself.

History

Bilinear and quadratic forms grew out of 19th-century work on systems of equations and matrices. In the 1850s James Joseph Sylvester proved that a quadratic form has a fixed number of positive and negative terms however it is simplified, a result now called Sylvester's law of inertia. Bilinear forms were later generalised to inner products, which gave geometry on abstract spaces, and in the 20th century they became central to quantum mechanics and to the metric of general relativity.

Recap

  • A bilinear form takes two vectors and returns one number, linear in each vector when the other is fixed.
  • In coordinates it is xTAyx^{\mathsf T} A y for a unique matrix AA, and the matrix depends on the basis.
  • The dot product is the case A=IA = I, and a symmetric AA gives a quadratic form when the two vectors are equal.
  • The same structure appears in covariance, metrics in physics and learned scoring functions in machine learning.
  • Read next: quadratic forms and positive definite matrices, which use the symmetric case.

Check yourself

QuestionWhat does it mean for a form to be bilinear?Show answer

It is linear in the first input when the second is held fixed, and linear in the second input when the first is held fixed. It is not required to be linear in both inputs at the same time.

QuestionLet A=(2001)A = \begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix}, x=(1,3)x = (1, 3) and y=(2,1)y = (2, 1). What is xTAyx^{\mathsf T} A y?Show answer

Ay=(4,1)Ay = (4, 1), and x⋅Ay=1⋅4+3⋅1=7x \cdot Ay = 1 \cdot 4 + 3 \cdot 1 = 7.

QuestionWhy does the dot product count as a bilinear form, and what matrix does it correspond to?Show answer

For fixed yy, the map x↦x⋅yx \mapsto x \cdot y is linear, and the same holds in yy. Writing x⋅y=xTIyx \cdot y = x^{\mathsf T} I y gives the identity matrix II as its matrix.

QuestionA recommender uses uTWvu^{\mathsf T} W v with u=(2,0)u = (2, 0), v=(1,4)v = (1, 4) and W=(3102)W = \begin{pmatrix} 3 & 1 \\ 0 & 2 \end{pmatrix}. What is the score, and what does doubling vv do to it?Show answer

Wv=(3⋅1+1⋅4,  2⋅4)=(7,8)Wv = (3 \cdot 1 + 1 \cdot 4,\; 2 \cdot 4) = (7, 8), and u⋅Wv=2⋅7=14u \cdot Wv = 2 \cdot 7 = 14. Doubling vv doubles the score to 2828, because the form is linear in its second input.

Sources