Algorithm Search⌘K

Algorithmadvanced

Brams-Taylor procedure

Also called Brams-Taylor envy-free protocol.

The first finite envy-free cake cutting protocol for any number of agents, but its number of steps has no bound in n alone.

Time
∞ worst
Space
∞ extra
Where
n = the number of agents
Properties
deterministicofflineiterative

The Brams-Taylor procedure is a finite protocol that divides a cake among any number nn of agents so that no agent envies another. It was the first such protocol for n≥4n \ge 4. It divides the cake part by part, and keeps dividing the leftover until each agent has an irrevocable advantage over each other agent, so that the last leftover can go to anyone. Its difference from the other envy-free protocols is its cost: it always stops, but the number of steps depends on the valuations and has no bound in terms of nn alone. The Selfridge-Conway procedure handles only three agents, with at most five cuts; the Stromquist moving knife gives connected pieces to three agents with continuous knives; and the Aziz-Mackenzie protocol handles nn agents with a bound that depends only on nn.

In plain words

Several friends share a cake. The method gives out most of the cake fairly in one round, but a few crumbs are left over. It gives out most of the crumbs fairly in the next round, and so on.

The key idea is a lead that cannot be lost. Suppose one friend thinks its own piece is better than a second friend's piece by more than all the crumbs that are left. Then that friend will never envy the second friend, even if the second friend gets every crumb later. The method keeps going until every friend has such a lead over every other friend. Then it hands the last crumbs to anyone and stops.

The method always ends, but how many rounds it needs depends on how the friends value the cake, and it can be very large.

The problem

There are nn agents and a cake [0,1][0, 1]. Each agent ii has a nonnegative, additive and nonatomic valuation ViV_i with Vi([0,1])=1V_i([0, 1]) = 1. The protocol asks queries in the Robertson-Webb model and must output disjoint pieces X1,…,XnX_1, \dots, X_n, each a finite union of intervals, that cover the cake, with Vi(Xi)≥Vi(Xj)V_i(X_i) \ge V_i(X_j) for all ii and jj.

Let X1,…,XnX_1, \dots, X_n be the pieces given out so far and RR the leftover. Agent ii has an irrevocable advantage over agent jj if

Vi(Xi)−Vi(Xj)≥Vi(R).V_i(X_i) - V_i(X_j) \ge V_i(R).

Then ii does not envy jj, even if jj later gets all of RR.

The algorithm

The page gives the structure of the protocol. The details of the sub-protocols are in the paper of Brams and Taylor and in their book.

  1. BRAMS-TAYLOR(agents 1, …, n)
  2. 1R ← [0, 1]; X_i ← ∅ for every agent i
  3. 2for each ordered pair (i, j) of different agents:
  4. 3while i has no irrevocable advantage over j with respect to R:
  5. 4divide a part P of R among all n agents with no envy, ▷ a trimming round
  6. 5so that i gets more of P than j does, in the eyes of i
  7. 6add each agent's part of P to its piece X
  8. 7R ← R minus P
  9. 8give R to any agent
  10. 9return X_1, …, X_n

A trimming round generalizes the first stage of the Selfridge-Conway procedure. One agent cuts the leftover into pieces that are equal to it, the other agents trim pieces to create ties, and the agents choose in an order that makes the division of the untrimmed parts envy-free. The trimmings form the new leftover. To make a lead of agent ii over a chosen agent jj, Brams and Taylor use the fact that, if ii and jj value some part of the leftover differently, the cake can be cut so that ii gets a part it values more than the part of jj.

The code of this page is a toy, not the protocol for nn agents. It works for three agents only. It keeps the loop over ordered pairs, but each round is the first stage of the Selfridge-Conway procedure with ii as the cutter, which gives ii an irrevocable advantage over whichever agent takes the trimmed piece, not over a chosen jj. So the toy caps the number of rounds, and at the cap it divides the leftover with the second stage of the Selfridge-Conway procedure.

Example

The first stage of the Selfridge-Conway procedure shows how a round makes an irrevocable advantage. Three agents, Alice, Bob and Charlie, have these values for four parts of the cake: A′A' and YY, which together form a piece AA, and two pieces BB and CC.

