33 of 40 focal problems use RatMath for a calculation or a substantive step.
Direct calculation
31 · 77.5%
Assisted
2 · 5%
Worked by hand
7 · 17.5%
Using the packages
Exact payoff arithmetic and equilibrium routines are helpful once utilities and allowed moves are explicit. Credible threats, information sets and strategic assumptions require interpretation.
Calculator interface
Provide a payoff editor with row and column players named. Highlight unilateral deviations, trace information sets and display support conditions together with mixed-strategy probabilities.
Each of the 40 focal problems has equal weight. Direct means the displayed package calculation answers the computational question after the inputs are set up. Assisted means it contributes a step and the worked solution supplies essential reasoning, interpretation or selection. Worked by hand means the guide relies on a construction, argument or judgment for that task. The helpful share combines direct and assisted days. Courses and instructors assign different mixes of problems. The percentages describe this syllabus.
Classroom inputs and practical limits
33 of 40 days include a checked executable example. On 11 days the measured size sweep exercises a named API used in the lesson. Each day identifies its tested inputs and the mathematical property checked. Hand-worked days give the input scale and the argument to verify.
Ranges across the five units
Days 1–8 · Normal form and best response. Two-player normal forms usually have 2–4 strategies each and integer or modest rational payoffs.
Unit benchmark · discrete.matrixGame, strategies per player. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 9–16 · Zero-sum play. Payoff matrices commonly 2×2 to 5×5; support enumeration and linear-program formulations have different costs.
Unit benchmark · discrete.matrixGame, strategies per player. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 17–24 · Sequential and combinatorial games. Short game trees of depth about 2–6 or a few small heaps; both branching and depth control tree size.
Unit benchmark · logic.binaryIncrement.run, input bits. Largest passing sample 2,048 (21.81 ms, 75.1 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 25–32 · Cooperation and collective choice. Coalitions or voters often number 3–10 for explicit enumeration; there are 2ⁿ coalitions before computing their values.
Unit benchmark · discrete.binomial, objects. Largest passing sample 10,000 (8.36 ms, 88 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 33–40 · Matching and assignments. Two to ten people, jobs or alternatives per side; stable matchings and minimum-cost assignments answer different questions.
Unit benchmark · discrete.assignment, rows and columns. Largest passing sample 16 (565 ms, 127.2 MiB peak process RSS). Time cutoff at 32, 64, 128. The first sampled passing call above 100 ms used 16 (565 ms).
Accuracy notes (1)
Open · Two distinct categorical tuples can merge. A uniform table on the two arrays [‘a,sb’,‘c’] and [‘a’,‘b,sc’] should give each probability 1/2. The table reports one outcome with probability 1 because the composite string keys collide. Use unambiguous scalar IDs for such labels. Ordinary numeric dice faces have distinct keys.
Each prisoner can Cooperate or Defect. Payoffs (row, column): CC , CD , DC , DD . Find the pure Nash equilibria.
Worked solution
Defect strictly dominates Cooperate for both (, ), so the only equilibrium is (D, D), paying .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const g = discrete.bimatrixGame([[-1, -3], [0, -2]], [[-1, 0], [-3, -2]], { rows: ["C", "D"], columns: ["C", "D"] });
console.log(g.equilibria().map(String));
Checked output
["(D; D) paying -2 and -2"]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two-player normal forms usually have 2–4 strategies each and integer or modest rational payoffs.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 1.80 ms on Node.
Related workload in this unit.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.bimatrixGame · 5 passing test cases, 10 distinct argument descriptions
No saddle point; each player mixes and the value is 0.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(String(discrete.matrixGame([[1, -1], [-1, 1]])));
Checked output
value 0; row plays r1 1/2, r2 1/2; column plays c1 1/2, c2 1/2
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two-player normal forms usually have 2–4 strategies each and integer or modest rational payoffs.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 1.44 ms on Node.
Same API, measured input family.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.matrixGame · 3 passing test cases, 9 distinct argument descriptions
Row payoffs , column payoffs . Find all Nash equilibria.
Worked solution
Pure: (r1, c1) paying (2, 1) and (r2, c2) paying (1, 2). Mixed: column makes row indifferent with , ; row makes column indifferent with , . Both expect .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(discrete.bimatrixGame([[2, 0], [0, 1]], [[1, 0], [0, 2]]).equilibria().map(String));
Checked 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"]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two-player normal forms usually have 2–4 strategies each and integer or modest rational payoffs.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 0.412 ms on Node.
Related workload in this unit.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.bimatrixGame · 5 passing test cases, 10 distinct argument descriptions
Row payoffs in a zero-sum game (row maximises). Does any strategy dominate another? Find the value.
Worked solution
For 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 .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(String(discrete.matrixGame([[3, 1, 0], [2, 2, 1], [1, 0, 2]])));
Checked output
value 4/3; row plays r2 2/3, r3 1/3; column plays c2 1/3, c3 2/3
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two-player normal forms usually have 2–4 strategies each and integer or modest rational payoffs.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 0.463 ms on Node.
Same API, measured input family.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.matrixGame · 3 passing test cases, 9 distinct argument descriptions
In (zero-sum, row maximises), find the optimal strategies and value.
Worked solution
No saddle point. : . : . Value .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(String(discrete.matrixGame([[5, 1], [2, 4]])));
Checked output
value 3; row plays r1 1/3, r2 2/3; column plays c1 1/2, c2 1/2
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two-player normal forms usually have 2–4 strategies each and integer or modest rational payoffs.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 0.329 ms on Node.
Same API, measured input family.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.matrixGame · 3 passing test cases, 9 distinct argument descriptions
Find the pure Nash equilibria of the coordination game with row payoffs and the same for the column player.
Worked solution
(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.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(discrete.bimatrixGame([[3, 0], [0, 2]], [[3, 0], [0, 2]]).pureEquilibria().length);
Checked output
2
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two-player normal forms usually have 2–4 strategies each and integer or modest rational payoffs.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 0.225 ms on Node.
Same API, measured input family.discrete.bimatrixGame.pureEquilibria · strategies per player. Baseline test points across courses 2, 3, 4, 5. For identical identity payoff matrices, exactly the n matching pure profiles are Nash equilibria.
Practical limit. Largest passing sample 100 (777 ms, 126.8 MiB peak process RSS). The first sampled passing call above 100 ms used 50 (110 ms). The runs did not locate a ceiling for this family. Pure equilibria can be checked cell by cell. Mixed equilibria require solving on supports and can be much more expensive at the same matrix size.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
1.17
75.7
3
Baseline
Passed
1.74
75.1
4
Baseline
Passed
4.56
75.5
5
Baseline
Passed
6.46
75.8
10
Stretch
Passed
4.27
77.6
25
Stretch
Passed
39.65
90.2
50
Stretch
Passed
110
92.4
100
Stretch
Passed
777
126.8
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.bimatrixGame · 5 passing test cases, 10 distinct argument descriptions
Is moving from payoffs (1,1) to (3,1) a Pareto improvement?
Worked solution
One player gains and the other is unchanged. No player loses.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Two-player normal forms usually have 2–4 strategies each and integer or modest rational payoffs.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 08 / 40 · Normal form and best response
Nash versus welfare
Worked by hand
Problem
Does an outcome maximizing the sum of payoffs have to be a Nash equilibrium?
Worked solution
No. Mutual cooperation in a prisoner's dilemma can maximize total payoff while each player has a profitable deviation.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Two-player normal forms usually have 2–4 strategies each and integer or modest rational payoffs.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 09 / 40 · Zero-sum play
A 2×2 zero-sum game
Direct calculation@ratmath/discrete
Problem
Solve the zero-sum game .
Worked solution
No saddle point (row minima ; column maxima 3, 4). Row plays on row 1: gives . Column: gives . Value .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(String(discrete.matrixGame([[3, -1], [-2, 4]])));
Checked output
value 1; row plays r1 3/5, r2 2/5; column plays c1 1/2, c2 1/2
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Payoff matrices commonly 2×2 to 5×5; support enumeration and linear-program formulations have different costs.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 0.313 ms on Node.
Same API, measured input family.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.matrixGame · 3 passing test cases, 9 distinct argument descriptions
Row minima 2, , 1: maximin 2. Column maxima 5, 2, 3: minimax 2. Saddle at row 1, column 2, value 2.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(discrete.saddlePoints([[4, 2, 3], [1, 0, -1], [5, 1, 2]]));
Checked output
[{ row: 0, column: 1, value: 2 }]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Payoff matrices commonly 2×2 to 5×5; support enumeration and linear-program formulations have different costs.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 0.157 ms on Node.
Related workload in this unit.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.saddlePoints · 1 passing test case, 1 distinct argument description
Solve rock–paper–scissors as a zero-sum game (win 1, lose , tie 0).
Worked solution
By symmetry the value is 0 and each player mixes .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(String(discrete.matrixGame([[0, -1, 1], [1, 0, -1], [-1, 1, 0]])));
Checked 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
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Payoff matrices commonly 2×2 to 5×5; support enumeration and linear-program formulations have different costs.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 0.258 ms on Node.
Same API, measured input family.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.matrixGame · 3 passing test cases, 9 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Payoff matrices commonly 2×2 to 5×5; support enumeration and linear-program formulations have different costs.
For this problem type. Use 2–5 variables for a worked linear program or about 2–10 binary choices, a handful of constraints and small exact coefficients.
Focal example. The code above passed its displayed check in 0.263 ms on Node.
Same API, measured input family.discrete.linearProgram · variables. Baseline test points across courses 1, 2, 3, 5. Maximize Σxᵢ under xᵢ≤i+1 and x≥0. The positive objective saturates every coordinate.
Practical limit. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family. A bounded box gives an easy linear program. Constraint count, degeneracy and intermediate rational bit lengths affect pivot cost.
Measured times, memory and outcomes
variables · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.30
75.3
2
Baseline
Passed
1.28
75.1
3
Baseline
Passed
3.76
74
5
Baseline
Passed
1.98
75.1
10
Stretch
Passed
2.83
75.6
25
Stretch
Passed
3.71
75.6
50
Stretch
Passed
9.66
78.2
100
Stretch
Passed
57.90
84.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.linearProgram · 7 passing test cases, 14 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Payoff matrices commonly 2×2 to 5×5; support enumeration and linear-program formulations have different costs.
For this problem type. Use 2–5 variables for a worked linear program or about 2–10 binary choices, a handful of constraints and small exact coefficients.
Focal example. The code above passed its displayed check in 1.07 ms on Node.
Same API, measured input family.discrete.linearProgram · variables. Baseline test points across courses 1, 2, 3, 5. Maximize Σxᵢ under xᵢ≤i+1 and x≥0. The positive objective saturates every coordinate.
Practical limit. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family. A bounded box gives an easy linear program. Constraint count, degeneracy and intermediate rational bit lengths affect pivot cost.
Measured times, memory and outcomes
variables · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.30
75.3
2
Baseline
Passed
1.28
75.1
3
Baseline
Passed
3.76
74
5
Baseline
Passed
1.98
75.1
10
Stretch
Passed
2.83
75.6
25
Stretch
Passed
3.71
75.6
50
Stretch
Passed
9.66
78.2
100
Stretch
Passed
57.90
84.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.linearProgram · 7 passing test cases, 14 distinct argument descriptions
Write the dual of: maximise subject to , , ; show both optimal values agree.
Worked solution
Dual: minimise with , , . Primal optimum at is ; dual optimum at is .
Using RatMath
Transpose the constraint matrix, exchange objective and right-hand sides, and set the dual inequality directions. The two solver calls check the proposed dual on this instance.
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Payoff matrices commonly 2×2 to 5×5; support enumeration and linear-program formulations have different costs.
For this problem type. Use 2–5 variables for a worked linear program or about 2–10 binary choices, a handful of constraints and small exact coefficients.
Focal example. The code above passed its displayed check in 0.282 ms on Node.
Same API, measured input family.discrete.linearProgram · variables. Baseline test points across courses 1, 2, 3, 5. Maximize Σxᵢ under xᵢ≤i+1 and x≥0. The positive objective saturates every coordinate.
Practical limit. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family. A bounded box gives an easy linear program. Constraint count, degeneracy and intermediate rational bit lengths affect pivot cost.
Measured times, memory and outcomes
variables · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.30
75.3
2
Baseline
Passed
1.28
75.1
3
Baseline
Passed
3.76
74
5
Baseline
Passed
1.98
75.1
10
Stretch
Passed
2.83
75.6
25
Stretch
Passed
3.71
75.6
50
Stretch
Passed
9.66
78.2
100
Stretch
Passed
57.90
84.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.linearProgram · 7 passing test cases, 14 distinct argument descriptions
A row action pays 4 against left and −2 against right. Left occurs with probability 1/3. What is the expected payoff?
Worked solution
Weight by the opponent's probabilities.
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { R } from "@ratmath/core";
console.log(String(R`4/3-2*2/3`));
Checked output
0
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Payoff matrices commonly 2×2 to 5×5; support enumeration and linear-program formulations have different costs.
Focal example. The code above passed its displayed check in 0.113 ms on Node.
Same arithmetic expression. Replaced its first numeral 4 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.add · denominator. Baseline test points across courses 1, 2, 3, 12, 100, 1,000. Cross-multiply 1/n + 1/(n+1) against (2n+1)/(n(n+1)).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000,007 (0.038 ms, 76.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact work depends on the bit lengths of both numerator and denominator. A long sum of relatively prime fractions can build a large common denominator.
Measured times, memory and outcomes
denominator · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.034
74.9
2
Baseline
Passed
0.036
75.6
3
Baseline
Passed
0.040
75.9
12
Baseline
Passed
0.039
75.2
100
Baseline
Passed
0.041
75
1,000
Baseline
Passed
0.035
75.8
1,000,003
Stretch
Passed
0.044
75
1,000,000,007
Stretch
Passed
0.038
76.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
Add 5 to every row-player payoff in a zero-sum payoff matrix. What happens to optimal policies and the value?
Worked solution
Every expected payoff rises by the same constant. Optimal policies are unchanged and the row value rises by five, with the column payoffs adjusted to preserve zero sum.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Payoff matrices commonly 2×2 to 5×5; support enumeration and linear-program formulations have different costs.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 17 / 40 · Sequential and combinatorial games
Backward induction
Direct calculation@ratmath/discrete
Problem
An 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.
Worked solution
After In, I prefers Accommodate (); knowing that, E prefers In (). Play: In, Accommodate, payoffs (1, 1). The threat to fight is not credible.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Short game trees of depth about 2–6 or a few small heaps; both branching and depth control tree size.
Focal example. The code above passed its displayed check in 0.401 ms on Node.
Related workload in this unit.logic.binaryIncrement.run · input bits. Baseline test points across courses 1, 2, 4, 8. Incrementing a string of n ones gives 1 followed by n zeroes.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 2,048 (21.81 ms, 75.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Simulation cost depends on executed transitions and tape use. Reaching a step budget establishes an incomplete trace only.
Measured times, memory and outcomes
input bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.248
75.8
2
Baseline
Passed
0.141
74.4
4
Baseline
Passed
0.141
76
8
Baseline
Passed
0.149
74.7
32
Stretch
Passed
0.201
74.9
128
Stretch
Passed
0.349
75.1
512
Stretch
Passed
1.56
75.1
2,048
Stretch
Passed
21.81
75.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.backwardInduction · 1 passing test case, 1 distinct argument description
In Nim with heaps 3, 4, 5, is the first player winning? Give a winning move.
Worked solution
: winning. Reduce the heap of 3 to .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const n = discrete.nim([3, 4, 5]);
console.log([n.nimSum, n.losing, n.winningMoves.map((m) => [m.from, m.to])]);
Checked output
[2n, false, [[3n, 1n]]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Short game trees of depth about 2–6 or a few small heaps; both branching and depth control tree size.
Focal example. The code above passed its displayed check in 0.141 ms on Node.
Related workload in this unit.logic.binaryIncrement.run · input bits. Baseline test points across courses 1, 2, 4, 8. Incrementing a string of n ones gives 1 followed by n zeroes.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 2,048 (21.81 ms, 75.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Simulation cost depends on executed transitions and tape use. Reaching a step budget establishes an incomplete trace only.
Measured times, memory and outcomes
input bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.248
75.8
2
Baseline
Passed
0.141
74.4
4
Baseline
Passed
0.141
76
8
Baseline
Passed
0.149
74.7
32
Stretch
Passed
0.201
74.9
128
Stretch
Passed
0.349
75.1
512
Stretch
Passed
1.56
75.1
2,048
Stretch
Passed
21.81
75.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.nim · 1 passing test case, 3 distinct argument descriptions
In the subtraction game where a move removes 1, 2 or 3 counters, find the Grundy values of heaps 0 to 11.
Worked solution
: 0, 1, 2, 3 repeating. The P-positions are multiples of 4.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const s = discrete.subtractionGame([1, 2, 3], 12);
console.log([s.values, s.period.length]);
Checked output
[[0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3], 4]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Short game trees of depth about 2–6 or a few small heaps; both branching and depth control tree size.
Focal example. The code above passed its displayed check in 0.341 ms on Node.
Related workload in this unit.logic.binaryIncrement.run · input bits. Baseline test points across courses 1, 2, 4, 8. Incrementing a string of n ones gives 1 followed by n zeroes.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 2,048 (21.81 ms, 75.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Simulation cost depends on executed transitions and tape use. Reaching a step budget establishes an incomplete trace only.
Measured times, memory and outcomes
input bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.248
75.8
2
Baseline
Passed
0.141
74.4
4
Baseline
Passed
0.141
76
8
Baseline
Passed
0.149
74.7
32
Stretch
Passed
0.201
74.9
128
Stretch
Passed
0.349
75.1
512
Stretch
Passed
1.56
75.1
2,048
Stretch
Passed
21.81
75.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.subtractionGame · 1 passing test case, 2 distinct argument descriptions
(a free move for Left), , and (star: whoever moves first wins).
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const c = discrete.cgame;
console.log([c([0], []), c([], [0]), c([0], [0])].map(String));
Checked output
["1", "-1", "*"]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Short game trees of depth about 2–6 or a few small heaps; both branching and depth control tree size.
Focal example. The code above passed its displayed check in 0.498 ms on Node.
Related workload in this unit.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.cgame · 1 passing test case, 6 distinct argument descriptions
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(
discrete.recurrence({ coefficients: [5, -6], initial: [1, 4] }).closedForm().toString()
);
Checked output
a(n) = −2^n + 2·3^n
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Short game trees of depth about 2–6 or a few small heaps; both branching and depth control tree size.
Focal example. The code above passed its displayed check in 2.10 ms on Node.
Related workload in this unit.logic.binaryIncrement.run · input bits. Baseline test points across courses 1, 2, 4, 8. Incrementing a string of n ones gives 1 followed by n zeroes.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 2,048 (21.81 ms, 75.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Simulation cost depends on executed transitions and tape use. Reaching a step budget establishes an incomplete trace only.
Measured times, memory and outcomes
input bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.248
75.8
2
Baseline
Passed
0.141
74.4
4
Baseline
Passed
0.141
76
8
Baseline
Passed
0.149
74.7
32
Stretch
Passed
0.201
74.9
128
Stretch
Passed
0.349
75.1
512
Stretch
Passed
1.56
75.1
2,048
Stretch
Passed
21.81
75.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.recurrence · 2 passing test cases, 5 distinct argument descriptions
After entry a monopolist earns 3 by accommodating and 1 by fighting. Is a threat to fight credible in the final subgame?
Worked solution
At that decision node accommodating strictly improves its payoff. Backward induction eliminates the threat.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Short game trees of depth about 2–6 or a few small heaps; both branching and depth control tree size.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 23 / 40 · Sequential and combinatorial games
Information sets
Worked by hand
Problem
Why can two nodes in the same information set not have independently chosen actions in a pure strategy?
Worked solution
The player cannot distinguish those nodes when acting. A strategy specifies one action for the information set.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Short game trees of depth about 2–6 or a few small heaps; both branching and depth control tree size.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 24 / 40 · Sequential and combinatorial games
Repeated play
Direct calculation@ratmath/core
Problem
With discount factor 1/2, what is the present value of receiving 2 each period starting now?
Worked solution
Sum the geometric series 2/(1−δ).
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { R } from "@ratmath/core";
console.log(String(R`2/(1-1/2)`));
Checked output
4
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Short game trees of depth about 2–6 or a few small heaps; both branching and depth control tree size.
Focal example. The code above passed its displayed check in 0.619 ms on Node.
Same arithmetic expression. Replaced its first numeral 2 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.add · denominator. Baseline test points across courses 1, 2, 3, 12, 100, 1,000. Cross-multiply 1/n + 1/(n+1) against (2n+1)/(n(n+1)).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000,007 (0.038 ms, 76.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact work depends on the bit lengths of both numerator and denominator. A long sum of relatively prime fractions can build a large common denominator.
Measured times, memory and outcomes
denominator · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.034
74.9
2
Baseline
Passed
0.036
75.6
3
Baseline
Passed
0.040
75.9
12
Baseline
Passed
0.039
75.2
100
Baseline
Passed
0.041
75
1,000
Baseline
Passed
0.035
75.8
1,000,003
Stretch
Passed
0.044
75
1,000,000,007
Stretch
Passed
0.038
76.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
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.
Worked solution
L is pivotal unless it comes first (in 4 of 6 orders): . R1 is pivotal only in the order L, R1, R2: ; likewise R2.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const g = discrete.cooperativeGame(["L", "R1", "R2"], (S) => (S.includes("L") && (S.includes("R1") || S.includes("R2")) ? 1 : 0));
console.log(
((o) => Object.fromEntries(Object.entries(o).map(([k, v]) => [k, String(v)])))(discrete.shapley(g))
);
Checked output
{ L: "2/3", R1: "1/6", R2: "1/6" }
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Coalitions or voters often number 3–10 for explicit enumeration; there are 2ⁿ coalitions before computing their values.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 0.414 ms on Node.
Related workload in this unit.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.cooperativeGame · 5 passing test cases, 5 distinct argument descriptions
Core constraints , , total 1, all , force : the core is the single point . Competition between the right gloves gives L everything.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const g = discrete.cooperativeGame(["L", "R1", "R2"], (S) => (S.includes("L") && (S.includes("R1") || S.includes("R2")) ? 1 : 0));
const c = discrete.coreVertices(g);
console.log(
[c.kind, c.vertices.map((o) => Object.fromEntries(Object.entries(o).map(([k, v]) => [k, String(v)])))]
);
Checked output
["point", [{ L: "1", R1: "0", R2: "0" }]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Coalitions or voters often number 3–10 for explicit enumeration; there are 2ⁿ coalitions before computing their values.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 1.38 ms on Node.
Related workload in this unit.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.cooperativeGame · 5 passing test cases, 5 distinct argument descriptions
Implementation limit. Enumerating tight coalitional constraints is capped at six players. Source at the tested revision
Day 27 / 40 · Cooperation and collective choice
Voting power
Direct calculation@ratmath/discrete
Problem
Three voters have weights 50, 49, 1 and the quota is 51. Find the Shapley–Shubik and Banzhaf power indices.
Worked solution
Winning 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.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const w = discrete.weightedVoting({ quota: 51, weights: [50, 49, 1] });
console.log([Object.values(w.shapleyShubik), Object.values(w.banzhaf)]);
Checked output
[[2/3, 1/6, 1/6], [3/5, 1/5, 1/5]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Coalitions or voters often number 3–10 for explicit enumeration; there are 2ⁿ coalitions before computing their values.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 0.489 ms on Node.
Related workload in this unit.discrete.matrixGame · strategies per player. Baseline test points across courses 2, 3, 4, 5. The identity payoff game has value 1/n by uniform mixing for both players.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 20 (19.80 ms, 79.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The identity game has an obvious symmetric solution. Enumerating supports or equilibria in general games can grow exponentially.
Measured times, memory and outcomes
strategies per player · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
3.60
75.7
3
Baseline
Passed
2.02
75
4
Baseline
Passed
3.65
75.1
5
Baseline
Passed
2.69
75.9
8
Stretch
Passed
3.31
76.3
12
Stretch
Passed
4.79
76.6
20
Stretch
Passed
19.80
79.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.weightedVoting · 1 passing test case, 2 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Coalitions or voters often number 3–10 for explicit enumeration; there are 2ⁿ coalitions before computing their values.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 0.883 ms on Node.
Related workload in this unit.discrete.binomial · objects. Baseline test points across courses 2, 5, 10, 52. Check k!(n−k)!·C(n,k)=n! for k=floor(n/2).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (8.36 ms, 88 MiB peak process RSS). The runs did not locate a ceiling for this family. Coefficient bit length grows with n and k. Counting is far cheaper than actually listing all k-subsets.
Measured times, memory and outcomes
objects · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.144
74.7
5
Baseline
Passed
0.151
73.9
10
Baseline
Passed
0.142
75.1
52
Baseline
Passed
0.141
75.9
100
Stretch
Passed
0.128
75
500
Stretch
Passed
0.171
76
2,000
Stretch
Passed
0.526
78.6
10,000
Stretch
Passed
8.36
88
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.plurality · 1 passing test case, 1 distinct argument description
discrete.condorcet · 1 passing test case, 2 distinct argument descriptions
[{ranking=array[3], count=8}, {ranking=array[3], count=5}, {ranking=array[3], count=4}] (n=3) or [["a", "b", "c"] (n=3), ["b", "c", "a"] (n=3), ["c", "a", "b"] (n=3)] (3×3) · voting methods can disagree on one profile
Day 29 / 40 · Cooperation and collective choice
Apportionment
Direct calculation@ratmath/discrete
Problem
Apportion 10 seats among states of population 120, 230 and 650 by Hamilton's method.
Worked solution
Quotas 1.2, 2.3, 6.5: floors 1, 2, 6 (9 seats); the largest remainder (0.5) gets the last seat. Seats .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(Object.values(discrete.apportion([120, 230, 650], 10).seats));
Checked output
[1n, 2n, 7n]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Coalitions or voters often number 3–10 for explicit enumeration; there are 2ⁿ coalitions before computing their values.
For this problem type. Hand payoff tables often have 2–4 strategies per player. Coalition or voting examples commonly have 3–8 players or candidates.
Focal example. The code above passed its displayed check in 1.25 ms on Node.
Related workload in this unit.discrete.binomial · objects. Baseline test points across courses 2, 5, 10, 52. Check k!(n−k)!·C(n,k)=n! for k=floor(n/2).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (8.36 ms, 88 MiB peak process RSS). The runs did not locate a ceiling for this family. Coefficient bit length grows with n and k. Counting is far cheaper than actually listing all k-subsets.
Measured times, memory and outcomes
objects · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.144
74.7
5
Baseline
Passed
0.151
73.9
10
Baseline
Passed
0.142
75.1
52
Baseline
Passed
0.141
75.9
100
Stretch
Passed
0.128
75
500
Stretch
Passed
0.171
76
2,000
Stretch
Passed
0.526
78.6
10,000
Stretch
Passed
8.36
88
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.apportion · 1 passing test case, 6 distinct argument descriptions
How many ways can the 4 vertices of a square be coloured with 3 colours, up to rotation? Up to rotation and reflection?
Worked solution
Rotations: . With reflections (two diagonal flips fix each, two edge flips each): .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(
[discrete.countColourings(discrete.symmetry.cyclic(4), 3), discrete.countColourings(discrete.symmetry.dihedral(4), 3)]
);
Checked output
[24n, 21n]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Coalitions or voters often number 3–10 for explicit enumeration; there are 2ⁿ coalitions before computing their values.
Focal example. The code above passed its displayed check in 6.73 ms on Node.
Related workload in this unit.discrete.binomial · objects. Baseline test points across courses 2, 5, 10, 52. Check k!(n−k)!·C(n,k)=n! for k=floor(n/2).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (8.36 ms, 88 MiB peak process RSS). The runs did not locate a ceiling for this family. Coefficient bit length grows with n and k. Counting is far cheaper than actually listing all k-subsets.
Measured times, memory and outcomes
objects · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.144
74.7
5
Baseline
Passed
0.151
73.9
10
Baseline
Passed
0.142
75.1
52
Baseline
Passed
0.141
75.9
100
Stretch
Passed
0.128
75
500
Stretch
Passed
0.171
76
2,000
Stretch
Passed
0.526
78.6
10,000
Stretch
Passed
8.36
88
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.countColourings · 1 passing test case, 2 distinct argument descriptions
A coalition can secure 9 but its members are allocated 4 and 3. Can this allocation lie in the core?
Worked solution
They receive only 7 in total and can split the extra 2 to improve both payoffs.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Coalitions or voters often number 3–10 for explicit enumeration; there are 2ⁿ coalitions before computing their values.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 32 / 40 · Cooperation and collective choice
Arrangements with repetition
Direct calculation@ratmath/discrete
Problem
How many arrangements of the letters of MISSISSIPPI are there?
Worked solution
.
Using RatMath
Decide what counts as one outcome and whether order matters. Supply the sizes to the counting function and keep the returned whole number exact.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(discrete.multinomial(1, 4, 4, 2));
Checked output
34650n
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Coalitions or voters often number 3–10 for explicit enumeration; there are 2ⁿ coalitions before computing their values.
For this problem type. Use about 3–20 labeled objects in hand examples. Counts can describe sets far too large to list. Enumeration exercises generally use fewer than ten objects.
Focal example. The code above passed its displayed check in 0.123 ms on Node.
Related workload in this unit.discrete.binomial · objects. Baseline test points across courses 2, 5, 10, 52. Check k!(n−k)!·C(n,k)=n! for k=floor(n/2).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (8.36 ms, 88 MiB peak process RSS). The runs did not locate a ceiling for this family. Coefficient bit length grows with n and k. Counting is far cheaper than actually listing all k-subsets.
Measured times, memory and outcomes
objects · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.144
74.7
5
Baseline
Passed
0.151
73.9
10
Baseline
Passed
0.142
75.1
52
Baseline
Passed
0.141
75.9
100
Stretch
Passed
0.128
75
500
Stretch
Passed
0.171
76
2,000
Stretch
Passed
0.526
78.6
10,000
Stretch
Passed
8.36
88
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.multinomial · 1 passing test case, 2 distinct argument descriptions
Proposers A: x > y and B: y > x; receivers x: B > A and y: A > B. Run Gale–Shapley with A and B proposing.
Worked solution
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.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const m = discrete.stableMatching({ A: ["x", "y"], B: ["y", "x"] }, { x: ["B", "A"], y: ["A", "B"] });
console.log([m.matching, m.blockingPairs]);
Checked output
[{ A: "x", B: "y" }, []]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to ten people, jobs or alternatives per side; stable matchings and minimum-cost assignments answer different questions.
For this problem type. Use about 2–8 agents on each side or 3–12 network vertices. Store costs, capacities and missing or forbidden edges explicitly.
Focal example. The code above passed its displayed check in 0.298 ms on Node.
Related workload in this unit.discrete.maximumMatching · vertices per side. Baseline test points across courses 1, 2, 5, 10. K_(n,n) has a diagonal perfect matching of size n.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 100 (102 ms, 125.5 MiB peak process RSS). The first sampled passing call above 100 ms used 100 (102 ms). The runs did not locate a ceiling for this family. Complete bipartite input has n² edges. Verifying a matching uses its vertices and edges. More general optimization objectives need their own check.
Measured times, memory and outcomes
vertices per side · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.869
75.2
2
Baseline
Passed
0.511
74.2
5
Baseline
Passed
0.783
76.1
10
Baseline
Passed
1.21
75
25
Stretch
Passed
4.06
78.9
50
Stretch
Passed
24.22
91.6
100
Stretch
Passed
102
125.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.stableMatching · 1 passing test case, 1 distinct argument description
Assign three workers to three jobs at minimum total cost with cost matrix .
Worked solution
Of the 6 assignments, worker 1→job 2, 2→1, 3→3 costs , the least (the next best cost 6).
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const r = discrete.assignment([[4, 1, 3], [2, 0, 5], [3, 2, 2]]);
console.log([r.assignment, r.cost]);
Checked output
[[1, 0, 2], 5]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to ten people, jobs or alternatives per side; stable matchings and minimum-cost assignments answer different questions.
For this problem type. Use about 2–8 agents on each side or 3–12 network vertices. Store costs, capacities and missing or forbidden edges explicitly.
Focal example. The code above passed its displayed check in 1.07 ms on Node.
Same API, measured input family.discrete.assignment · rows and columns. Baseline test points across courses 1, 2, 4, 8. Unit diagonal and strictly larger off-diagonal costs force the unique identity assignment, cost n.
Practical limit. Largest passing sample 16 (565 ms, 127.2 MiB peak process RSS). Time cutoff at 32, 64, 128. The first sampled passing call above 100 ms used 16 (565 ms). Materializing the cost table takes n² entries. Exact optimization can take much longer than evaluating the cost of a proposed assignment.
Measured times, memory and outcomes
rows and columns · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
2.62
74.8
2
Baseline
Passed
2.05
75.5
4
Baseline
Passed
10.52
77.3
8
Baseline
Passed
52.50
92.3
16
Stretch
Passed
565
127.2
32
Stretch
Time cutoff
—
271.4
64
Stretch
Time cutoff
—
315.2
128
Stretch
Time cutoff
—
333.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.assignment · 1 passing test case, 2 distinct argument descriptions
What is the size of a maximum matching in ? Is it perfect?
Worked solution
Hall's condition holds (every set of left vertices has 3 neighbours), so there is a perfect matching of size 3.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const m = discrete.maximumMatching(discrete.completeBipartite(3, 3));
console.log([m.size, m.perfect]);
Checked output
[3, true]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to ten people, jobs or alternatives per side; stable matchings and minimum-cost assignments answer different questions.
For this problem type. Use about 2–8 agents on each side or 3–12 network vertices. Store costs, capacities and missing or forbidden edges explicitly.
Focal example. The code above passed its displayed check in 0.708 ms on Node.
Same API, measured input family.discrete.maximumMatching · vertices per side. Baseline test points across courses 1, 2, 5, 10. K_(n,n) has a diagonal perfect matching of size n.
Practical limit. Largest passing sample 100 (102 ms, 125.5 MiB peak process RSS). The first sampled passing call above 100 ms used 100 (102 ms). The runs did not locate a ceiling for this family. Complete bipartite input has n² edges. Verifying a matching uses its vertices and edges. More general optimization objectives need their own check.
Measured times, memory and outcomes
vertices per side · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.869
75.2
2
Baseline
Passed
0.511
74.2
5
Baseline
Passed
0.783
76.1
10
Baseline
Passed
1.21
75
25
Stretch
Passed
4.06
78.9
50
Stretch
Passed
24.22
91.6
100
Stretch
Passed
102
125.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.maximumMatching · 1 passing test case, 1 distinct argument description
In the network (3), (2), (1), (2), (3), find the maximum flow from to .
Worked solution
The cut has capacity . Flow: 2, 1, 2: total 5. Max flow min cut .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const g = discrete.digraph([["s", "a", 3], ["s", "b", 2], ["a", "b", 1], ["a", "t", 2], ["b", "t", 3]]);
console.log(String(discrete.maxFlow(g, "s", "t").value));
Checked output
5
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to ten people, jobs or alternatives per side; stable matchings and minimum-cost assignments answer different questions.
For this problem type. Use about 2–8 agents on each side or 3–12 network vertices. Store costs, capacities and missing or forbidden edges explicitly.
Focal example. The code above passed its displayed check in 0.465 ms on Node.
Related workload in this unit.discrete.maximumMatching · vertices per side. Baseline test points across courses 1, 2, 5, 10. K_(n,n) has a diagonal perfect matching of size n.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 100 (102 ms, 125.5 MiB peak process RSS). The first sampled passing call above 100 ms used 100 (102 ms). The runs did not locate a ceiling for this family. Complete bipartite input has n² edges. Verifying a matching uses its vertices and edges. More general optimization objectives need their own check.
Measured times, memory and outcomes
vertices per side · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.869
75.2
2
Baseline
Passed
0.511
74.2
5
Baseline
Passed
0.783
76.1
10
Baseline
Passed
1.21
75
25
Stretch
Passed
4.06
78.9
50
Stretch
Passed
24.22
91.6
100
Stretch
Passed
102
125.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.digraph · 3 passing test cases, 3 distinct argument descriptions
Three players jointly earn 12. Players 1 and 2 alone can earn 9. Does the proposed allocation (4,4,4) survive their blocking threat under transferable utility?
Worked solution
Their current total is 8. They can divide 9 as 4.5 each, strictly improving both payoffs.
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { R } from "@ratmath/core";
console.log(String(R`9-(4+4)`));
Checked output
1
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to ten people, jobs or alternatives per side; stable matchings and minimum-cost assignments answer different questions.
Focal example. The code above passed its displayed check in 0.109 ms on Node.
Same arithmetic expression. Replaced its first numeral 9 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.R · whole-number operand. Baseline test points across courses 0, 1, 10, 20, 100, 1,000, 1,000,000. (n+7)(n−3) by independent BigInt arithmetic.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 9,007,199,254,740,991 (1.67 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact integer arithmetic grows with operand bit length. Enter large integers as decimal strings or BigInts before any JavaScript Number conversion.
Measured times, memory and outcomes
whole-number operand · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
1.75
75
1
Baseline
Passed
1.70
75.7
10
Baseline
Passed
1.78
75.1
20
Baseline
Passed
1.88
75.4
100
Baseline
Passed
1.55
75.4
1,000
Baseline
Passed
1.36
75.3
1,000,000
Baseline
Passed
1.39
74.8
1,000,000,000
Stretch
Passed
1.69
76.3
9,007,199,254,740,991
Stretch
Passed
1.67
75.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
Roll a die. If it is even, flip two coins; otherwise flip one. What is the expected number of heads?
Worked solution
.
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import * as stats from "@ratmath/stats";
import { R } from "@ratmath/core";
console.log(String(stats.die().expect((d) => (d % 2 === 0 ? R`1` : R`1/2`))));
Checked output
3/4
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to ten people, jobs or alternatives per side; stable matchings and minimum-cost assignments answer different questions.
For this problem type. Use a few events or a table of roughly 2–36 elementary outcomes. Two to four independent dice are common; verify whether the question needs ordered tuples or a sum.
Focal example. The code above passed its displayed check in 0.249 ms on Node.
Related workload in this unit.stats.die.power · six-sided dice in the ordered sample space. Baseline test points across courses 1, 2, 3, 4. The implicit product has 6^n ordered tuples. Check the exact count and the probability of the all-sixes tuple without listing it.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 100 (2.08 ms, 76.7 MiB peak process RSS). The runs did not locate a ceiling for this family. An independent product stores its factors. Point lookup multiplies one weight per die. An arbitrary predicate may visit 6ⁿ tuples; asking for all entries also consumes exponential space.
Measured times, memory and outcomes
six-sided dice in the ordered sample space · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.650
74.9
2
Baseline
Passed
0.654
75.1
3
Baseline
Passed
0.953
75.2
4
Baseline
Passed
0.755
75.3
7
Stretch
Passed
0.751
75.6
9
Stretch
Passed
0.788
75.6
32
Stretch
Passed
1.68
75.5
100
Stretch
Passed
2.08
76.7
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
stats.die · 4 passing test cases, 2 distinct argument descriptions
Seven ordered dice. The current product represents 279,936 outcomes in 0.34 ms and streams the order-sensitive probability check in 33.46 ms. Accessing .entries materializes all tuples. For the sum, stats.die().sumOf(7) needs only 36 totals. Compare the representations and their measured costs
Accuracy notes (1)
Open · Two distinct categorical tuples can merge. A uniform table on the two arrays [‘a,sb’,‘c’] and [‘a’,‘b,sc’] should give each probability 1/2. The table reports one outcome with probability 1 because the composite string keys collide. Use unambiguous scalar IDs for such labels. Ordinary numeric dice faces have distinct keys.
Day 39 / 40 · Matching and assignments
Blocking pairs
Worked by hand
Problem
In a matching, both members of an unmatched pair prefer one another to their current partners. What follows?
Worked solution
They form a blocking pair, which disproves stability under those preferences.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Two to ten people, jobs or alternatives per side; stable matchings and minimum-cost assignments answer different questions.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 40 / 40 · Matching and assignments
Bayesian actions
Direct calculation@ratmath/core
Problem
A high type occurs with probability 1/4. An action pays 8 against high and 0 otherwise. Compare with a sure payoff of 3.
Worked solution
The first action's expected payoff is 2. A risk-neutral player prefers the sure 3.
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { R } from "@ratmath/core";
console.log(String(R`8/4`));
Checked output
2
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to ten people, jobs or alternatives per side; stable matchings and minimum-cost assignments answer different questions.
Focal example. The code above passed its displayed check in 0.055 ms on Node.
Same arithmetic expression. Replaced its first numeral 8 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.add · denominator. Baseline test points across courses 1, 2, 3, 12, 100, 1,000. Cross-multiply 1/n + 1/(n+1) against (2n+1)/(n(n+1)).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000,007 (0.038 ms, 76.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact work depends on the bit lengths of both numerator and denominator. A long sum of relatively prime fractions can build a large common denominator.
Measured times, memory and outcomes
denominator · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.034
74.9
2
Baseline
Passed
0.036
75.6
3
Baseline
Passed
0.040
75.9
12
Baseline
Passed
0.039
75.2
100
Baseline
Passed
0.041
75
1,000
Baseline
Passed
0.035
75.8
1,000,003
Stretch
Passed
0.044
75
1,000,000,007
Stretch
Passed
0.038
76.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions