tropical / max-plus algebra

Where addition is a maximum.

Systems ruled by "wait for the slowest" — assembly lines, timetables, project plans — look like tangles of special cases. In max-plus algebra they are linear systems: one matrix, one eigenvalue, one eigenvector, and the whole schedule is explained.

↓ Start with the two-machine line — watch a schedule find its own rhythm.

the idea

Swap two operations, keep all the machinery

Max-plus algebra is ordinary linear algebra with its two operations replaced. "Addition" becomes take the larger, and "multiplication" becomes add. Nothing else changes: matrices, powers, eigenvalues, and eigenvectors all survive; they just mean something new.

addition ⊕
a ⊕ b = max(a, b)
identity is −∞ (a blank cell below)
multiplication ⊗
a ⊗ b = a + b
identity is 0

Read a matrix entry A[i][j] as "event i must wait A[i][j] time units after event j" (and −∞ when i does not depend on j at all). Then the tropical matrix product is exactly the scheduling rule start as soon as every prerequisite allows, a matrix power collects the heaviest path of a given length, and the eigenvalue is the pace the whole system settles into. Everything below runs live in your browser: edit any number and every consequence updates.

the tool · try it live

The max-plus playground

Enter waiting times below, or load a sample system. Leave a cell blank for −∞ (no dependence). Everything on this page recomputes as you type: the eigenvalue λ, the eigenvector, the matrix powers, and the schedule simulation in the next section all describe the matrix in this grid.

sample systems · or enter your own
2 × 2
A — waiting times (row waits on column)
Warning: data entered in the browser is not saved; it is lost when the page is closed or refreshed. Use "Download summary" before leaving to keep your numbers and results.
what the matrix says

matrix powers — the best total weight over walks of exactly k steps
k = 1

simulation · the eigenvalue at work

A schedule finds its rhythm

The recurrence x(k+1) = A ⊗ x(k) is "every event fires as soon as its slowest prerequisite allows." Iterate it from any starting times and the gaps between firings settle into a pattern whose average is exactly the eigenvalue λ of the matrix above. Change the matrix or the start and watch the rhythm reassert itself.

starting times x(0)
steps: 16

how to read it

Four readings of one matrix

01 · the matrix is a graph

Entries are edges; blanks are missing edges.

A[i][j] is the delay event i must leave after event j. Drawing an arrow j → i for every finite entry turns the matrix into the dependence graph of the system, and every statement below is a statement about that graph.

02 · the eigenvalue is the rhythm

λ = the heaviest average cycle.

Take any cycle in the graph, divide its total weight by its length, and λ is the largest such mean. It is the pace the schedule settles into: one full round of the system every λ time units, no matter how it starts. The cycle that achieves it is the bottleneck; highlighted amber in the star table above.

03 · the eigenvector is the offsets

v fixes who fires when inside each round.

The eigen-relation A ⊗ v = λ + v says: start the events at the times in v and every one of them repeats exactly λ later, forever. Differences between components of v are the steady phase offsets between events, which is why v is displayed with its smallest entry shifted to 0.

04 · the star is every path at once

A* = I ⊕ A ⊕ A² ⊕ …

Entry (i, j) of the Kleene star is the best weight over paths of every length from j to i, which on a project graph is the critical path method. It exists exactly when no cycle has positive weight; otherwise weights grow without bound, and the tool says so rather than pretending.

the twin · min-plus

Shortest paths and dynamic programming

Swap the max for a min and the same algebra computes cheapest routes. Now a ⊕ b = min(a, b), a blank cell means +∞ (no road), and smaller is better. The slider runs Bellman–Ford before your eyes: paths of at most k edges, with the entries that just improved highlighted. When nothing changes from one k to the next, value iteration has converged and you are looking at the all-pairs shortest distances, the min-plus Kleene star, computed by Floyd–Warshall.

edge costs (row from, column to) · blank = no road
4 × 4
at most 1 edges

the dictionary

Every classic DP is this algebra in disguise.

The Bellman update "try every predecessor, keep the cheapest" is one min-plus matrix–vector product. Matrix powers are optimal k-step costs, so Bellman–Ford is repeated multiplication. The Kleene star is all-pairs shortest paths, and computing it by allowing one more intermediate node at a time is Floyd–Warshall: Gaussian elimination over the semiring. The eigenvalue, the minimum cycle mean, is the best achievable average cost per stage. Viterbi decoding and edit distance run the same identities in neighboring semirings.

where it shows up

Five places max-plus runs the show

01

Manufacturing lines.

Machines wait for parts and for each other. The eigenvalue is the line's throughput ceiling; the critical cycle names the bottleneck worth investing in, and the eigenvector schedules everything else around it.

02

Railway timetables.

Trains wait for connections. National timetables have been analyzed as max-plus systems: λ is the shortest sustainable period of the whole network, and delay propagation is the transient the simulator above displays.

03

Project planning.

Tasks wait for prerequisites. The Kleene star of the precedence graph is the critical path method: longest paths give earliest starts, and the residuated system runs the dates backward from a deadline.

04

Networks and queues.

Packets wait for links and buffers. Network calculus bounds delays through min-plus convolutions, the continuous sibling of the matrix products on this page.

05

Dynamic programming everywhere.

Shortest paths, Viterbi decoding, sequence alignment, and reinforcement-learning value iteration all iterate a tropical matrix product to a fixed point. Even rhythmic stepping in biology, from legged gaits to molecular motors, has been modeled with the same eigenvalue.

the library

tropmat.js — the whole engine, one small file

Everything on this page runs on a dependency-free JavaScript library of about two hundred lines, a direct port of the original MicroPython tropmat. It works in any browser or in Node, carries both semirings, and is MIT licensed. The download button hands you exactly the code this page is executing.

MIT License · no dependencies
MAXPLUS, MINPLUSthe two semirings; every function takes one as its last argument
zeros(n,m,S), identity(n,S)the semiring zero matrix and identity
fromEdges(n,edges,S)build a matrix from [from, to, weight] triples (0-indexed)
madd(A,B,S), mmul(A,B,S)⊕ entrywise, and the tropical matrix product
mvmul(A,x,S), mpow(A,k,S)matrix–vector product and fast matrix power
closure(A,S)the Kleene star A* by Floyd–Warshall; check divergence first with cycleMean
maxCycleMean(A), minCycleMean(A)the eigenvalue by Karp's algorithm
eigenvector(A)[λ, v] with mmul(A,[v]) = λ + v, from the critical column of the star
criticalNodes(A)the nodes on a heaviest-mean cycle: the bottleneck
isIrreducible(A,S)strong connectivity, the hypothesis behind the unique rhythm
ldiv(A,b)residuation: the greatest x with A ⊗ x ≤ b (latest starts under a deadline)
orbit(A,x0,k,S), transient(A)simulate x(k+1)=A⊗x(k); detect when it turns exactly periodic
want to go deeper?

Three next steps