A′A' YY BB CC
Alice 1/4 1/12 1/3 1/3
Bob 3/10 1/5 3/10 1/5
Charlie 2/5 0 3/10 3/10

Alice cut the cake into AA, BB and CC, each worth 1/31/3 to her. Bob liked AA best, at 1/21/2, and trimmed it to A′A', worth 3/103/10 to him, the same as his second best piece BB. The trimming YY is the leftover. Charlie chooses first and takes A′A'. Bob takes BB, and Alice takes CC. No one envies another on A′A', BB and CC.

Alice values her piece CC at 1/31/3 and the piece A′A' of Charlie at 1/41/4. The difference is 1/121/12, which is her value for YY. So Alice has an irrevocable advantage over Charlie: even if Charlie gets all of YY, his piece is AA, which is worth 1/31/3 to her. Alice has no such advantage over Bob, whose piece BB she values at 1/31/3. The rest of the protocol must still deal with YY and the other pairs.

Correctness

Advantages last. Suppose ii has an irrevocable advantage over jj with respect to RR. A round divides a part PP of RR with no envy, so ii values its own part of PP at least as much as the part of jj. After the round, Vi(Xi)−Vi(Xj)V_i(X_i) - V_i(X_j) does not decrease, and the new leftover R∖PR \setminus P has value at most Vi(R)V_i(R) to ii. So the advantage remains.

No envy at the end. Each round divides its part with no envy, so after the loop there is no envy on the pieces given out. When the loop ends, every agent has an irrevocable advantage over every other agent. Line L8 gives RR to some agent kk. For each i≠ki \ne k, Vi(Xi)≥Vi(Xk)+Vi(R)V_i(X_i) \ge V_i(X_k) + V_i(R), which is the value of the new piece of kk to ii. No other piece changes. So the final division is envy-free, and, as it covers the whole cake, also proportional.

Finite. Brams and Taylor prove that each while loop ends after finitely many rounds, for every choice of the valuations. This is the part that depends on the valuations, so it gives no bound in terms of nn.

Proof: The Brams-Taylor procedure is envy-free when it stops, and the toy for three agents is envy-freepartial

Setting. The cake is [0,1][0, 1]. Agents 1,…,n1, \dots, n have nonnegative, additive and nonatomic valuations ViV_i with Vi([0,1])=1V_i([0, 1]) = 1. At each moment the pieces X1,…,XnX_1, \dots, X_n given out so far and the leftover RR are disjoint and cover the cake. Agent ii has an irrevocable advantage over agent jj if Vi(Xi)−Vi(Xj)≥Vi(R)V_i(X_i) - V_i(X_j) \ge V_i(R). We refer to the lines L1 to L9 of the page. This proof shows that the protocol is envy-free when it stops, and that the toy for three agents in impl/python is envy-free and stops. It does not prove that each while loop of the protocol for nn agents ends; that is the theorem of Brams and Taylor (1995), and it is the reason for the status "partial".

Lemma 1 (advantages last). If ii has an irrevocable advantage over jj before a round of lines L4 to L7, it has one after the round.

Proof. The round gives parts P1,…,PnP_1, \dots, P_n of a part PP of RR with no envy, so Vi(Pi)≥Vi(Pj)V_i(P_i) \ge V_i(P_j). After the round, Vi(Xi∪Pi)−Vi(Xj∪Pj)≥Vi(Xi)−Vi(Xj)≥Vi(R)≥Vi(R∖P)V_i(X_i \cup P_i) - V_i(X_j \cup P_j) \ge V_i(X_i) - V_i(X_j) \ge V_i(R) \ge V_i(R \setminus P), because ViV_i is additive and nonnegative. □\square

Lemma 2 (no envy at the end). If the loop of lines L2 to L7 ends, the division of line L9 is envy-free.

Proof. The loop for the pair (i,j)(i, j) ends only when ii has an irrevocable advantage over jj. By Lemma 1 the advantage holds until the end of the loop, so at line L8 every agent has an irrevocable advantage over every other agent. Line L8 gives RR to an agent kk. For i≠ki \ne k, Vi(Xi)≥Vi(Xk)+Vi(R)=Vi(Xk∪R)V_i(X_i) \ge V_i(X_k) + V_i(R) = V_i(X_k \cup R). For ii and jj that are both different from kk, nothing changes, and Vi(Xi)−Vi(Xj)≥Vi(R)≥0V_i(X_i) - V_i(X_j) \ge V_i(R) \ge 0. Agent kk only gains. So no agent envies another. □\square

The toy. The toy has n=3n = 3. Each round is stage one of the Selfridge-Conway procedure on RR, with ii as the cutter, cc: the cutter cuts RR into three pieces of value Vc(R)/3V_c(R)/3 each; the trimmer tt trims its best piece, if it is strictly best, to the value of its second best piece, and the trimmings are the new leftover R′R'; the chooser picks a best piece; the trimmer takes the trimmed piece if it is still there, and otherwise a best remaining piece; the cutter takes the last piece.

Lemma 3 (a toy round). A toy round divides R∖R′R \setminus R' with no envy. If TT is the agent that takes the trimmed piece, then Vc(Pc)−Vc(PT)=Vc(R′)V_c(P_c) - V_c(P_T) = V_c(R').

