Algorithmadvanced
Daskalakis-Mehta-Papadimitriou algorithm
Also called DMP algorithm, 1/2-approximate Nash algorithm.
Finds a 1/2-approximate Nash equilibrium of a bimatrix game in linear time from one action, its best response and the best response to that.
- Time
- O(m + n) worst
- Space
- O(m + n) extra
- Where
- m = the number of pure strategies of the row player; n = the number of pure strategies of the column player
- Model
- Real RAM
- Properties
- deterministicnot exactofflineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Constantinos Daskalakis, Aranyak Mehta, Christos H. Papadimitriou, 2006
The Daskalakis-Mehta-Papadimitriou (DMP) algorithm finds an approximate Nash equilibrium of a two-player game in strategic form (a bimatrix game) with payoffs in . It takes any row, a best column against that row, and a best row against that column. The row player mixes the two rows with equal weight and the column player plays the column. No player can then gain more than by a change of strategy, so the pair is a -Nash equilibrium in the additive sense of the epsilon-Nash equilibrium page. The method reads only one row and one column of the input. It is the simplest member of a line of polynomial-time approximations, and the bound is the best possible for every method whose strategies have small supports.
In plain words
Two players each pick a move, and every outcome pays each of them between 0 and 1. We want a pair of plans where nobody can win much by switching. Start with any move of the first player. Let the second player pick a best answer to it. Let the first player pick a best answer to that answer. Now the first player flips a fair coin between the start move and its best answer, and the second player keeps its answer. Half of the time the first player already plays its best move, so it loses at most half a point. Half of the time the second player meets the move it answered best, so it also loses at most half a point.
The problem
The input is two matrices and with entries in . On this page and are the numbers of pure strategies of the row player and of the column player, not numbers of players. If the row player plays row and the column player plays column , they get and , and both maximize. A pair of mixed strategies , is an -Nash equilibrium if
The maxima are over pure strategies, and this is enough: a mixed strategy is a best response if and only if its support is inside the set of pure best responses, and any mixed deviation earns an average of pure deviation payoffs. The output is a pair with . The scale matters, because the additive has a meaning only relative to the range of the payoffs.
The algorithm
DMP(A, B, i) ▷ A, B are m by n with entries in [0, 1]; i is any row- 1
j ← a column that maximizes B[i][c] ▷ a best response to row i - 2
k ← a row that maximizes A[r][j] ▷ a best response to column j - 3
x ← (1/2) e_i + (1/2) e_k ▷ x = e_i if k = i - 4
y ← e_j - 5
return (x, y)
Line L1 reads one row of , and line L2 reads one column of . The code breaks ties to the smallest index, but any tie rule gives the same guarantee.
Example
Take , and the start row . Row 0 of is , so line L1 picks . Column 0 of is , so line L2 picks . The output is and .
| player | payoff of | best pure deviation | gain |
|---|---|---|---|
| row | row 1, payoff 1 | ||
| column | column 1, payoff |
Both gains are exactly , so the bound of the analysis is reached. The game also has the pure equilibrium (row 1, column 1), and the algorithm finds it from the start row : then and , and the output is pure.
In matching pennies scaled to , with and , the start row 0 gives , , and . The column player has gain 0, and the row player has gain , while the only equilibrium is the uniform pair.
Correctness
Let . The row player gets , and its best pure payoff is by line L2. So the row gain is , because both entries are in .
The column player gets . A deviation to column gives , and by line L1. So the gain from column is at most . In words, on the half of the time when the row player plays , the column player already plays a best response, and on the other half it loses at most 1.
By the best-response fact, pure deviations give the largest gains, so is a -Nash equilibrium. If , both gains are 0 and the output is a pure Nash equilibrium. If the payoffs are in instead of , the same argument gives a -Nash equilibrium. The proof file has the details and the tight example.
Proof: The DMP pair is a 1/2-Nash equilibrium, and the bound 1/2 is tightfull
Let be an bimatrix game with all entries in . Here and are the numbers of pure strategies of the row player and of the column player. For mixed strategies and , the row player gets and the column player gets . The pair is an -Nash equilibrium if and .
Lemma 1 (pure deviations are enough). For every mixed strategy of the row player, , and the same holds for the column player.
Proof. is an average of the numbers , so it is at most their maximum.
So the gain of a player from any deviation is the gain from its best pure deviation, and the two inequalities above are the full definition.
The algorithm takes any row , then lets be a column with (line L1), and a row with (line L2). It outputs and (lines L3 to L5). If , then .
Theorem 1. is a -Nash equilibrium. More exactly, the gain of the row player is , and the gain of the column player is at most .
Proof. First, and are mixed strategies: the weights are and on rows and (or 1 on row if ), and 1 on column .
Row player. Since , , and by the choice of . The row player gets . So the gain is
because and .
Column player. The column player gets . A pure deviation to column gives . By the choice of , . So the gain from column is
because and . By Lemma 1 the largest gain over all strategies is the largest of these numbers, so it is at most .
Corollary 1 (pure equilibrium). If , then is a pure Nash equilibrium.
Proof. With the row gain is . For the column player, and is a best column against row , so the gain is 0 too.
Corollary 2 (other payoff ranges). If every entry of and of is in , the output is a -Nash equilibrium.
Proof. The algorithm only compares entries of the same matrix, so it gives the same output on with and , whose entries are in . All gains scale by the factor . If , every gain is 0.
Theorem 2 (the bound is tight). For every , the game
with start row and ties broken to the smallest index gives an output where both gains are exactly .
Proof. Row 0 of is , so the tie goes to . Column 0 of is , so . The output is and . The row player gets and row 1 gives 1, a gain of . The column player gets , and column 1 gives , a gain of .
Running time. Line L1 reads the entries and line L2 reads the entries . The other lines write numbers. So the time is , which is sublinear in the size of the input when the matrices can be read at random positions.
Complexity
Line L1 reads entries and line L2 reads entries, and the output has numbers. So the time is and the extra space is , in the real-RAM model with one step for each comparison. This is sublinear in the input size if the input can be read at any position. Trying all start rows and keeping the best pair costs and still guarantees only .
Properties
- Small supports. The row player uses at most 2 strategies and the column player uses 1.
- Deterministic and exact. With rational payoffs the output and its gains are exact rationals.
- Tight analysis. The example above reaches the bound for both players at the same time.
- Not an equilibrium in general. The output is an exact equilibrium only when , that is, when the start row is a best response to its own best response.
- Additive only. The guarantee needs payoffs on a common scale. It says nothing about relative approximation.
Variants and improvements
- Smaller in polynomial time. Larger supports and linear programs give better bounds: about (Daskalakis, Mehta and Papadimitriou, EC 2007), (Bosse, Byrka and Markakis), (Tsaknakis and Spirakis 2008, by a descent method) and for every constant (Deligkas, Fasoulakis and Markakis, ESA 2022 and ACM Transactions on Algorithms 2023). A 2026 preprint of Li and Li claims about , and it is not yet peer reviewed as of November 2026.
- Quasi-polynomial time for any . The Lipton-Markakis-Mehta algorithm searches over supports of size . Under an exponential-time hypothesis for PPAD, constant cannot be done much faster (Rubinstein's theorem).
- Well-supported equilibria. In an -well-supported equilibrium every strategy in the support must be within of a best response. The same note of DMP gives a reduction of this notion to win-lose games and a bound that depends on a graph conjecture. The best known polynomial bound is (Deligkas, Fasoulakis and Markakis).
- Exact equilibria. Lemke-Howson or support enumeration give exact answers in exponential time in the worst case. The exact problem is PPAD-complete (PPAD-completeness of Nash).
When to use it
Use it as a fast baseline, as a warm start for a local search, or when the game is too large to read in full and only queries are allowed. Use it in tests and in teaching, because the analysis fits in a few lines. When is too coarse, use the LP-based methods with a bound near , or an exact method on small games.
Pitfalls
- Payoffs outside . The bound is in units of the payoff range. Scale the payoffs first, or read the result as .
- Wrong matrix in a step. Line L1 uses the column player's payoffs and line L2 uses the row player's payoffs . Swapping them breaks the proof.
- Two entries for one row when . If the code stores as a list of (row, weight) pairs, row appears twice with weight . Merge the pairs, so that row has weight 1.
- Expecting better on easy games. A good start row helps, but no choice of start row improves the worst-case bound, and the example above has gain from row 0.
- Small supports cannot do better. Feder, Nazerzadeh and Saberi (EC 2007) showed games in which every -Nash equilibrium with needs supports of logarithmic size. So no method of this kind, with supports of constant size, can beat .
Implementations
The Python code follows lines L1 to L5 in exact rational arithmetic and returns the two gains. The tests check the tight example for several values of the free entries, a pure equilibrium found when , battle of the sexes, matching pennies and chicken scaled to , and 300 random games with every start row, each checked against the shared exact checker. They also scale random integer payoffs to test the bound , and count the entries that are read, which must be exactly .
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Shared helper of the algorithmic game theory pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Finite games in normal form, with exact payoffs and exact equilibrium checks.
A game is a pair (sizes, pay). sizes is a tuple (k_1, ..., k_n) of the numbers of pure
strategies of the n players; the pure strategies of player i are 0, ..., k_i - 1. pay is a
dict that maps each profile, a tuple s = (s_1, ..., s_n), to a tuple of n Fraction
utilities, which each player maximizes. A cost game passes the utilities u = -c.
A mixed profile sigma is a list of n lists; sigma[i][a] is the probability, a Fraction,
that player i plays a. A distribution on profiles (for correlated and coarse correlated
equilibria) is a dict from profiles to Fraction; missing profiles have probability 0.
All checks are exact: there is no tolerance anywhere. There is no LP and no equilibrium
algorithm in this module.
"""
from fractions import Fraction
from itertools import product
def profiles(sizes):
"""Return the list of all pure profiles, in lexicographic order."""
return list(product(*(range(k) for k in sizes)))
def from_bimatrix(A, B):
"""Return the game of the bimatrix (A, B): the row player gets A[r][c], the column player B[r][c]."""
m, n = len(A), len(A[0])
if len(B) != m or any(len(row) != n for row in A) or any(len(row) != n for row in B):
raise ValueError("A and B must be m by n matrices of the same shape")
pay = {(r, c): (Fraction(A[r][c]), Fraction(B[r][c])) for r in range(m) for c in range(n)}
return (m, n), pay
def random_game(rng, sizes, lo, hi):
"""Return a game with integer utilities drawn uniformly from lo to hi (inclusive), as Fraction."""
sizes = tuple(sizes)
pay = {s: tuple(Fraction(rng.randint(lo, hi)) for _ in sizes) for s in profiles(sizes)}
return sizes, pay
def _replace(s, i, a):
return s[:i] + (a,) + s[i + 1:]
def _weight(sigma, s, skip=None):
w = Fraction(1)
for k, a in enumerate(s):
if k != skip:
w *= sigma[k][a]
if w == 0:
return w
return w
def expected_utility(game, i, sigma):
"""Return u_i(sigma), the expected utility of player i when the players draw independently."""
sizes, pay = game
return sum((_weight(sigma, s) * pay[s][i] for s in profiles(sizes)), Fraction(0))
def deviation_payoffs(game, i, sigma):
"""Return the list of u_i(a, sigma_-i) for every pure strategy a of player i."""
sizes, pay = game
out = [Fraction(0)] * sizes[i]
for s in profiles(sizes):
w = _weight(sigma, s, skip=i)
if w:
out[s[i]] += w * pay[s][i]
return out
def pure_best_responses(game, i, sigma):
"""Return the sorted list of the pure strategies of player i that maximize u_i(a, sigma_-i)."""
d = deviation_payoffs(game, i, sigma)
best = max(d)
return [a for a, v in enumerate(d) if v == best]
def max_gain(game, sigma):
"""Return the largest gain of any player from a pure deviation: max_i (max_a u_i(a, sigma_-i) - u_i(sigma)).
The result is never negative, because u_i(sigma) is an average of the deviation payoffs.
"""
sizes, _ = game
gain = Fraction(0)
for i in range(len(sizes)):
d = deviation_payoffs(game, i, sigma)
u = sum((p * v for p, v in zip(sigma[i], d)), Fraction(0))
gain = max(gain, max(d) - u)
return gain
def is_distribution(p):
"""Return True if p (a sequence, or a dict of probabilities) is nonnegative and sums to exactly 1."""
vals = list(p.values()) if isinstance(p, dict) else list(p)
return all(v >= 0 for v in vals) and sum(vals, Fraction(0)) == 1
def _is_mixed_profile(game, sigma):
sizes, _ = game
return len(sigma) == len(sizes) and all(
len(sigma[i]) == k and is_distribution(sigma[i]) for i, k in enumerate(sizes))
def is_nash(game, sigma):
"""Return True if sigma is a mixed Nash equilibrium: no pure deviation gains for any player."""
return _is_mixed_profile(game, sigma) and max_gain(game, sigma) == 0
def is_epsilon_nash(game, sigma, eps):
"""Return True if no player gains more than eps by a pure deviation (the additive form)."""
return _is_mixed_profile(game, sigma) and max_gain(game, sigma) <= eps
def _check_dist(game, dist):
sizes, _ = game
allowed = set(profiles(sizes))
return all(s in allowed for s in dist) and is_distribution(dist)
def is_correlated(game, dist):
"""Return True if dist is a correlated equilibrium.
For every player i and every pair a, b of its pure strategies, the sum over the profiles s
with s_i = a of dist(s) (u_i(s) - u_i(b, s_-i)) is at least 0.
"""
sizes, pay = game
if not _check_dist(game, dist):
return False
for i, k in enumerate(sizes):
for a in range(k):
rows = [(q, s) for s, q in dist.items() if s[i] == a and q]
for b in range(k):
if b != a and sum((q * (pay[s][i] - pay[_replace(s, i, b)][i]) for q, s in rows), Fraction(0)) < 0:
return False
return True
def is_coarse_correlated(game, dist):
"""Return True if dist is a coarse correlated equilibrium.
For every player i and every pure strategy b, E_{s ~ dist} u_i(s) >= E_{s ~ dist} u_i(b, s_-i).
"""
sizes, pay = game
if not _check_dist(game, dist):
return False
for i, k in enumerate(sizes):
here = sum((q * pay[s][i] for s, q in dist.items()), Fraction(0))
for b in range(k):
if sum((q * pay[_replace(s, i, b)][i] for s, q in dist.items()), Fraction(0)) > here:
return False
return True
def pure_nash_brute(game):
"""Return the list of all pure Nash equilibria, found by checking every profile."""
sizes, pay = game
out = []
for s in profiles(sizes):
if all(pay[s][i] >= pay[_replace(s, i, b)][i] for i in range(len(sizes)) for b in range(sizes[i])):
out.append(s)
return out
dmp_half_approximate_nash.py 34 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/dmp-half-approximate-nash/. The authors are listed in prov/F0ZSX8.jsonl.
"""The Daskalakis-Mehta-Papadimitriou algorithm for a 1/2-approximate Nash equilibrium.
The row player gets A[i][j] and the column player gets B[i][j]; both maximize. If all the
payoffs are in [0, 1], the output is a 1/2-Nash equilibrium in the additive sense: no player
gains more than 1/2 by a deviation. The method reads one row of B and one column of A, so
it reads m + n entries. Ties go to the smallest index.
"""
from fractions import Fraction
def dmp(A, B, i=0):
"""Return (x, y): x mixes row i and row k with weight 1/2 each, y is the pure column j."""
m, n = len(A), len(A[0])
j = max(range(n), key=lambda c: (B[i][c], -c)) # @line L1
k = max(range(m), key=lambda r: (A[r][j], -r)) # @line L2
x = [Fraction(0)] * m # @line L3
x[i] += Fraction(1, 2)
x[k] += Fraction(1, 2)
y = [Fraction(0)] * n # @line L4
y[j] = Fraction(1)
return x, y # @line L5
def gains(A, B, x, y):
"""Return the largest gain of the row player and of the column player from a pure deviation."""
m, n = len(A), len(A[0])
Ay = [sum((Fraction(A[r][c]) * y[c] for c in range(n)), Fraction(0)) for r in range(m)]
xB = [sum((x[r] * Fraction(B[r][c]) for r in range(m)), Fraction(0)) for c in range(n)]
u = sum((x[r] * Ay[r] for r in range(m)), Fraction(0))
v = sum((xB[c] * y[c] for c in range(n)), Fraction(0))
return max(Ay) - u, max(xB) - v
test_dmp_half_approximate_nash.py 115 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/dmp-half-approximate-nash/. The authors are listed in prov/F0ZSX8.jsonl.
import random
from fractions import Fraction
from agtgame import from_bimatrix, is_epsilon_nash, is_nash, max_gain
from dmp_half_approximate_nash import dmp, gains
F = Fraction
HALF = F(1, 2)
def random_unit_matrix(rng, m, n, den):
return [[F(rng.randint(0, den), den) for _ in range(n)] for _ in range(m)]
class CountingMatrix:
"""A matrix that counts how many entries are read."""
def __init__(self, rows):
self.rows = rows
self.reads = 0
def __len__(self):
return len(self.rows)
def __getitem__(self, r):
return CountingRow(self, self.rows[r])
class CountingRow:
def __init__(self, owner, row):
self.owner = owner
self.row = row
def __len__(self):
return len(self.row)
def __getitem__(self, c):
self.owner.reads += 1
return self.row[c]
def test_tight_example_gains_are_exactly_half():
for a, b in [(0, 0), (1, 1), (F(1, 3), F(2, 3))]:
A = [[0, a], [1, b]]
B = [[1, 1], [0, 1]]
x, y = dmp(A, B, 0)
assert x == [HALF, HALF] and y == [1, 0]
assert gains(A, B, x, y) == (HALF, HALF)
assert max_gain(from_bimatrix(A, B), [x, y]) == HALF
def test_pure_equilibrium_when_k_equals_i():
# Prisoner's dilemma scaled to [0, 1]: defect (row 1, column 1) is dominant.
A = [[F(3, 5), 0], [1, F(1, 5)]]
B = [[F(3, 5), 1], [0, F(1, 5)]]
x, y = dmp(A, B, 1)
assert x == [0, 1] and y == [0, 1]
assert is_nash(from_bimatrix(A, B), [x, y])
def test_check_games():
# Battle of the sexes and matching pennies, scaled to [0, 1].
bos = ([[1, 0], [0, HALF]], [[HALF, 0], [0, 1]])
mp = ([[1, 0], [0, 1]], [[0, 1], [1, 0]])
chicken = ([[0, 1], [F(2, 7), F(6, 7)]], [[0, F(2, 7)], [1, F(6, 7)]])
for A, B in (bos, mp, chicken):
g = from_bimatrix(A, B)
for i in range(len(A)):
x, y = dmp(A, B, i)
assert is_epsilon_nash(g, [x, y], HALF)
# In matching pennies the bound 1/2 is reached from row 0.
x, y = dmp(*mp, 0)
assert x == [HALF, HALF] and y == [0, 1]
assert gains(*mp, x, y) == (HALF, 0)
def test_random_games_every_start_row():
rng = random.Random(20261120)
for _ in range(300):
m, n = rng.randint(1, 6), rng.randint(1, 6)
A = random_unit_matrix(rng, m, n, rng.choice([1, 2, 5, 12]))
B = random_unit_matrix(rng, m, n, rng.choice([1, 2, 5, 12]))
g = from_bimatrix(A, B)
for i in range(m):
x, y = dmp(A, B, i)
assert sum(x) == 1 and sum(y) == 1 and min(x) >= 0
assert sum(1 for p in x if p) <= 2 and sum(1 for p in y if p) == 1
gr, gc = gains(A, B, x, y)
assert gr <= HALF and gc <= HALF
assert max_gain(g, [x, y]) == max(gr, gc)
assert is_epsilon_nash(g, [x, y], HALF)
def test_gain_scales_with_the_payoff_range():
rng = random.Random(7)
for _ in range(200):
m, n = rng.randint(1, 5), rng.randint(1, 5)
lo, hi = rng.randint(-9, 0), rng.randint(1, 9)
A = [[rng.randint(lo, hi) for _ in range(n)] for _ in range(m)]
B = [[rng.randint(lo, hi) for _ in range(n)] for _ in range(m)]
x, y = dmp(A, B, rng.randrange(m))
gr, gc = gains(A, B, x, y)
assert gr <= F(hi - lo, 2) and gc <= F(hi - lo, 2)
def test_reads_m_plus_n_entries():
rng = random.Random(3)
for m, n in [(1, 1), (3, 5), (8, 2), (10, 10)]:
A = CountingMatrix(random_unit_matrix(rng, m, n, 4))
B = CountingMatrix(random_unit_matrix(rng, m, n, 4))
dmp(A, B, m - 1)
assert B.reads == n and A.reads == m
History
Althöfer (1994) had shown that some games need supports of logarithmic size for a -approximation, and Lipton, Markakis and Mehta (2003) had given a quasi-polynomial algorithm. Daskalakis, Mehta and Papadimitriou presented the simple method at WINE 2006, with the journal version in Theoretical Computer Science in 2009. The following year they gave the bound at EC 2007, where Feder, Nazerzadeh and Saberi also showed that small supports cannot go below . The bound then went down to in 2007 and 2008, and to in 2022.
References
- Constantinos Daskalakis, Aranyak Mehta and Christos H. Papadimitriou, A note on approximate Nash equilibria, Theoretical Computer Science 410(17) (2009), 1581-1588, the linear-time algorithm that examines two strategies of one player and one of the other and reaches a 1/2-approximate equilibrium; conference version in WINE 2006
- Constantinos Daskalakis, Aranyak Mehta and Christos H. Papadimitriou, Progress in approximate Nash equilibria, Proceedings of the 8th ACM Conference on Electronic Commerce (EC 2007), 355-358, the improvement to about 0.38 with a linear program and larger supports
- Haralampos Tsaknakis and Paul G. Spirakis, An optimization approach for approximate Nash equilibria, Internet Mathematics 5(4) (2008), 365-382, the descent method that reaches a 0.3393-approximation
- Argyrios Deligkas, Michail Fasoulakis and Evangelos Markakis, A polynomial-time algorithm for 1/3-approximate Nash equilibria in bimatrix games, ACM Transactions on Algorithms 19(4) (2023), 31:1-31:17, the (1/3 + delta)-approximation in polynomial time; conference version in ESA 2022
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag F0ZSX8 Edit this page History Report an error Markdown