mathgame theory
game theory
choices that depend on what others choose: dominant strategies, nash equilibria, mixed strategies, minimax.
a game is players, the choices each one has, and what each gets for every combination of choices. nobody picks alone. your best choice depends on theirs and theirs on yours, and an equilibrium is a set of choices where each one is a best answer to the rest.
- best response
- the top reply the choice that pays the most against what the other player does
- dominant
- best every time a best response to everything the other could do. pick it
- nash equilibrium
- no one gains alone each choice is a best response to the other's. mark them in the table
- not the best outcome
- 1, 1 over 3, 3 the prisoner's dilemma. the equilibrium leaves both worse off
- mixed strategy
- p from their payoffs set your odds so the other player is indifferent
- minimax
- max min = min max in a zero-sum game, once mixed strategies are allowed
- pricing against a competitor, bidding in an auction
- a rock-paper-scissors bot that can't be exploited
- rules and protocols where cheating doesn't pay
- the minimax search in a two-player game tree
on this page
the idea
a game has players, a set of choices for each one (their strategies), and a payoff for each player at every combination of choices. the whole subject is in one fact: your payoff depends on what the others choose, so your best choice does too. a two-player game with a few choices each fits in a table. the row player picks a row, the column player picks a column, and the cell they land in holds two numbers: the row player’s payoff first, then the column player’s. bigger is better.
the table below is the prisoner’s dilemma. two suspects are questioned apart. each can stay quiet or talk. if both stay quiet they get a light sentence, 3 points each here. if one talks and the other stays quiet, the talker walks free, 5, and the quiet one takes the full sentence, 0. if both talk, both get 1. the movie works out what each player should do, and where that leaves them.
an animation of the prisoner's dilemma table: quiet or talk for each player, with payoffs 3, 3 / 0, 5 / 5, 0 / 1, 1, the row player's first. the row player's best responses get rings one at a time: talk against quiet (5 over 3) and talk against talk (1 over 0). then the column player's: talk against quiet (5 over 3) and talk against talk (1 over 0). the cell with both rings, (talk, talk) with 1 and 1, is the equilibrium. last, a dashed ring on (quiet, quiet), 3 and 3, which both would rather have.
explore
pick a game or type your own payoffs. a ring marks a best response, and a cell with both rings is a pure equilibrium. the plot underneath draws what the other player gets from each of their choices as you change your odds: two straight lines, and where they cross, the other player is indifferent. that crossing is the mixed equilibrium’s odds. the prisoner’s dilemma’s lines never cross, coordination’s cross at , and matching pennies’ at .
type a payoff to change it. a ring marks a best response; a cell with both is a pure equilibrium
- pure equilibria
- (cafe, cafe), (park, park)
- strictly dominated
- none
- mixed equilibrium
- p = 1/3 cafe, q = 1/3 cafe
- payoffs at the mix
- 0.67, 0.67
what the column player gets at p = 0.50, by choice
- from cafe
- 1.00
- from park
- 0.50
- better
- cafe
- crossing
- p = 1/3, both pay 0.67
an interactive figure: buttons pick the prisoner's dilemma, coordination, matching pennies or chicken, or type new payoffs into a 2×2 table. rings mark each best response, a white ring each pure equilibrium, and a readout gives the strictly dominated strategies and the mixed equilibrium from the indifference rule. below, a chart of the other player's expected payoff from each of their two choices as one player's odds slide from 0 to 1, a solid and a dashed line that cross where that player is indifferent. it opens on coordination with the row player mixing at p = 0.50: the cafe pays the column player 1.00 and the park 0.50, and the lines cross at p = 1/3, where both pay 0.67. the prisoner's dilemma's lines don't cross: talk pays the column player more at every p. matching pennies crosses at p = 1/2 and payoff 0, chicken at p = 9/10 and −0.10.
try it
which cell is a nash equilibrium in pure strategies?
pick one.
a practice exercise over 2×2 payoff tables: which cell is a nash equilibrium in pure strategies, how many there are, which strategy is strictly dominated, and the odds that make the other player indifferent. it opens on the prisoner's dilemma, where the answer is (talk, talk), then coordination's mix, 1/3, then matching pennies, which has 0 pure equilibria.
the rules
a game as a table
two players, a finite list of strategies each, and a payoff for each player at every pair. for two players that’s a table with a row per strategy of player 1 and a column per strategy of player 2, and the pair in each cell, the row player’s first. this page writes the row player’s numbers as and the column player’s as , for row and column . a pure strategy is one choice. a mixed strategy is odds over the choices, and it comes in below.
best responses and dominance
a best response is the choice that pays the most against a given choice of the other player. in the table, hold a column fixed and find the biggest first number in it: that row is the row player’s best response to that column. hold a row fixed and find the biggest second number: the column player’s best response to that row. a strategy is strictly dominated when another one pays more against every choice of the other player, for all . a dominated strategy is never a best response, so a player should never use it, and removing it loses no equilibrium. once it’s gone, the smaller table may have new dominated strategies: remove them one at a time, and whatever survives holds every equilibrium of the original. the dominating strategy, if it beats everything, is dominant. in the prisoner’s dilemma talk is dominant for both. weak dominance, where the other strategy is at least as good everywhere and better somewhere, is a different thing: removing weakly dominated strategies can lose an equilibrium.
nash equilibrium
a pair of choices where each is a best response to the other, so neither player gains by changing alone. that’s the whole definition: nothing about fairness, nothing about the total, nothing about what the players would agree to if they could talk. to find the pure ones in a table, mark the row player’s best response in every column and the column player’s in every row; a cell with both marks is an equilibrium. the prisoner’s dilemma has one, (talk, talk). a coordination game, where two people each prefer the cafe to the park but above all want to end up in the same place, has two: (cafe, cafe) with 2 each and (park, park) with 1 each. matching pennies, where the row player wins 1 if the two coins match and loses 1 if they don’t, has none in pure strategies: in every cell someone wants to switch.
mixed strategies and the indifference rule
a mixed strategy picks at random with set odds: the row player plays the first row with probability , the column player the first column with probability . a mixed strategy is a best response only if every choice it uses pays the same against the other player’s mix, or the player would drop the worse one. so in a mixed equilibrium each player’s odds are set to make the other player indifferent. for a 2×2 game that’s one equation each. the column player gets from the first column and from the second; set them equal and solve for . the row player’s comes from the ‘s the same way. notice which payoffs feed which formula: , the row player’s odds, is built from , the column player’s payoffs. the key idea below says why.
the two lines
each of the column player’s expected payoffs is a straight line in . draw both over and the crossing is the of the mixed equilibrium. that’s the explore figure. two things can go wrong. the lines can be parallel, when both columns pay the same difference between the rows. or they can cross outside , or not at all in it: then one column is better at every , that column is dominant, and the column player never mixes. the prisoner’s dilemma is the second case: talk pays the column player against from quiet, more at every .
zero-sum games and minimax
a game is zero-sum when in every cell: what one wins the other loses, so one table of numbers is enough. the row player can guarantee the maximin, the best of their worst cases: for each row the least they can get, and the most of those. the column player, who wants small, can hold the row player to the minimax: for each column the most the row player can get, and the least of those. maximin is never more than minimax, since the row player’s guarantee can’t beat what the column player can hold them to. when they’re equal the cell is a saddle point, the least in its row and the most in its column, and it’s a pure equilibrium. in matching pennies they aren’t: the maximin is and the minimax is , and the gap is the whole game. with mixed strategies allowed they meet:
here and are the two players’ odds and is the table, so is the row player’s expected payoff, the kind of product the matrices page sets up. this is the minimax theorem. the common number is the value of the game, 0 for pennies, and the mixes that reach it are its equilibria. von neumann proved it in 1928, for any finite two-player zero-sum game, and the pennies table, with its pure max min of against a min max of , is the simplest example he gives of a game where the two differ.1 minimax is a statement about zero-sum games. in a general game the two players don’t want opposite things, and the row player’s worst case isn’t what the column player is after.
every finite game has an equilibrium
a finite game, any number of players with finitely many strategies each, has at least one nash equilibrium once mixed strategies are allowed. nash proved it in a two-page note in 1950, with a fixed point theorem: the map that sends every profile of mixes to the players’ best replies has a point it sends to itself, and that point is an equilibrium.2 it says one exists. it doesn’t say there’s only one, or how to find it, or that it’s any good for the players.
worked examples
the prisoner’s dilemma by elimination
for the row player, talk pays 5 and 1 against quiet and talk, and quiet pays 3 and 0: talk is better every time, so quiet is strictly dominated. drop it. in the row that’s left, the column player compares 0 from quiet with 1 from talk, and drops quiet. one cell survives, (talk, talk) with 1 and 1, and it’s the game’s only equilibrium. the best-response marks say the same: all four rings land on talk.
a 3×3 game, one strategy at a time
| left | center | right | |
|---|---|---|---|
| up | 4, 3 | 5, 1 | 6, 2 |
| middle | 2, 1 | 8, 4 | 3, 6 |
| down | 3, 0 | 9, 6 | 2, 8 |
no row dominates another at first: up is best against left and right, down against center. look at the column player instead. center pays 1, 4, 6 down the three rows and right pays 2, 6, 8: right is better in every row, so center is dominated. remove it, and the row player sees two columns. up pays 4 and 6, middle 2 and 3, down 3 and 2: up beats both. remove middle, then down. against up alone the column player compares 3 from left with 2 from right and keeps left. the survivor is (up, left), 4 and 3. check it in the full table: 4 is the biggest first number in the left column and 3 the biggest second number in the up row, so it’s an equilibrium, and the elimination says it’s the only one.
coordination: three equilibria
the cafe is worth 2 to each if they both go, the park 1, and a split 0. (cafe, cafe) and (park, park) are both pure equilibria: from either, whoever leaves alone drops to 0. there’s a mixed one too. the column player gets from the cafe and from the park when the row player goes to the cafe with odds ; equal when , so . by symmetry . the better place gets the smaller odds: to keep the other player indifferent, the better option has to be made rarer. at that mix each player expects , worse than either pure equilibrium.
matching pennies: the value is 0
the row player gets 1 on a match and otherwise. each row’s worst case is , so the maximin is ; each column’s best case for the row player is 1, so the minimax is 1. no saddle point, no pure equilibrium. with the rule, the column player is indifferent when , so , and the same way. at that mix the row player’s expected payoff is 0 whatever the column player does, and the column player can hold it to 0 whatever the row player does. the two guarantees meet at 0: the value.
chicken: 9/10
two drivers head at each other. swerve against swerve is 0 each; swerve against straight is for the one who swerved and 1 for the other; straight against straight is each. the pure equilibria are (swerve, straight) and (straight, swerve). for the mixed one, the column player gets from swerving and from going straight when the row player swerves with odds ; equal when , so . check the other side: against , swerving pays the row player and going straight . indifferent, as the rule promised, and each expects .
the key idea up close
why the indifference rule
let the column player mix with odds , and write for what the row player gets from the first row against that mix and for the second row. if the row player mixes with odds , their expected payoff is
a straight line in . a straight line on takes its biggest value at an end, unless it’s flat. so if the best is 1, and if it’s 0: a player who strictly prefers one row plays it every time, and a mix with isn’t a best response. the only way a real mix can be a best response is . in an equilibrium where the row player mixes, the column player’s must therefore make the row player indifferent, and by the same argument the row player’s must make the column player indifferent. that’s why each player’s odds solve the other player’s equation, and why the formula for holds only ‘s.
write the column player’s indifference out for a 2×2 table,
and dividing gives the formula from the rules. the denominator is 0 when the two columns differ by the same amount in both rows: then the lines are parallel and no makes the column player indifferent. the explore figure draws exactly these two lines, and the crossing is this equation’s solution.
the same idea gives the minimax theorem its shape in a 2×2 zero-sum game. at the equilibrium mix the row player’s two rows pay the same against , so the row player gets that number whatever they do, and it’s the most they can guarantee; the column player’s two columns pay the same against , so the row player gets that number whatever the column player does, and it’s the least the column player can hold them to. the two numbers are the same expected payoff at the same mix, so the maximin and the minimax, over mixes, agree.
in code
python/math/equilibrium.py works on a payoff table of any size, with fractions.Fraction keeping every number exact: the best responses of each player, the strictly dominated strategies and their removal one at a time, the pure equilibria as the cells where both numbers are best responses, the mixed equilibrium of a 2×2 table from the indifference rule, and maximin, minimax and the value of a zero-sum game. its tests pin this page’s numbers: the prisoner’s dilemma’s one equilibrium at (talk, talk) and the dominance that gets there, the 3×3 table falling to (up, left) once center, then middle and down, then right are removed, matching pennies at each with value 0 against a pure maximin of and minimax of 1, coordination at each with apiece, chicken at with apiece, and that changing only the row player’s payoffs moves and leaves alone.
"""two-player games as payoff tables, the row player's payoff first in every cell: each player's best responses, strictly dominated strategies removed one at a time, the pure nash equilibria of a table of any size (the cells where both numbers are best responses), the mixed equilibrium of a 2×2 game from the indifference rule, with fractions.Fraction keeping the odds exact, and maximin and minimax for a zero-sum game, which can differ in pure strategies and meet in mixed ones."""
from __future__ import annotations
from fractions import Fraction
Payoff = tuple[Fraction, Fraction]
Table = list[list[Payoff]]
Number = int | Fraction
def game(rows: list[list[tuple[Number, Number]]]) -> Table:
"""Return a payoff table from rows of (row payoff, column payoff) pairs, every number an exact Fraction."""
return [[(Fraction(a), Fraction(b)) for a, b in row] for row in rows]
def best_responses(table: Table) -> tuple[list[set[int]], list[set[int]]]:
"""Return the row player's best responses to each column, and the column player's to each row.
The first list has one set per column: the rows that give the row player the most there. The second has
one set per row: the columns that give the column player the most there. A set holds more than one index
only on a tie.
"""
m, n = len(table), len(table[0])
rows = []
for j in range(n):
best = max(table[i][j][0] for i in range(m))
rows.append({i for i in range(m) if table[i][j][0] == best})
cols = []
for i in range(m):
best = max(table[i][j][1] for j in range(n))
cols.append({j for j in range(n) if table[i][j][1] == best})
return rows, cols
def pure_equilibria(table: Table) -> list[tuple[int, int]]:
"""Return the cells (row, column) where each player's choice is a best response to the other's.
That's a nash equilibrium in pure strategies: neither player gains by changing alone. A table can have
none, one, or several.
"""
rows, cols = best_responses(table)
return [(i, j) for j in range(len(table[0])) for i in rows[j] if j in cols[i]]
def strictly_dominated(table: Table, player: int) -> list[int]:
"""Return the strategies of a player (0 = row, 1 = column) that one of their others beats every time.
Row i is strictly dominated when some row k pays the row player more than i against every column.
"""
m, n = len(table), len(table[0])
if player == 0:
pays = [[table[i][j][0] for j in range(n)] for i in range(m)]
else:
pays = [[table[i][j][1] for i in range(m)] for j in range(n)]
out = []
for s, mine in enumerate(pays):
if any(k != s and all(o > x for o, x in zip(other, mine)) for k, other in enumerate(pays)):
out.append(s)
return out
def eliminate_dominated(table: Table) -> tuple[list[int], list[int]]:
"""Remove strictly dominated strategies one at a time, until none is left, and return the survivors.
Each pass drops the lowest-numbered dominated strategy, the row player's first, and rebuilds the smaller
table. A strategy that is dominated only once another is gone goes in a later pass. The result is the
surviving row indices and column indices of the original table.
"""
rows = list(range(len(table)))
cols = list(range(len(table[0])))
while True:
sub = [[table[i][j] for j in cols] for i in rows]
gone = strictly_dominated(sub, 0)
if gone:
del rows[gone[0]]
continue
gone = strictly_dominated(sub, 1)
if gone:
del cols[gone[0]]
continue
return rows, cols
def mixed_equilibrium(table: Table) -> tuple[Fraction, Fraction] | None:
"""Return (p, q) for a 2×2 game: the mixed equilibrium from the indifference rule, or None.
p is the row player's odds of their first strategy, set so the column player gets the same from either
column. q is the column player's odds of their first, set so the row player gets the same from either
row. Each comes from the other player's payoffs. None when either equation has no solution strictly
between 0 and 1: then someone has a strategy that is never worse, and nobody mixes.
"""
(a11, b11), (a12, b12) = table[0]
(a21, b21), (a22, b22) = table[1]
# column indifferent: b11 p + b21 (1 - p) = b12 p + b22 (1 - p)
dp = b11 - b12 - b21 + b22
# row indifferent: a11 q + a12 (1 - q) = a21 q + a22 (1 - q)
dq = a11 - a21 - a12 + a22
if dp == 0 or dq == 0:
return None
p = (b22 - b21) / dp
q = (a22 - a12) / dq
if not (0 < p < 1 and 0 < q < 1):
return None
return p, q
def expected(table: Table, p: Fraction, q: Fraction) -> Payoff:
"""Return each player's expected payoff when the row player picks row 0 with odds p and the column player column 0 with odds q."""
(a11, b11), (a12, b12) = table[0]
(a21, b21), (a22, b22) = table[1]
row = p * (q * a11 + (1 - q) * a12) + (1 - p) * (q * a21 + (1 - q) * a22)
col = p * (q * b11 + (1 - q) * b12) + (1 - p) * (q * b21 + (1 - q) * b22)
return row, col
def is_zero_sum(table: Table) -> bool:
"""Return whether every cell's payoffs add to 0: what one player wins, the other loses."""
return all(a + b == 0 for row in table for a, b in row)
def maximin(table: Table) -> tuple[Fraction, Fraction]:
"""Return the row player's maximin and the column player's minimax over pure strategies, in a zero-sum game.
Maximin is the best of the row player's worst cases: for each row the least they can get, then the most of
those. Minimax is the column player's version on the same numbers: for each column the most the row player
can get, then the least of those. Maximin is never more than minimax, and when the two are equal that cell
is a pure equilibrium, a saddle point.
"""
if not is_zero_sum(table):
raise ValueError("maximin and minimax compare the row player's payoff, so the game must be zero-sum")
worst_rows = [min(a for a, _ in row) for row in table]
best_cols = [max(table[i][j][0] for i in range(len(table))) for j in range(len(table[0]))]
return max(worst_rows), min(best_cols)
def value(table: Table) -> Fraction:
"""Return the value of a 2×2 zero-sum game: the row player's payoff at the equilibrium.
When maximin equals minimax that number is the value, and a pure strategy each gets it. Otherwise the two
meet in mixed strategies, at the mix from the indifference rule.
"""
low, high = maximin(table)
if low == high:
return low
mix = mixed_equilibrium(table)
if mix is None:
raise ValueError("a 2×2 zero-sum game without a saddle point has a mixed equilibrium")
return expected(table, *mix)[0]pitfalls
- an equilibrium isn’t the best outcome. in the prisoner’s dilemma both players get 1 at the equilibrium and could have 3 each. equilibrium means stable against a change by one player, not good for the players
- mixing doesn’t mean 50/50. coordination mixes at , chicken at . the odds come out of the payoffs, and the better option often gets the smaller odds, because that’s what keeps the other player indifferent
- you set your odds from the other player’s payoffs, not your own. the most common slip with the indifference rule. is the row player’s odds and is built from the column player’s numbers. change the row player’s payoffs and doesn’t move; does
- a game can have several equilibria, and nothing in the definition picks one. coordination has three. the definition says each is stable; it doesn’t say which one the players reach, or that they reach any
- minimax is for zero-sum games. maximin and minimax compare one player’s payoff from both sides. in a general game the players don’t want opposite things, and the row player’s worst case has nothing to do with the column player’s aims. use best responses there
- weak and strict dominance aren’t the same. removing a strictly dominated strategy never loses an equilibrium. removing a weakly dominated one can, so eliminate strictly, or check what you dropped
practice
-
the stag hunt: two hunters each pick stag or hare. stag together pays 4 each; a hare alone pays 3 whatever the other does, except that a hunter who goes for the stag alone gets 0, and two hare hunters get 2 each. so the table is (4, 4), (0, 3) / (3, 0), (2, 2). mark the best responses and find the pure equilibria.
answer
against stag, stag pays the row player 4 and hare 3: stag. against hare, stag pays 0 and hare 2: hare. the column player’s marks mirror these. two cells get both marks: (stag, stag) with 4 each and (hare, hare) with 2 each. nothing is dominated, and (stag, stag) is better for both, but (hare, hare) is still an equilibrium: a hunter who switches to stag alone drops from 2 to 0.
-
in the stag hunt, find the mixed equilibrium and the expected payoff at it.
answer
the column player gets from stag and from hare; equal when , so . by symmetry . at the mix each player’s two choices pay the same, stag and hare , both , so that’s what each expects: between the two pure equilibria’s 2 and 4.
-
in the 3×3 table above, which strategy is strictly dominated at the very start, and why doesn’t any row count?
answer
center, for the column player: right pays 2, 6, 8 against center’s 1, 4, 6, more in every row. no row is dominated at the start because each row is a best response to some column: up to left (4) and right (6), down to center (9). middle is never a best response, but no single row beats it everywhere: up loses to it against center (5 against 8) and down loses to it against right (2 against 3). only once center is gone does up beat both.
-
the table (1, 2), (3, 0) / (2, 1), (0, 4), rows up and down, columns left and right. show there’s no pure equilibrium, then find the mixed one.
answer
against left the row player prefers down (2 over 1); against down the column player prefers right (4 over 1); against right the row player prefers up (3 over 0); against up the column player prefers left (2 over 0). the marks chase each other round the table and no cell gets both. for , the column player’s payoffs: from left and from right, equal when , so , where both pay . for , the row player’s: from up and from down, equal when , so , where both pay . at the mix the row player expects and the column player .
-
a zero-sum game with the row player’s table (2, −1) / (−1, 1). find the pure maximin and minimax, the mixed equilibrium, and the value.
answer
row minimums are and , so the maximin is ; column maximums are 2 and 1, so the minimax is 1. no saddle point. the column player’s payoffs are the negatives, , and they’re indifferent when , so . the row player is indifferent when , so . the value is the row player’s expected payoff there: from the first row, , and the second row gives the same. the row player can guarantee and the column player can hold them to it.
-
chicken has two pure equilibria, (swerve, straight) and (straight, swerve). is (swerve, swerve) one? is the game zero-sum?
answer
no: from (swerve, swerve), 0 each, either driver gains by going straight, 1 instead of 0, while the other is swerving. so it’s not stable, though it’s the outcome both would prefer to the mixed one at each. and it isn’t zero-sum: the payoffs at (straight, straight) are and , which don’t add to 0. both players lose there, which is the point of the game. so minimax has nothing to say about chicken; best responses do.
sources
-
j. von neumann, “zur theorie der gesellschaftsspiele” (opens in a new tab), mathematische annalen 100 (1928), pages 295–320, digitized by the göttingen state and university library. on page 303 the pennies-shaped table, with max min = −1 and min max = 1, is the simplest example he gives where max min is less than min max, and section iii, from page 307, proves max min = min max once mixed strategies are allowed. ↩
-
john f. nash, “equilibrium points in n-person games” (opens in a new tab), proceedings of the national academy of sciences 36, no. 1 (january 1950), pages 48–49. the note credits david gale with suggesting kakutani’s fixed point theorem to simplify the proof. ↩