Proof. The chooser picks first, so it envies no one. The trimmer values the trimmed piece and its second best piece equally and both at least as much as the third piece. At most one of these two is taken by the chooser, so the trimmer gets a piece of the largest value among the three pieces as they are after the trim. The cutter values each untrimmed piece at Vc(R)/3V_c(R)/3 and the trimmed piece at Vc(R)/3−Vc(R′)V_c(R)/3 - V_c(R'). The trimmed piece is never left for the cutter, so the cutter gets an untrimmed piece and envies no one. Its gain over TT is Vc(R)/3−(Vc(R)/3−Vc(R′))=Vc(R′)V_c(R)/3 - (V_c(R)/3 - V_c(R')) = V_c(R'). If there is no trim, R′=∅R' = \emptyset and the gain is 0=Vc(R′)0 = V_c(R'). □\square

By Lemma 3 and induction over the earlier rounds, each of which is envy-free, after a toy round with cutter cc the agent cc has an irrevocable advantage over TT.

Lemma 4 (the fallback). Suppose cc has an irrevocable advantage over TT, and let uu be the third agent. If uu cuts RR into three pieces of value Vu(R)/3V_u(R)/3 each, then TT picks a best piece, then cc picks a best remaining piece, and uu takes the last piece, the final division is envy-free.

Proof. Before the fallback there is no envy on the pieces given out, by Lemma 3. TT picks first, so it envies no one on RR. Agent cc envies no one on RR except possibly TT, and Vc(Xc)−Vc(XT)≥Vc(R)V_c(X_c) - V_c(X_T) \ge V_c(R) covers any part of RR that TT gets. Agent uu values the three parts of RR equally. Adding an envy-free division of RR to an envy-free division of the rest, with the one exception covered by the advantage, gives an envy-free division. □\square

Theorem. The toy stops after at most max_rounds rounds and returns an envy-free division of [0,1][0, 1] among three agents.

Proof. Each pass through the while loop either returns through the fallback, when the round counter has reached max_rounds, or runs one round and adds 1 to the counter. So there are at most max_rounds rounds. If the toy returns through the fallback, the last round had a cutter cc and a taker TT, and cc still has an irrevocable advantage over TT by Lemma 1, so the result is envy-free by Lemma 4. The condition max_rounds >= 1 makes sure that there was a last round. If the loops over all ordered pairs end, the result is envy-free by Lemma 2. In both cases every interval of RR goes to some agent, so the pieces cover the cake. □\square

The toy chooses which agent takes the trimmed piece only through the order of the roles, so it can fail to make an advantage of ii over jj in a round. This is why it needs the cap. The protocol of Brams and Taylor uses a different round for nn agents, which this proof does not cover.

Complexity

The number of queries is finite for every input, but there is no function ff such that the protocol uses at most f(n)f(n) queries for all valuations. The number of rounds in line L3 depends on the valuations, through how much agent ii gains over agent jj in each round compared with the value of the leftover. The extra space is the list of pieces, which grows with the number of cuts, so it has no bound in nn either. This unboundedness is a theorem about this protocol, stated by Brams and Taylor and by Aziz and Mackenzie; it says nothing about other protocols.

Properties

  • Envy-free and proportional, for any number of agents.
  • Finite but unbounded. It ends on every input, after a number of steps that is not bounded by a function of nn.
  • Pieces are not connected. Each agent can get many intervals. By Stromquist's impossibility theorem, no finite protocol can guarantee connected envy-free pieces for n≥3n \ge 3.
  • Discrete. It uses only cuts and evaluations, with no moving knives.

Variants and improvements

  • Bounded protocols. Aziz and Mackenzie gave a bounded envy-free protocol for four agents in 2016, and then the Aziz-Mackenzie protocol for any nn, with a bound that is a tower of exponentials in nn.
  • Three agents. For n=3n = 3, the Selfridge-Conway procedure is a bounded special case of the same ideas: one trimming round, then a division of the leftover in which the agent with the irrevocable advantage chooses last.
  • Chores. A bounded envy-free protocol for chores with any number of agents was given later by Dehghani, Farhadi, Hajiaghayi and Yami (2018).

When to use it

Use the Brams-Taylor procedure as a proof that envy-free divisions can be found by a finite protocol for any nn, or for teaching the idea of irrevocable advantage. For computing, it is impractical: no bound in nn holds. For three agents use Selfridge-Conway. For more agents, a protocol with a bound, or an approximately envy-free method, is the better choice.

Pitfalls

  • Finite is not bounded. Each run stops, but for a fixed nn there are valuations that make it run longer than any given number of steps.
  • Advantage over whom. An irrevocable advantage of ii over jj says nothing about ii and a third agent kk. The protocol needs it for every ordered pair.
  • Giving out the leftover too early. Giving RR to an agent kk before every other agent has an advantage over kk can create envy.

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.

agtcake.pyI0RawGitHub
# 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()
brams_taylor_procedure.py 138 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/brams-taylor-procedure/. The authors are listed in prov/MN3VTM.jsonl.
"""A toy version of the Brams-Taylor procedure, for three agents only.

This is a toy. It keeps the outer loop of the page: for each ordered pair
(i, j) it runs rounds on the leftover until agent i has an irrevocable
advantage over agent j, and then it gives the last leftover to any agent.
It does not implement the sub-protocols of Brams and Taylor for n agents.
Each round is the first stage of the Selfridge-Conway procedure, with agent
i as the cutter, so the toy works for three agents only. A round gives i an
advantage over the agent that takes the trimmed piece, but it cannot choose
that agent, so the loop has no bound in general. After max_rounds rounds the
toy stops the loop and divides the leftover with the second stage of the
Selfridge-Conway procedure, which is envy-free because the cutter of the
last round has an irrevocable advantage over the taker of its trimmed piece.
"""

from fractions import Fraction

from agtcake import Oracle

Interval = tuple[Fraction, Fraction]
Piece = list[Interval]


def piece_eval(oracle: Oracle, i: int, piece: Piece) -> Fraction:
    """V_i(piece), with one eval query per interval."""
    return sum((oracle.eval_query(i, a, b) for a, b in piece), Fraction(0))


def split_prefix(oracle: Oracle, i: int, piece: Piece, t: Fraction) -> tuple[Piece, Piece]:
    """Split a piece into a prefix of value t to agent i and the rest.

    The intervals of the piece are in increasing order. Needs t <= V_i(piece).
    """
    head: Piece = []
    rest: Piece = []
    left = t
    for idx, (a, b) in enumerate(piece):
        v = oracle.eval_query(i, a, b)
        if v <= left and left > 0:
            head.append((a, b))
            left -= v
            continue
        x = oracle.cut_query(i, a, left) if left > 0 else a
        if x > a:
            head.append((a, x))
        if b > x:
            rest.append((x, b))
        rest.extend(piece[idx + 1:])
        break
    return head, rest


def has_advantage(own: Fraction, other: Fraction, leftover: Fraction) -> bool:
    """V_i(X_i) - V_i(X_j) >= V_i(R): agent i cannot come to envy agent j."""
    return own - other >= leftover


def advantage(oracle: Oracle, i: int, j: int, alloc: dict[int, Piece], rest: Piece) -> bool:
    return has_advantage(piece_eval(oracle, i, alloc[i]), piece_eval(oracle, i, alloc[j]),
                         piece_eval(oracle, i, rest))


def trimming_round(oracle: Oracle, rest: Piece, cutter: int, trimmer: int,
                   chooser: int) -> tuple[dict[int, Piece], Piece, int]:
    """Stage one of Selfridge-Conway on the leftover.

    Returns the three pieces given out, the new leftover (the trimmings) and
    the agent that took the trimmed piece.
    """
    third = piece_eval(oracle, cutter, rest) / 3
    p0, more = split_prefix(oracle, cutter, rest, third)
    p1, p2 = split_prefix(oracle, cutter, more, third)
    pieces = [p0, p1, p2]
    vals = [piece_eval(oracle, trimmer, p) for p in pieces]
    order = sorted(range(3), key=lambda k: (-vals[k], k))
    p, q = order[0], order[1]
    trimmings: Piece = []
    if vals[p] > vals[q]:
        pieces[p], trimmings = split_prefix(oracle, trimmer, pieces[p], vals[q])
    left = [0, 1, 2]
    cv = [piece_eval(oracle, chooser, pieces[k]) for k in left]
    c = cv.index(max(cv))
    left.remove(c)
    if p in left:
        t = p
    else:
        t = left[0] if vals[left[0]] >= vals[left[1]] else left[1]
    left.remove(t)
    give = {chooser: pieces[c], trimmer: pieces[t], cutter: pieces[left[0]]}
    taker = chooser if c == p else trimmer
    return give, trimmings, taker


def finish_stage_two(oracle: Oracle, alloc: dict[int, Piece], rest: Piece, cutter: int,
                     taker: int) -> None:
    """Stage two of Selfridge-Conway: needs that cutter has an advantage over taker."""
    other = 3 - cutter - taker
    third = piece_eval(oracle, other, rest) / 3
    a, more = split_prefix(oracle, other, rest, third)
    b, c = split_prefix(oracle, other, more, third)
    parts = [a, b, c]
    for agent in (taker, cutter):
        vals = [piece_eval(oracle, agent, part) for part in parts]
        alloc[agent].extend(parts.pop(vals.index(max(vals))))
    alloc[other].extend(parts[0])


def brams_taylor_toy(oracle: Oracle, max_rounds: int = 40) -> tuple[dict[int, Piece], int]:
    """Return an envy-free division of [0, 1] among three agents and the number of rounds."""
    if oracle.n != 3:
        raise ValueError("this toy is for three agents")
    if max_rounds < 1:
        raise ValueError("max_rounds must be at least 1")
    alloc: dict[int, Piece] = {0: [], 1: [], 2: []}
    rest: Piece = [(Fraction(0), Fraction(1))]  # @line L1
    rounds = 0
    last = (0, 1)
    for i in range(3):
        for j in range(3):  # @line L2
            if i == j:
                continue
            k = 3 - i - j
            while not advantage(oracle, i, j, alloc, rest):  # @line L3
                if rounds == max_rounds:
                    finish_stage_two(oracle, alloc, rest, *last)
                    return alloc, rounds
                trimmer, chooser = (j, k) if rounds % 2 == 0 else (k, j)  # @line L4
                # i gains over the taker of the trimmed piece, not always over j
                give, trimmings, taker = trimming_round(oracle, rest, i, trimmer, chooser)  # @line L5
                for agent, piece in give.items():
                    alloc[agent].extend(piece)  # @line L6
                rest = trimmings  # @line L7
                last = (i, taker)
                rounds += 1
    alloc[0].extend(rest)  # @line L8
    return alloc, rounds  # @line L9
test_brams_taylor_procedure.py 99 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/brams-taylor-procedure/. The authors are listed in prov/MN3VTM.jsonl.
# Tests of a toy for three agents. They do not test the protocol of Brams and Taylor for n agents.

import random
from fractions import Fraction

import pytest

from agtcake import Oracle, normalize, piece_value, random_valuation
from brams_taylor_procedure import (
    advantage,
    brams_taylor_toy,
    has_advantage,
    piece_eval,
    trimming_round,
)

F = Fraction


def check_partition(alloc) -> None:
    """The pieces are disjoint and cover [0, 1]."""
    assert sorted(alloc) == [0, 1, 2]
    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


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 test_page_example_advantage() -> None:
    # Alice values C at 1/3, the piece A' of Charlie at 1/4 and the leftover Y at 1/12.
    assert has_advantage(F(1, 3), F(1, 4), F(1, 12))
    # She values the piece B of Bob at 1/3, so she has no advantage over Bob.
    assert not has_advantage(F(1, 3), F(1, 3), F(1, 12))


def test_round_gives_cutter_an_advantage() -> None:
    rng = random.Random(5)
    for _ in range(100):
        vals = [random_valuation(rng, 6, 5) for _ in range(3)]
        o = Oracle(vals)
        rest = [(F(0), F(1))]
        give, new_rest, taker = trimming_round(o, rest, 0, 1, 2)
        alloc = {i: list(give[i]) for i in range(3)}
        # the round is envy-free on the pieces it gives out
        for i in range(3):
            for j in range(3):
                assert piece_eval(o, i, alloc[i]) >= piece_eval(o, i, alloc[j])
        assert advantage(o, 0, taker, alloc, new_rest)
        gain = piece_eval(o, 0, alloc[0]) - piece_eval(o, 0, alloc[taker])
        assert gain == piece_eval(o, 0, new_rest)


def test_identical_valuations_end_after_one_round() -> None:
    rng = random.Random(3)
    for _ in range(20):
        v = random_valuation(rng, rng.randint(1, 8), 5)
        o = Oracle([v, v, v])
        alloc, rounds = brams_taylor_toy(o)
        assert rounds == 1
        check_partition(alloc)
        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(60):
        vals = [random_valuation(rng, rng.randint(1, 6), 5) for _ in range(3)]
        o = Oracle(vals)
        alloc, rounds = brams_taylor_toy(o, max_rounds=12)
        check_partition(alloc)
        check_envy_free(vals, alloc)
        assert 1 <= rounds <= 12


def test_round_cap_uses_the_fallback() -> None:
    vals = [normalize([1, 2, 3, 1, 1, 2]), normalize([3, 1, 1, 2, 2, 1]), normalize([1, 1, 2, 3, 1, 2])]
    for cap in (1, 2, 3):
        o = Oracle(vals)
        alloc, rounds = brams_taylor_toy(o, max_rounds=cap)
        assert rounds <= cap
        check_partition(alloc)
        check_envy_free(vals, alloc)


def test_only_three_agents() -> None:
    v = normalize([1])
    with pytest.raises(ValueError):
        brams_taylor_toy(Oracle([v, v]))
    with pytest.raises(ValueError):
        brams_taylor_toy(Oracle([v, v, v]), max_rounds=0)

History

Steven Brams and Alan Taylor published the protocol in the American Mathematical Monthly in January 1995, and described it again in their 1996 book. Envy-free cake cutting for n≥4n \ge 4 agents had been an open problem since the Selfridge-Conway procedure for three agents around 1960. The question of a bounded protocol stayed open until Aziz and Mackenzie solved it in 2016.

References

  1. Steven J. Brams and Alan D. Taylor, An envy-free cake division protocol, American Mathematical Monthly 102(1) (1995), pp. 9-18 (the protocol for n agents, and irrevocable advantage)
  2. Steven J. Brams and Alan D. Taylor, Fair Division, From Cake-Cutting to Dispute Resolution, Cambridge University Press, 1996, the envy-free procedure for n persons
  3. Haris Aziz and Simon Mackenzie, A discrete and bounded envy-free cake cutting protocol for any number of agents, FOCS 2016, pp. 416-427, the introduction (the Brams-Taylor protocol is finite but unbounded)
  4. 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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of correctness
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • History with a source
  • a scene preset for the example