Course Test · University: upper level

Game theory: RatMath answers

The same twenty exercises, answered with RatMath Core and the Shelf libraries only. The code below was run when this page was built; its output is shown as printed, and compared with the independent answer.

Agrees 20

Libraries used here: core, discrete. In this code each library is in scope under its own name (linalg.det, stats.tTest), and Core's names (R, Rational, …) are in scope directly.

  1. 1.Prisoner's dilemmaAgrees
    Each prisoner can Cooperate or Defect. Payoffs (row, column): CC (−1,−1)(-1, -1), CD (−3,0)(-3, 0), DC (0,−3)(0, -3), DD (−2,−2)(-2, -2). Find the pure Nash equilibria.
    Independent answer
    Defect strictly dominates Cooperate for both (0>−10 > -1, −2>−3-2 > -3), so the only equilibrium is (D, D), paying (−2,−2)(-2, -2).
    RatMath code
    const g = discrete.bimatrixGame([[-1, -3], [0, -2]], [[-1, 0], [-3, -2]], { rows: ["C", "D"], columns: ["C", "D"] });
    g.equilibria().map(String)
    Output
    ["(D; D) paying -2 and -2"]
  2. 2.Matching penniesAgrees
    Solve the zero-sum game (1−1−11)\begin{pmatrix}1&-1\\-1&1\end{pmatrix}.
    Independent answer
    No saddle point; each player mixes 12,12\tfrac12, \tfrac12 and the value is 0.
    RatMath code
    String(discrete.matrixGame([[1, -1], [-1, 1]]))
    Output
    value 0; row plays r1 1/2, r2 1/2; column plays c1 1/2, c2 1/2
  3. 3.A 2×2 zero-sum gameAgrees
    Solve the zero-sum game (3−1−24)\begin{pmatrix}3&-1\\-2&4\end{pmatrix}.
    Independent answer
    No saddle point (row minima −1,−2-1, -2; column maxima 3, 4). Row plays pp on row 1: 3p−2(1−p)=−p+4(1−p)3p - 2(1-p) = -p + 4(1-p) gives p=35p = \tfrac35. Column: 3q−(1−q)=−2q+4(1−q)3q - (1-q) = -2q + 4(1-q) gives q=12q = \tfrac12. Value =3⋅4−(−1)(−2)3+4+1+2=1= \tfrac{3\cdot4 - (-1)(-2)}{3 + 4 + 1 + 2} = 1.
    RatMath code
    String(discrete.matrixGame([[3, -1], [-2, 4]]))
    Output
    value 1; row plays r1 3/5, r2 2/5; column plays c1 1/2, c2 1/2
  4. 4.Saddle pointsAgrees
    Find the saddle points of (42310−1512)\begin{pmatrix}4&2&3\\1&0&-1\\5&1&2\end{pmatrix}.
    Independent answer
    Row minima 2, −1-1, 1: maximin 2. Column maxima 5, 2, 3: minimax 2. Saddle at row 1, column 2, value 2.
    RatMath code
    discrete.saddlePoints([[4, 2, 3], [1, 0, -1], [5, 1, 2]])
    Output
    [{ row: 0, column: 1, value: 2 }]
  5. 5.Rock, paper, scissorsAgrees
    Solve rock–paper–scissors as a zero-sum game (win 1, lose −1-1, tie 0).
    Independent answer
    By symmetry the value is 0 and each player mixes 13,13,13\tfrac13, \tfrac13, \tfrac13.
    RatMath code
    String(discrete.matrixGame([[0, -1, 1], [1, 0, -1], [-1, 1, 0]]))
    Output
    value 0; row plays r1 1/3, r2 1/3, r3 1/3; column plays c1 1/3, c2 1/3, c3 1/3
  6. 6.Battle of the sexesAgrees
    Row payoffs (2001)\begin{pmatrix}2&0\\0&1\end{pmatrix}, column payoffs (1002)\begin{pmatrix}1&0\\0&2\end{pmatrix}. Find all Nash equilibria.
    Independent answer
    Pure: (r1, c1) paying (2, 1) and (r2, c2) paying (1, 2). Mixed: column makes row indifferent with 2q=1−q2q = 1 - q, q=13q = \tfrac13; row makes column indifferent with p=2(1−p)p = 2(1 - p), p=23p = \tfrac23. Both expect 23\tfrac23.
    RatMath code
    discrete.bimatrixGame([[2, 0], [0, 1]], [[1, 0], [0, 2]]).equilibria().map(String)
    Output
    ["(r1; c1) paying 2 and 1", "(r2; c2) paying 1 and 2", "(2/3 r1 + 1/3 r2; 1/3 c1 + 2/3 c2) paying 2/3 and 2/3"]
  7. 7.Backward inductionAgrees
    An entrant E chooses Out (payoffs E 0, incumbent I 2) or In. After In, I chooses Fight (−1,−1-1, -1) or Accommodate (1, 1). Find the subgame perfect equilibrium.
    Independent answer
    After In, I prefers Accommodate (1>−11 > -1); knowing that, E prefers In (1>01 > 0). Play: In, Accommodate, payoffs (1, 1). The threat to fight is not credible.
    RatMath code
    const tree = { player: "E", moves: {
      out: { payoff: { E: 0, I: 2 } },
      in: { player: "I", moves: { fight: { payoff: { E: -1, I: -1 } }, accommodate: { payoff: { E: 1, I: 1 } } } },
    } };
    const b = discrete.backwardInduction(tree);
    [b.path, ((o) => Object.fromEntries(Object.entries(o).map(([k, v]) => [k, String(v)])))(b.value)]
    Output
    [["in", "accommodate"], { E: "1", I: "1" }]
  8. 8.NimAgrees
    In Nim with heaps 3, 4, 5, is the first player winning? Give a winning move.
    Independent answer
    3⊕4⊕5=011⊕100⊕101=010=2≠03 \oplus 4 \oplus 5 = 011 \oplus 100 \oplus 101 = 010 = 2 \ne 0: winning. Reduce the heap of 3 to 3⊕2=13 \oplus 2 = 1.
    RatMath code
    const n = discrete.nim([3, 4, 5]);
    [n.nimSum, n.losing, n.winningMoves.map((m) => [m.from, m.to])]
    Output
    [2n, false, [[3n, 1n]]]
  9. 9.Sprague–Grundy valuesAgrees
    In the subtraction game where a move removes 1, 2 or 3 counters, find the Grundy values of heaps 0 to 11.
    Independent answer
    g(n)=mex⁡{g(n−1),g(n−2),g(n−3)}=n mod 4g(n) = \operatorname{mex}\{g(n-1), g(n-2), g(n-3)\} = n \bmod 4: 0, 1, 2, 3 repeating. The P-positions are multiples of 4.
    RatMath code
    const s = discrete.subtractionGame([1, 2, 3], 12);
    [s.values, s.period.length]
    Output
    [[0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3], 4]
  10. 10.Partizan gamesAgrees
    Find the values of the games {0∣ }\{0 \mid\ \}, { ∣0}\{\ \mid 0\} and {0∣0}\{0 \mid 0\}.
    Independent answer
    {0∣}=1\{0\mid\} = 1 (a free move for Left), {∣0}=−1\{\mid0\} = -1, and {0∣0}=∗\{0\mid0\} = {*} (star: whoever moves first wins).
    RatMath code
    const c = discrete.cgame;
    [c([0], []), c([], [0]), c([0], [0])].map(String)
    Output
    ["1", "-1", "*"]
  11. 11.Shapley valueAgrees
    In the glove game, player L owns a left glove and R1, R2 each own a right glove; a coalition is worth 1 if it can make a pair. Find the Shapley value.
    Independent answer
    L is pivotal unless it comes first (in 4 of 6 orders): 23\tfrac23. R1 is pivotal only in the order L, R1, R2: 16\tfrac16; likewise R2.
    RatMath code
    const g = discrete.cooperativeGame(["L", "R1", "R2"], (S) => (S.includes("L") && (S.includes("R1") || S.includes("R2")) ? 1 : 0));
    ((o) => Object.fromEntries(Object.entries(o).map(([k, v]) => [k, String(v)])))(discrete.shapley(g))
    Output
    { L: "2/3", R1: "1/6", R2: "1/6" }
  12. 12.The coreAgrees
    Find the core of the glove game.
    Independent answer
    Core constraints xL+xR1≥1x_L + x_{R1} \ge 1, xL+xR2≥1x_L + x_{R2} \ge 1, total 1, all ≥0\ge 0, force xR1=xR2=0x_{R1} = x_{R2} = 0: the core is the single point (1,0,0)(1, 0, 0). Competition between the right gloves gives L everything.
    RatMath code
    const g = discrete.cooperativeGame(["L", "R1", "R2"], (S) => (S.includes("L") && (S.includes("R1") || S.includes("R2")) ? 1 : 0));
    const c = discrete.coreVertices(g);
    [c.kind, c.vertices.map((o) => Object.fromEntries(Object.entries(o).map(([k, v]) => [k, String(v)])))]
    Output
    ["point", [{ L: "1", R1: "0", R2: "0" }]]
    coreVertices lists every vertex of the core: one, so the core is the single point.
    Fix: ratmath/discrete#7, transportation, binary option on integerProgram, coreVertices
  13. 13.Voting powerAgrees
    Three voters have weights 50, 49, 1 and the quota is 51. Find the Shapley–Shubik and Banzhaf power indices.
    Independent answer
    Winning coalitions: {1,2},{1,3},{1,2,3}\{1,2\}, \{1,3\}, \{1,2,3\}. Shapley–Shubik: voter 1 is pivotal in 4 of 6 orders: (23,16,16)(\tfrac23, \tfrac16, \tfrac16). Banzhaf swings: voter 1 in 3, voters 2 and 3 in 1 each: (35,15,15)(\tfrac35, \tfrac15, \tfrac15). Weight 49 has no more power than weight 1.
    RatMath code
    const w = discrete.weightedVoting({ quota: 51, weights: [50, 49, 1] });
    [Object.values(w.shapleyShubik), Object.values(w.banzhaf)]
    Output
    [[2/3, 1/6, 1/6], [3/5, 1/5, 1/5]]
  14. 14.Voting methodsAgrees
    Nine voters: 4 rank A > B > C, 3 rank B > C > A, 2 rank C > B > A. Find the plurality, Borda and Condorcet winners.
    Independent answer
    Plurality: A (4 first places). Borda (2, 1, 0 points): A 8, B 12, C 7, so B. Pairwise: B beats A 5–4 and C 7–2, so B is the Condorcet winner.
    RatMath code
    const b = [{ count: 4, ranking: ["A", "B", "C"] }, { count: 3, ranking: ["B", "C", "A"] }, { count: 2, ranking: ["C", "B", "A"] }];
    [discrete.plurality(b).winners, discrete.borda(b).winners, discrete.condorcet(b).winner]
    Output
    [["A"], ["B"], "B"]
  15. 15.Stable matchingAgrees
    Proposers A: x > y and B: y > x; receivers x: B > A and y: A > B. Run Gale–Shapley with A and B proposing.
    Independent answer
    A proposes to x, B to y; both are accepted and nobody is rejected. Matching A–x, B–y: stable (and best for the proposers), with no blocking pair.
    RatMath code
    const m = discrete.stableMatching({ A: ["x", "y"], B: ["y", "x"] }, { x: ["B", "A"], y: ["A", "B"] });
    [m.matching, m.blockingPairs]
    Output
    [{ A: "x", B: "y" }, []]
  16. 16.ApportionmentAgrees
    Apportion 10 seats among states of population 120, 230 and 650 by Hamilton's method.
    Independent answer
    Quotas 1.2, 2.3, 6.5: floors 1, 2, 6 (9 seats); the largest remainder (0.5) gets the last seat. Seats 1,2,71, 2, 7.
    RatMath code
    Object.values(discrete.apportion([120, 230, 650], 10).seats)
    Output
    [1n, 2n, 7n]
  17. 17.Assignment problemAgrees
    Assign three workers to three jobs at minimum total cost with cost matrix (413205322)\begin{pmatrix}4&1&3\\2&0&5\\3&2&2\end{pmatrix}.
    Independent answer
    Of the 6 assignments, worker 1→job 2, 2→1, 3→3 costs 1+2+2=51 + 2 + 2 = 5, the least (the next best cost 6).
    RatMath code
    const r = discrete.assignment([[4, 1, 3], [2, 0, 5], [3, 2, 2]]);
    [r.assignment, r.cost]
    Output
    [[1, 0, 2], 5]
  18. 18.Iterated dominanceAgrees
    Row payoffs (310221102)\begin{pmatrix}3&1&0\\2&2&1\\1&0&2\end{pmatrix} in a zero-sum game (row maximises). Does any strategy dominate another? Find the value.
    Independent answer
    For the minimising column player, column 1 (3,2,1)(3, 2, 1) is at least column 2 (1,2,0)(1, 2, 0) entry by entry, so column 1 is dominated and dropped. In (102102)\begin{pmatrix}1&0\\2&1\\0&2\end{pmatrix} row 1 is dominated by row 2. That leaves (2102)\begin{pmatrix}2&1\\0&2\end{pmatrix} (rows 2, 3; columns 2, 3), with no saddle point. Row: 2p=p+2(1−p)2p = p + 2(1 - p), p=23p = \tfrac23 on row 2. Column: 2q+(1−q)=2(1−q)2q + (1 - q) = 2(1 - q), q=13q = \tfrac13 on column 2. Value 2⋅2−1⋅02+2−1−0=43\tfrac{2\cdot2 - 1\cdot0}{2 + 2 - 1 - 0} = \tfrac43.
    RatMath code
    String(discrete.matrixGame([[3, 1, 0], [2, 2, 1], [1, 0, 2]]))
    Output
    value 4/3; row plays r2 2/3, r3 1/3; column plays c2 1/3, c3 2/3
  19. 19.Mixed strategies by indifferenceAgrees
    In (5124)\begin{pmatrix}5&1\\2&4\end{pmatrix} (zero-sum, row maximises), find the optimal strategies and value.
    Independent answer
    No saddle point. 5p+2(1−p)=p+4(1−p)5p + 2(1-p) = p + 4(1-p): p=13p = \tfrac13. 5q+(1−q)=2q+4(1−q)5q + (1 - q) = 2q + 4(1 - q): q=12q = \tfrac12. Value =5⋅4−1⋅25+4−1−2=3= \tfrac{5\cdot4 - 1\cdot2}{5 + 4 - 1 - 2} = 3.
    RatMath code
    String(discrete.matrixGame([[5, 1], [2, 4]]))
    Output
    value 3; row plays r1 1/3, r2 2/3; column plays c1 1/2, c2 1/2
  20. 20.Pure equilibriaAgrees
    Find the pure Nash equilibria of the coordination game with row payoffs (3002)\begin{pmatrix}3&0\\0&2\end{pmatrix} and the same for the column player.
    Independent answer
    (r1, c1) paying (3, 3) and (r2, c2) paying (2, 2): neither player gains by deviating alone in either. The off-diagonal cells are not equilibria.
    RatMath code
    discrete.bimatrixGame([[3, 0], [0, 2]], [[3, 0], [0, 2]]).pureEquilibria().length
    Output
    2