Boolean Matrices
A boolean matrix is a matrix whose entries are 0 or 1, with operations:
- And (∧): for multiplication-like operations
- Or (∨): for addition-like operations
The Boolean Semiring
The boolean semiring B={0,1} has:
- Addition: 0∨0=0, 0∨1=1, 1∨0=1, 1∨1=1 (OR)
- Multiplication: 0∧0=0, 0∧1=0, 1∧0=0, 1∧1=1 (AND)
Matrix-Relation Correspondence
From Relation to Matrix
For finite sets A=[m] and B=[n], a relation R:A↛B corresponds to an m×n boolean matrix mat(R):
mat(R)ij={10if iRjotherwise
From Matrix to Relation
Given an m×n boolean matrix M, define rel(M):[m]↛[n] by:
irel(M)j⟺Mij=1
Mutual Inverses
rel(mat(R))=Randmat(rel(M))=M
This is a bijection between relations [m]↛[n] and m×n boolean matrices.
Matrix Operations for Relations
Composition as Matrix Multiplication
For R:[m]↛[n] and S:[n]↛[p]:
mat(S∘R)=mat(S)⊗mat(R)
where ⊗ is boolean matrix multiplication:
(M⊗N)ik=⋁j=1n(Mij∧Njk)
Union as Matrix Addition
mat(R∪S)=mat(R)⊕mat(S)
where ⊕ is boolean matrix addition (pointwise OR):
(M⊕N)ij=Mij∨Nij
Example
Let R:{1,2}↛{a,b} with R={(1,a),(2,b)}.
mat(R)=(1001)
Let S:{a,b}↛{X,Y} with S={(a,X),(b,Y)}.
mat(S)=(1001)
Then S∘R={(1,X),(2,Y)} and:
mat(S)⊗mat(R)=(1001)⊗(1001)=(1001)
Reachability via Matrix Powers
The Adjacency Matrix
For a relation R:[n]↛[n], the matrix mat(R) is the adjacency matrix of the corresponding directed graph.
Path Matrices
The matrix mat(R)∘k=mat(R)⊗⋯⊗mat(R) (k times) encodes paths of length exactly k.
Computing Reachability
Define:
M0=In(identity matrix)
Mk+1=In⊕(M⊗Mk)
Then Mn=mat(R∘∗), the adjacency matrix of the path relation.
Why This Works
- A simple path in an n-vertex graph has length <n
- Mk accumulates all paths of length ≤k
- By step n, all reachable vertices are discovered
Example
For R={(1,2),(2,3),(3,1)} (a 3-cycle):
mat(R)=001100010
Computing M3 gives mat(R∘∗)=mat({1,2,3}×{1,2,3}) (everything reachable).
Semirings for Different Graph Problems
The power of matrix multiplication is that changing the underlying semiring changes what problem we solve.
Matrix multiplication over a semiring (S,⊕,⊗,0,1):
(M⊗N)ik=⨁j=1n(Mij⊗Njk)
This formula works for ANY semiring!
Comparison of Semirings
| Semiring | Addition ⊕ | Multiply ⊗ | Zero | One | Computes |
|---|
| Boolean | ∨ (OR) | ∧ (AND) | 0 | 1 | Reachability |
| Min-Plus | min | + | ∞ | 0 | Shortest path |
| Max-Plus | max | + | −∞ | 0 | Longest path |
| Standard | + | × | 0 | 1 | Path counting |

The Boolean Semiring: Reachability
For adjacency matrix A:
Aijk=1⟺exists path of length k from i to j
Aij∗=1⟺exists ANY path from i to j
The Min-Plus Semiring: Shortest Path
For weighted adjacency matrix W (where Wij = weight of edge i→j, ∞ if no edge):
Wij(k)=minj1,…,jk−1(Wij1+Wj1j2+⋯+Wjk−1j)
This is the minimum cost of any path of exactly k edges.
Wij∗=shortest path cost from i to j
Example: Shortest Path
Consider weighted graph:
1 --3--> 2
| |
4 1
| |
v v
3 --2--> 4
Adjacency matrix (min-plus):
W=∞∞∞∞3∞∞∞4∞∞∞∞12∞
W2 computes shortest paths of exactly 2 edges:
W1,42=min(W1,2+W2,4,W1,3+W3,4)=min(3+1,4+2)=4
The path 1→2→4 costs 4, which is cheaper than 1→3→4 (cost 6).
Identity Elements in Min-Plus
- Additive identity (⊕-identity): ∞ (since min(x,∞)=x)
- Multiplicative identity (⊗-identity): 0 (since x+0=x)
Annnihilation Property
∞+x=∞
Even if a path exists (x finite), if you must traverse a non-existent edge (∞), the total is impossible.
Warning: Negative Weights
The min-plus semiring works correctly only when:
- All edge weights are non-negative, OR
- The graph has no negative-weight cycles
If negative cycles exist, shortest paths may not be well-defined.
Summary
- Relations on finite sets correspond to boolean matrices
- Composition corresponds to boolean matrix multiplication
- Union corresponds to boolean matrix addition
- Matrix powers compute reachability in directed graphs
- Changing the semiring changes the problem: Boolean = reachability, Min-Plus = shortest path
- Min-Plus semiring: ⊕=min, ⊗=+, identities are ∞ and 0