Algorithmcore
Selfridge-Conway procedure
Also called Selfridge-Conway discrete procedure.
A finite protocol that gives an envy-free division of a cake among three agents with at most five cuts. Each agent gets at most two intervals.
- Solves
- Cake cutting problem
- Time
- Θ(1) worst
- Space
- Θ(1) extra
- Where
- n = the number of agents (here 3)
- Properties
- deterministicofflineiterative
- Evidence
- Proof sketchCode in 1 languages
The Selfridge-Conway procedure is a finite protocol that divides a cake among three agents so that the division is envy-free: no agent values another agent's piece more than its own. It uses at most five cuts, and each agent gets at most two intervals. It differs from the three other envy-free protocols of this area as follows: the Stromquist moving knife gives connected pieces to three agents but needs continuously moving knives, the Brams-Taylor procedure works for any number of agents but has no bound on its steps, and the Aziz-Mackenzie protocol works for any number of agents with a bound that is a tower of exponentials. In the Robertson-Webb query model, the procedure makes at most 5 cut queries and 12 eval queries.
In plain words
Three friends share a cake. The first friend cuts it into three pieces that look equal to her. The second friend looks at the pieces. If two pieces tie for best in her eyes, nothing changes. If one piece looks bigger than all others, she trims a thin slice from it until it ties with her second best piece. The slice is put aside for now.
The third friend chooses first, then the second friend, then the first friend. The second friend must take the trimmed piece if it is still there. So the first friend always gets an untrimmed piece.
Now the slice is shared. The friend who did not get the trimmed piece cuts the slice into three equal parts in her eyes. The friend with the trimmed piece chooses first, then the first friend, then the cutter of the slice.
The problem
The cake is . Agents 1, 2 and 3 have nonnegative, additive and nonatomic valuations with . The protocol must output pieces , each a finite union of intervals, that are disjoint and cover the cake, with for all and . Pieces need not be connected. An envy-free division is also proportional, because . The protocol learns the valuations only by the queries and , the least with .
The algorithm
Agent 1 is the cutter, agent 2 the trimmer and agent 3 the first chooser. "Takes the piece it values most" means one eval query per piece that is left; ties go to the leftmost piece.
SELFRIDGE-CONWAY(agents 1, 2, 3)- 1
c ← CUT_1(0, 1/3); d ← CUT_1(c, 1/3); the pieces are [0, c], [c, d], [d, 1] - 2
P ← the piece agent 2 values most; Q ← the piece agent 2 values second ▷ three evals - 3
if V_2(P) > V_2(Q) then - 4
[a, b] ← P; x ← CUT_2(a, V_2(Q)); P ← [a, x]; L ← [x, b] ▷ trim P, set L aside - 5
else L ← nothing ▷ no trim needed - 6
agent 3 takes the piece it values most - 7
if P is still there then agent 2 takes P else agent 2 takes its better piece of the two left - 8
agent 1 takes the last piece - 9
if L is nothing then return - 10
T ← the agent of {2, 3} that holds P; U ← the other one - 11
U cuts L into three parts that U values at V_U(L)/3 each ▷ one eval, two cuts - 12
T takes the part it values most, then agent 1 takes its better part, U takes the last
Stage one is lines L1 to L8 and divides the cake minus the trimmings . Stage two is lines L10 to L12 and divides . Agent 2 needs no query in line L7, because it knows its values from line L2.
Example
Take six equal segments of with piecewise-constant densities. Agent 1 is uniform. Agent 2 has densities proportional to , and agent 3 to .
| step | what happens | values |
|---|---|---|
| L1 | agent 1 cuts at and | , , |
| L2 | agent 2 values | , , , so and |
| L4 | agent 2 trims to value | , |
| L6 | agent 3 values | , , , so it takes |
| L7 | is still there | agent 2 takes |
| L8 | the last piece | agent 1 takes |
| L10 | = agent 2, = agent 3 | |
| L11 | agent 3 values at and cuts at and | three parts of value to agent 3 |
| L12 | agent 2 takes , agent 1 takes | agent 3 gets |
The final values, with row giving of each agent's piece:
| 13/36 | 5/18 | 13/36 | |
| 7/18 | 7/18 | 2/9 | |
| 19/72 | 2/9 | 37/72 |
Each row has its largest entry on the diagonal, so the division is envy-free. Agent 1 ties with agent 3, and agent 2 ties with agent 1. The run made 5 cut queries and 12 eval queries. With agent 2 as and agent 3 as instead, agent 3 takes the trimmed piece , agent 2 takes , and then agent 2 cuts the trimmings.
Correctness
The proof checks each agent against each other agent, stage by stage, and adds the two stages by additivity.
- Agents 2 and 3 in stage one. Agent 3 chooses first. Agent 2 values the trimmed piece equal to its second best piece and at least as much as the third piece, so whichever piece it gets in line L7 is a best piece for it.
- Agent 1 in stage one. Agent 2 or agent 3 holds the trimmed piece, so agent 1 gets an untrimmed piece of value , which is at least the value of any stage one piece to agent 1.
- Stage two. chooses first, so it envies nobody's part. made three equal parts, so it envies nobody's part. Agent 1 chooses before . Against , agent 1 uses a stronger fact: the trimmed piece and all of together are worth exactly to agent 1, because they make up one of agent 1's equal pieces. So 's whole piece is worth at most to agent 1, which is what agent 1 already has from stage one.
The full proof, with the existence of each cut and the query count, is in proofs/correctness.md.
Proof: The Selfridge-Conway procedure is envy-free and uses at most five cutsfull
Setting. The cake is . Agents 1, 2 and 3 have nonnegative, additive and nonatomic valuations with . Single points have value 0, so two intervals that meet at one end point do not overlap in value. For and , the query returns the least with ; such an exists because is continuous and nondecreasing. We refer to the lines L1 to L12 of the page. Let be the three pieces of line L1, let and be the best and second best piece of agent 2 at line L2, and let be the third piece.
Lemma 1 (the cuts exist). Every cut query of the procedure has an answer.
Proof. Line L1 asks and then , where . Line L4 asks with , and . Line L11 asks and then with and ; here and .
Lemma 2 (stage one). After line L8, the three pieces (with when there is no trim) form, together with the trimmings , a partition of . The values satisfy:
- , and ;
- ;
- agent 3 holds a piece that it values at least as much as each of the other two pieces of stage one;
- agent 1 holds or , never the trimmed piece when a trim happened.
Proof. Line L1 makes three pieces of value each to agent 1. Line L4 replaces by and , so , and and keep the value . This gives item 1. Item 2: with a trim, by line L4, and by the choice of ; without a trim, by line L3. Item 3 holds because agent 3 chooses first, in line L6, from all three pieces. For item 4: if agent 3 did not take , line L7 gives to agent 2. If agent 3 took , then is gone. In both cases is not left for agent 1 in line L8.
Lemma 3 (agent 2 in stage one). Agent 2 holds a piece that it values at least as much as each of the other two pieces of stage one.
Proof. If agent 2 takes in line L7, its value is by Lemma 2, so it is a best piece. If agent 3 took , agent 2 takes the better of and by its own values, and that value is .
Theorem 1 (envy-free). The final division is envy-free: for all .
Proof. Without a trim, line L9 returns after stage one. Each is one of . Agents 2 and 3 do not envy by Lemma 2 item 3 and Lemma 3, and agent 1 values all three pieces at .
With a trim, let be the agent of that holds and the other one (line L10). Line L11 cuts into with . In line L12, takes a part first, agent 1 takes a part second, and takes the last part. Write for the stage one piece and for the part of of agent , so and by additivity.
- Agent : for each by Lemma 2 item 3 or Lemma 3, and because chooses first among all three parts.
- Agent : by the same lemmas, and for every because made the parts.
- Agent 1: against , by Lemma 2 items 1 and 4, and because agent 1 chooses before . Against , , by Lemma 2 item 1 and monotonicity.
Adding the two inequalities for and for gives in each case.
Theorem 2 (partition and pieces). The pieces are disjoint up to end points and cover . Each is a union of at most two intervals.
Proof. Stage one splits into and (Lemma 2), and line L11 splits into three intervals. Each agent gets one interval in stage one and at most one interval in stage two.
Theorem 3 (cost). The procedure makes at most 5 cut queries and at most 12 eval queries.
Proof. Cuts: two in line L1, at most one in line L4 and at most two in line L11. Evals: three by agent 2 in line L2 and three by agent 3 in line L6; agent 2 needs no new query in line L7, because it knows its values from line L2 and . In stage two, makes one eval in line L11, makes three and agent 1 makes two in line L12. The total is at most .
Complexity
The number of agents is fixed at three, so the cost is a constant.
- At most 5 cut queries: two in line L1, one in line L4 and two in line L11. Without a trim, only 2.
- At most 12 eval queries: three each in lines L2 and L6, one in line L11, and three plus two in line L12.
- The time outside the queries is , and the output has at most six intervals.
Properties
- Envy-free and proportional. Envy-freeness implies proportionality for additive valuations.
- Not connected. Agents 2 and 3 can each get two intervals, and so can agent 1. With connected pieces, no finite protocol in the Robertson-Webb model can be envy-free for three agents, by Stromquist's impossibility theorem.
- Safe for an honest agent. Each agent that answers by its own valuation gets an envy-free share, whatever the other agents do. The proof for agent uses only agent 's own answers and the order of choices.
- Not equitable and not Pareto optimal in general. In the example, the agents get , and .
Variants and improvements
- More agents. Brams and Taylor found the first finite envy-free protocol for every number of agents, with no bound on its steps. Aziz and Mackenzie gave a bounded protocol for four agents and then for any number of agents.
- Connected pieces. The Stromquist moving knife gives each of three agents one interval, at the price of continuous knives.
- Chores. For a burden that each agent wants to minimize, the roles of choosing change; see chore division.
- Proportional only. If proportionality is enough, divide and choose style protocols such as the Dubins-Spanier moving knife need fewer queries per agent and give connected pieces.
When to use it
Use the Selfridge-Conway procedure when exactly three agents must share a divisible good without envy, and each agent accepts a piece made of two intervals. It is short enough to run by hand. For connected pieces, use a moving-knife method; for more agents, the known envy-free protocols are much larger.
Pitfalls
- Letting agent 2 skip the trimmed piece. If agent 3 leaves the trimmed piece and agent 2 may choose freely, agent 1 can be left with it. Agent 1 values it at less than and then envies.
- The wrong cutter in stage two. The agent without the trimmed piece cuts the trimmings, and the holder of the trimmed piece chooses first. If the holder cut, the other agent would choose before agent 1, and agent 1 could envy it, because agent 1's extra margin holds only against the holder of the trimmed piece.
- Agent 1 choosing last in stage two. Agent 1 must choose before ; agent 1 has no margin against from stage one.
- Stopping after stage one. Stage one alone leaves the trimmings unassigned. The partial division is envy-free, but it is not a division of the whole cake.
- Trimming on a tie. When agent 2's two best pieces tie, there is nothing to trim. A trim of zero value gives empty trimmings and the same result with one more query.
Implementations
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/.
"""Piecewise-constant cake valuations and a Robertson-Webb query oracle.
The cake is the interval [0, 1]. A valuation is a list of k nonnegative
Fraction densities d[0], ..., d[k - 1]. Density d[j] holds on the segment
[j/k, (j + 1)/k], so that segment has value d[j] / k. A valuation is
normalized when the value of the whole cake is 1, that is, sum(d) = k.
All numbers are Fraction, so every value and every cut point is exact.
This module holds no cake cutting protocol.
"""
from fractions import Fraction
from random import Random
from typing import Optional, Sequence
Valuation = list[Fraction]
Interval = tuple[Fraction, Fraction]
ZERO = Fraction(0)
ONE = Fraction(1)
def normalize(dens: Sequence) -> Valuation:
"""Scale nonnegative densities so that the whole cake has value 1."""
d = [Fraction(x) for x in dens]
if not d:
raise ValueError("a valuation needs at least one segment")
if any(x < 0 for x in d):
raise ValueError("densities must be nonnegative")
total = sum(d)
if total == 0:
raise ValueError("densities must not all be zero")
k = len(d)
return [x * k / total for x in d]
def _check_point(x: Fraction) -> None:
if x < 0 or x > 1:
raise ValueError("a point of the cake must be in [0, 1]")
def value(v: Valuation, a, b) -> Fraction:
"""Return the value of the interval [a, b] under v. Needs 0 <= a <= b <= 1."""
a, b = Fraction(a), Fraction(b)
_check_point(a)
_check_point(b)
if a > b:
raise ValueError("value(v, a, b) needs a <= b")
k = len(v)
total = ZERO
j = min(int(a * k), k - 1)
while j < k:
lo = Fraction(j, k)
if lo >= b:
break
hi = Fraction(j + 1, k)
left = a if a > lo else lo
right = b if b < hi else hi
if right > left:
total += v[j] * (right - left)
j += 1
return total
def cut(v: Valuation, a, t) -> Optional[Fraction]:
"""Return the least x >= a with value(v, a, x) = t, or None if there is none."""
a, t = Fraction(a), Fraction(t)
_check_point(a)
if t < 0:
raise ValueError("cut(v, a, t) needs t >= 0")
if t == 0:
return a
k = len(v)
pos = a
rest = t
j = min(int(a * k), k - 1)
while j < k:
hi = Fraction(j + 1, k)
d = v[j]
if d > 0 and hi > pos:
here = d * (hi - pos)
if rest <= here:
return pos + rest / d
rest -= here
if hi > pos:
pos = hi
j += 1
return None
def piece_value(v: Valuation, piece: Sequence[Interval]) -> Fraction:
"""Return the value of a piece, given as a list of intervals (a, b)."""
return sum((value(v, a, b) for a, b in piece), ZERO)
def random_valuation(rng: Random, k: int, hi: int) -> Valuation:
"""Return a normalized valuation with k segments and integer densities in 0..hi."""
if k < 1 or hi < 1:
raise ValueError("random_valuation needs k >= 1 and hi >= 1")
while True:
dens = [rng.randint(0, hi) for _ in range(k)]
if any(dens):
return normalize(dens)
class Oracle:
"""Answer Robertson-Webb queries for a list of valuations and count them.
eval_query(i, a, b) returns V_i([a, b]). cut_query(i, a, t) returns the
least x with V_i([a, x]) = t, or None. The lists evals and cuts hold the
number of queries of each kind for each agent.
"""
def __init__(self, valuations: Sequence[Valuation]) -> None:
self.valuations = [list(v) for v in valuations]
n = len(self.valuations)
self.evals = [0] * n
self.cuts = [0] * n
@property
def n(self) -> int:
return len(self.valuations)
def eval_query(self, i: int, a, b) -> Fraction:
self.evals[i] += 1
return value(self.valuations[i], a, b)
def cut_query(self, i: int, a, t) -> Optional[Fraction]:
self.cuts[i] += 1
return cut(self.valuations[i], a, t)
def total_evals(self) -> int:
return sum(self.evals)
def total_cuts(self) -> int:
return sum(self.cuts)
def total(self) -> int:
return self.total_evals() + self.total_cuts()
selfridge_conway_procedure.py 73 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/selfridge-conway-procedure/. The authors are listed in prov/9GXB9K.jsonl.
from fractions import Fraction
from agtcake import Oracle
Interval = tuple[Fraction, Fraction]
Piece = list[Interval]
def _best(oracle: Oracle, i: int, pieces: list[Interval]) -> int:
"""Return the index of the piece agent i values most (ties: the smallest index).
One eval query per piece.
"""
vals = [oracle.eval_query(i, a, b) for a, b in pieces]
top = max(vals)
return vals.index(top)
def selfridge_conway(oracle: Oracle) -> dict[int, Piece]:
"""The Selfridge-Conway procedure for three agents.
Agents 0, 1 and 2 of the code are agents 1, 2 and 3 of the page: agent 0
cuts, agent 1 trims and agent 2 chooses first. The result maps each agent
to its piece, a list of at most two intervals.
"""
if oracle.n != 3:
raise ValueError("the Selfridge-Conway procedure is for three agents")
third = Fraction(1, 3)
c = oracle.cut_query(0, 0, third) # @line L1
d = oracle.cut_query(0, c, third)
pieces: list[Interval] = [(Fraction(0), c), (c, d), (d, Fraction(1))]
vals = [oracle.eval_query(1, a, b) for a, b in pieces] # @line L2
order = sorted(range(3), key=lambda j: (-vals[j], j))
p, q = order[0], order[1]
trimmings: Interval | None
if vals[p] > vals[q]: # @line L3
a, b = pieces[p]
x = oracle.cut_query(1, a, vals[q]) # @line L4
pieces[p] = (a, x)
trimmings = (x, b)
else:
trimmings = None # @line L5
alloc: dict[int, Piece] = {}
left = [0, 1, 2]
j3 = left[_best(oracle, 2, [pieces[j] for j in left])] # @line L6
alloc[2] = [pieces[j3]]
left.remove(j3)
if p in left: # @line L7
j2 = p
elif vals[left[0]] >= vals[left[1]]:
j2 = left[0] # agent 1 knows these values from line L2
else:
j2 = left[1]
alloc[1] = [pieces[j2]]
left.remove(j2)
alloc[0] = [pieces[left[0]]] # @line L8
if trimmings is None: # @line L9
return alloc
t = 2 if j3 == p else 1 # @line L10
u = 3 - t
a, b = trimmings
w = oracle.eval_query(u, a, b) / 3 # @line L11
y = oracle.cut_query(u, a, w)
z = oracle.cut_query(u, y, w)
parts: list[Interval] = [(a, y), (y, z), (z, b)]
for agent in (t, 0): # @line L12
k = _best(oracle, agent, parts)
alloc[agent].append(parts.pop(k))
alloc[u].append(parts[0])
return alloc
test_selfridge_conway_procedure.py 96 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/selfridge-conway-procedure/. The authors are listed in prov/9GXB9K.jsonl.
import random
from fractions import Fraction
from agtcake import Oracle, normalize, piece_value, random_valuation
from selfridge_conway_procedure import selfridge_conway
F = Fraction
def check_partition(alloc) -> None:
"""The pieces are disjoint, cover [0, 1], and each has at most two intervals."""
assert sorted(alloc) == [0, 1, 2]
assert all(1 <= len(alloc[i]) <= 2 for i in range(3))
ivs = sorted(iv for i in range(3) for iv in alloc[i])
assert ivs[0][0] == 0 and ivs[-1][1] == 1
for (a1, b1), (a2, b2) in zip(ivs, ivs[1:]):
assert a1 <= b1 == a2 <= b2
assert ivs[-1][0] <= ivs[-1][1]
def check_envy_free(vals, alloc) -> None:
for i in range(3):
own = piece_value(vals[i], alloc[i])
for j in range(3):
assert own >= piece_value(vals[i], alloc[j])
def run(vals):
o = Oracle(vals)
alloc = selfridge_conway(o)
check_partition(alloc)
check_envy_free(vals, alloc)
assert o.total_cuts() <= 5
assert o.total_evals() <= 12
return o, alloc
def test_page_example() -> None:
vals = [normalize([1] * 6), normalize([3, 1, 1, 1, 2, 4]), normalize([1, 2, 3, 3, 2, 1])]
o, alloc = run(vals)
assert alloc[0] == [(F(0), F(1, 3)), (F(17, 18), F(35, 36))]
assert alloc[1] == [(F(2, 3), F(11, 12)), (F(11, 12), F(17, 18))]
assert alloc[2] == [(F(1, 3), F(2, 3)), (F(35, 36), F(1))]
table = [[piece_value(vals[i], alloc[j]) for j in range(3)] for i in range(3)]
assert table == [
[F(13, 36), F(5, 18), F(13, 36)],
[F(7, 18), F(7, 18), F(2, 9)],
[F(19, 72), F(2, 9), F(37, 72)],
]
assert o.cuts == [2, 1, 2] and o.evals == [2, 6, 4]
def test_third_agent_takes_trimmed_piece() -> None:
vals = [normalize([1] * 6), normalize([1, 1, 2, 2, 3, 3]), normalize([1, 1, 1, 2, 4, 3])]
o, alloc = run(vals)
# [2/3, 1] is trimmed to [2/3, 8/9]; the first chooser (agent 2 of the code)
# takes it, so agent 1 of the code takes its second best piece [1/3, 2/3].
assert alloc[2][0] == (F(2, 3), F(8, 9))
assert alloc[1][0] == (F(1, 3), F(2, 3))
assert alloc[0][0] == (F(0), F(1, 3))
assert o.total_cuts() == 5 and o.cuts == [2, 3, 0]
def test_identical_valuations_need_no_trim() -> None:
rng = random.Random(7)
for _ in range(30):
v = random_valuation(rng, rng.randint(1, 8), 5)
o, alloc = run([v, v, v])
assert o.total_cuts() == 2
assert all(piece_value(v, alloc[i]) == F(1, 3) for i in range(3))
def test_random_valuations() -> None:
rng = random.Random(2024)
for _ in range(300):
k = rng.randint(1, 8)
vals = [random_valuation(rng, k, 6) for _ in range(3)]
o, alloc = run(vals)
# the cutter gets at least a third, as one of its own equal pieces
assert piece_value(vals[0], alloc[0]) >= F(1, 3)
def test_trim_matches_second_best() -> None:
rng = random.Random(11)
for _ in range(200):
vals = [random_valuation(rng, 8, 4) for _ in range(3)]
o, alloc = run(vals)
if o.total_cuts() == 5:
# the agent with the trimmed piece holds it as its first interval,
# and agent 1 of the code values it as its second best of the three.
first = [alloc[i][0] for i in range(3)]
v1 = sorted((piece_value(vals[1], [iv]) for iv in first), reverse=True)
assert v1[0] == v1[1]
History
John Selfridge found the procedure around 1960 and told it to Richard Guy, who passed it on. John Horton Conway found it independently later. Neither of them published it, and Brams and Taylor describe it in their 1996 book. It was the first finite envy-free procedure for three agents. Brams and Taylor extended the trimming idea to any number of agents in 1995, and Aziz and Mackenzie gave the first bounded protocol for any number of agents in 2016.
References
- Steven J. Brams and Alan D. Taylor, Fair Division, From Cake-Cutting to Dispute Resolution, Cambridge University Press, 1996, the Selfridge-Conway procedure and its history, pp. 116-120
- Jack Robertson and William Webb, Cake-Cutting Algorithms, Be Fair If You Can, A K Peters, 1998, the envy-free procedure for three players, pp. 13-14
- Steven J. Brams and Alan D. Taylor, An envy-free cake division protocol, American Mathematical Monthly 102(1) (1995), pp. 9-18 (the extension of the trimming idea to any number of agents)
- Felix Brandt, Vincent Conitzer, Ulle Endriss, Jerome Lang and Ariel D. Procaccia (eds.), Handbook of Computational Social Choice, Cambridge University Press, 2016, Chapter 13, Ariel D. Procaccia, Cake Cutting Algorithms (pp. 311-330)
Where this leads
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 9GXB9K Edit this page History Report an error Markdown