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.Prisoner's dilemmaAgreesEach prisoner can Cooperate or Defect. Payoffs (row, column): CC , CD , DC , DD . Find the pure Nash equilibria.Independent answerDefect strictly dominates Cooperate for both (, ), so the only equilibrium is (D, D), paying .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.Matching penniesAgreesSolve the zero-sum game .Independent answerNo saddle point; each player mixes and the value is 0.RatMath code
String(discrete.matrixGame([[1, -1], [-1, 1]]))Outputvalue 0; row plays r1 1/2, r2 1/2; column plays c1 1/2, c2 1/2
- 3.A 2×2 zero-sum gameAgreesSolve the zero-sum game .Independent answerNo saddle point (row minima ; column maxima 3, 4). Row plays on row 1: gives . Column: gives . Value .RatMath code
String(discrete.matrixGame([[3, -1], [-2, 4]]))Outputvalue 1; row plays r1 3/5, r2 2/5; column plays c1 1/2, c2 1/2
- 4.Saddle pointsAgreesFind the saddle points of .Independent answerRow minima 2, , 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.Rock, paper, scissorsAgreesSolve rock–paper–scissors as a zero-sum game (win 1, lose , tie 0).Independent answerBy symmetry the value is 0 and each player mixes .RatMath code
String(discrete.matrixGame([[0, -1, 1], [1, 0, -1], [-1, 1, 0]]))Outputvalue 0; row plays r1 1/3, r2 1/3, r3 1/3; column plays c1 1/3, c2 1/3, c3 1/3
- 6.Battle of the sexesAgreesRow payoffs , column payoffs . Find all Nash equilibria.Independent answerPure: (r1, c1) paying (2, 1) and (r2, c2) paying (1, 2). Mixed: column makes row indifferent with , ; row makes column indifferent with , . Both expect .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.Backward inductionAgreesAn entrant E chooses Out (payoffs E 0, incumbent I 2) or In. After In, I chooses Fight () or Accommodate (1, 1). Find the subgame perfect equilibrium.Independent answerAfter In, I prefers Accommodate (); knowing that, E prefers In (). 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.NimAgreesIn Nim with heaps 3, 4, 5, is the first player winning? Give a winning move.Independent answer: winning. Reduce the heap of 3 to .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.Sprague–Grundy valuesAgreesIn the subtraction game where a move removes 1, 2 or 3 counters, find the Grundy values of heaps 0 to 11.Independent answer: 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.Partizan gamesAgreesFind the values of the games , and .Independent answer(a free move for Left), , and (star: whoever moves first wins).RatMath code
const c = discrete.cgame; [c([0], []), c([], [0]), c([0], [0])].map(String)Output["1", "-1", "*"]
- 11.Shapley valueAgreesIn 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 answerL is pivotal unless it comes first (in 4 of 6 orders): . R1 is pivotal only in the order L, R1, R2: ; 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.The coreAgreesFind the core of the glove game.Independent answerCore constraints , , total 1, all , force : the core is the single point . 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" }]]coreVerticeslists every vertex of the core: one, so the core is the single point. - 13.Voting powerAgreesThree voters have weights 50, 49, 1 and the quota is 51. Find the Shapley–Shubik and Banzhaf power indices.Independent answerWinning coalitions: . Shapley–Shubik: voter 1 is pivotal in 4 of 6 orders: . Banzhaf swings: voter 1 in 3, voters 2 and 3 in 1 each: . 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.Voting methodsAgreesNine voters: 4 rank A > B > C, 3 rank B > C > A, 2 rank C > B > A. Find the plurality, Borda and Condorcet winners.Independent answerPlurality: 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.Stable matchingAgreesProposers A: x > y and B: y > x; receivers x: B > A and y: A > B. Run Gale–Shapley with A and B proposing.Independent answerA 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.ApportionmentAgreesApportion 10 seats among states of population 120, 230 and 650 by Hamilton's method.Independent answerQuotas 1.2, 2.3, 6.5: floors 1, 2, 6 (9 seats); the largest remainder (0.5) gets the last seat. Seats .RatMath code
Object.values(discrete.apportion([120, 230, 650], 10).seats)Output[1n, 2n, 7n]
- 17.Assignment problemAgreesAssign three workers to three jobs at minimum total cost with cost matrix .Independent answerOf the 6 assignments, worker 1→job 2, 2→1, 3→3 costs , 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.Iterated dominanceAgreesRow payoffs in a zero-sum game (row maximises). Does any strategy dominate another? Find the value.Independent answerFor the minimising column player, column 1 is at least column 2 entry by entry, so column 1 is dominated and dropped. In row 1 is dominated by row 2. That leaves (rows 2, 3; columns 2, 3), with no saddle point. Row: , on row 2. Column: , on column 2. Value .RatMath code
String(discrete.matrixGame([[3, 1, 0], [2, 2, 1], [1, 0, 2]]))Outputvalue 4/3; row plays r2 2/3, r3 1/3; column plays c2 1/3, c3 2/3
- 19.Mixed strategies by indifferenceAgreesIn (zero-sum, row maximises), find the optimal strategies and value.Independent answerNo saddle point. : . : . Value .RatMath code
String(discrete.matrixGame([[5, 1], [2, 4]]))Outputvalue 3; row plays r1 1/3, r2 2/3; column plays c1 1/2, c2 1/2
- 20.Pure equilibriaAgreesFind the pure Nash equilibria of the coordination game with row payoffs 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().lengthOutput2