36 of 40 focal problems use RatMath for a calculation or a substantive step.
Direct calculation
35 · 87.5%
Assisted
1 · 2.5%
Worked by hand
4 · 10%
Using the packages
Exact counting functions make large answers readable, but interpreting labels, order, repetition and symmetry is the main part of setting up a counting argument.
Calculator interface
Ask which objects are distinguishable and which symmetries identify outcomes. Display a small enumeration beside the counting formula and offer ranking for larger families.
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
36 of 40 days include a checked executable example. On 8 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 · Elementary counts. Choose from sets of roughly 2–100 elements, often with small k or k near half the set size.
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 9–16 · Partitions of sets and permutations. Permutations or set partitions mainly of 2–12 elements for listings; much larger n may be practical when only counting.
Unit benchmark · discrete.stirling2, elements. Largest passing sample 512 (181 ms, 113 MiB peak process RSS). The first sampled passing call above 100 ms used 512 (181 ms). The runs did not locate a ceiling for this family.
Days 17–24 · Integer partitions and series. Compositions, integer partitions and truncated generating functions typically through degrees 5–30.
Unit benchmark · discrete.stirling2, elements. Largest passing sample 512 (181 ms, 113 MiB peak process RSS). The first sampled passing call above 100 ms used 512 (181 ms). The runs did not locate a ceiling for this family.
Days 25–32 · Identities and structures. A few integer parameters, small trees or designs and binomial sums of tens of terms.
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 · Group actions and probability. Cyclic or dihedral actions on roughly 3–12 positions and a few colors. Counting orbits can avoid materializing all colorings.
Unit benchmark · structures.symmetric.orderStatistics, permuted points. Largest passing sample 7 (73.20 ms, 89.4 MiB peak process RSS). Library refusal at 8. The first sampled passing call above 100 ms used 6 (157 ms).
How many distinct arrangements of the letters of MISSISSIPPI are there?
Worked solution
11 letters: M once, I four times, S four times, P twice. .
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(4, 4, 2, 1));
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. Choose from sets of roughly 2–100 elements, often with small k or k near half the set size.
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.051 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
How many solutions in non-negative integers does have?
Worked solution
.
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.multichoose(4, 10));
Checked output
286n
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. Choose from sets of roughly 2–100 elements, often with small k or k near half the set size.
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.028 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.multichoose · 1 passing test case, 2 distinct argument descriptions
How many integers from 1 to 100 are divisible by 2, 3 or 5?
Worked solution
.
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 by = (d) => Array.from({ length: 100 }, (_, i) => i + 1).filter((n) => n % d === 0);
console.log(discrete.inclusionExclusion([by(2), by(3), by(5)]).union);
Checked output
74n
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. Choose from sets of roughly 2–100 elements, often with small k or k near half the set size.
Focal example. The code above passed its displayed check in 0.160 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.inclusionExclusion · 1 passing test case, 4 distinct argument descriptions
In how many ways can 5 letters go into 5 addressed envelopes with none in the right one?
Worked solution
.
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.derangementCount(5));
Checked output
44n
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. Choose from sets of roughly 2–100 elements, often with small k or k near half the set size.
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.041 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.derangementCount · 3 passing test cases, 7 distinct argument descriptions
How many lattice paths go from to with unit steps right and up?
Worked solution
Choose which 3 of the 7 steps go up: .
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.binomial(7, 3));
Checked output
35n
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. Choose from sets of roughly 2–100 elements, often with small k or k near half the set size.
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.109 ms on Node.
Same API, measured input family.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. 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. 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.binomial · 1 passing test case, 6 distinct argument descriptions
How many five-card poker hands contain exactly two pairs?
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.binomial(13, 2) * discrete.binomial(4, 2) ** 2n * 11n * 4n);
Checked output
123552n
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. Choose from sets of roughly 2–100 elements, often with small k or k near half the set size.
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.062 ms on Node.
Same API, measured input family.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. 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. 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.binomial · 1 passing test case, 6 distinct argument descriptions
How many strings consist of two uppercase English letters followed by one decimal digit if repeats are allowed?
Worked solution
Each of the three positions can be selected independently.
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`26^2*10`));
Checked output
6760
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. Choose from sets of roughly 2–100 elements, often with small k or k near half the set size.
Focal example. The code above passed its displayed check in 0.089 ms on Node.
Same arithmetic expression. Replaced its first numeral 26 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.multiply · operand bits. Baseline test points across courses 8, 32, 64, 256. Cross-multiply the unreduced integer products; operands have unlike denominators.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 131,072 (1.53 ms, 75.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Intermediate products can have twice the bit length of their factors. Repeated squaring can exhaust the engine’s BigInt allocation limit in a small number of steps.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
8
Baseline
Passed
0.317
74.6
32
Baseline
Passed
0.035
75.5
64
Baseline
Passed
0.045
75.1
256
Baseline
Passed
0.106
74
1,024
Stretch
Passed
0.035
75.3
8,192
Stretch
Passed
0.075
75.8
32,768
Stretch
Passed
0.245
75
131,072
Stretch
Passed
1.53
75.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.
core.R · 2 passing test cases, 10 distinct argument descriptions
Place three identical items among four bins. Stars and bars gives choose(6,3).
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.binomial(6,3));
Checked output
20n
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. Choose from sets of roughly 2–100 elements, often with small k or k near half the set size.
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.050 ms on Node.
Same API, measured input family.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. 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. 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.binomial · 1 passing test case, 6 distinct argument descriptions
How many functions from a 5-set onto a 3-set are there?
Worked solution
().
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.surjections(5, 3));
Checked output
150n
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. Permutations or set partitions mainly of 2–12 elements for listings; much larger n may be practical when only counting.
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.121 ms on Node.
Related workload in this unit.discrete.stirling2 · elements. Baseline test points across courses 2, 4, 8, 15. S(n,2)=2^(n−1)−1 from counting the two nonempty, unlabeled blocks.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 512 (181 ms, 113 MiB peak process RSS). The first sampled passing call above 100 ms used 512 (181 ms). The runs did not locate a ceiling for this family. The check holds the number of blocks at two. Keeping all possible block counts or listing partitions can be substantially more expensive.
Measured times, memory and outcomes
elements · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.174
75.3
4
Baseline
Passed
0.173
76.4
8
Baseline
Passed
0.195
74
15
Baseline
Passed
0.278
74.8
32
Stretch
Passed
0.250
74.8
128
Stretch
Passed
3.45
75.8
512
Stretch
Passed
181
113
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.surjections · 2 passing test cases, 2 distinct argument descriptions
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.stirling2(5, 2), discrete.bell(5)]);
Checked output
[15n, 52n]
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. Permutations or set partitions mainly of 2–12 elements for listings; much larger n may be practical when only counting.
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.085 ms on Node.
Same API, measured input family.discrete.stirling2 · elements. Baseline test points across courses 2, 4, 8, 15. S(n,2)=2^(n−1)−1 from counting the two nonempty, unlabeled blocks.
Practical limit. Largest passing sample 512 (181 ms, 113 MiB peak process RSS). The first sampled passing call above 100 ms used 512 (181 ms). The runs did not locate a ceiling for this family. The check holds the number of blocks at two. Keeping all possible block counts or listing partitions can be substantially more expensive.
Measured times, memory and outcomes
elements · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.174
75.3
4
Baseline
Passed
0.173
76.4
8
Baseline
Passed
0.195
74
15
Baseline
Passed
0.278
74.8
32
Stretch
Passed
0.250
74.8
128
Stretch
Passed
3.45
75.8
512
Stretch
Passed
181
113
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.stirling2 · 1 passing test case, 6 distinct argument descriptions
How many permutations of 5 elements have exactly 2 cycles?
Worked solution
: from .
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.stirling1(5, 2));
Checked output
50n
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. Permutations or set partitions mainly of 2–12 elements for listings; much larger n may be practical when only counting.
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.106 ms on Node.
Related workload in this unit.discrete.stirling2 · elements. Baseline test points across courses 2, 4, 8, 15. S(n,2)=2^(n−1)−1 from counting the two nonempty, unlabeled blocks.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 512 (181 ms, 113 MiB peak process RSS). The first sampled passing call above 100 ms used 512 (181 ms). The runs did not locate a ceiling for this family. The check holds the number of blocks at two. Keeping all possible block counts or listing partitions can be substantially more expensive.
Measured times, memory and outcomes
elements · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.174
75.3
4
Baseline
Passed
0.173
76.4
8
Baseline
Passed
0.195
74
15
Baseline
Passed
0.278
74.8
32
Stretch
Passed
0.250
74.8
128
Stretch
Passed
3.45
75.8
512
Stretch
Passed
181
113
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.stirling1 · 1 passing test case, 6 distinct argument descriptions
How many permutations of have exactly one descent?
Worked solution
.
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.eulerian(4, 1));
Checked output
11n
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. Permutations or set partitions mainly of 2–12 elements for listings; much larger n may be practical when only counting.
Focal example. The code above passed its displayed check in 0.113 ms on Node.
Related workload in this unit.discrete.stirling2 · elements. Baseline test points across courses 2, 4, 8, 15. S(n,2)=2^(n−1)−1 from counting the two nonempty, unlabeled blocks.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 512 (181 ms, 113 MiB peak process RSS). The first sampled passing call above 100 ms used 512 (181 ms). The runs did not locate a ceiling for this family. The check holds the number of blocks at two. Keeping all possible block counts or listing partitions can be substantially more expensive.
Measured times, memory and outcomes
elements · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.174
75.3
4
Baseline
Passed
0.173
76.4
8
Baseline
Passed
0.195
74
15
Baseline
Passed
0.278
74.8
32
Stretch
Passed
0.250
74.8
128
Stretch
Passed
3.45
75.8
512
Stretch
Passed
181
113
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.eulerian · 1 passing test case, 4 distinct argument descriptions
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. Permutations or set partitions mainly of 2–12 elements for listings; much larger n may be practical when only counting.
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
Direct calculation@ratmath/discrete · @ratmath/core
Problem
Ten letters go into ten envelopes at random. Find the expected number in the right envelope and the probability that none is.
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 discrete from "@ratmath/discrete";
import { R, Rational } from "@ratmath/core";
console.log([R`10 * 1/10`, new Rational(discrete.derangementCount(10), discrete.factorial(10))]);
Checked output
[1, 16481/44800]
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. Permutations or set partitions mainly of 2–12 elements for listings; much larger n may be practical when only counting.
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.108 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.derangementCount · 3 passing test cases, 7 distinct argument descriptions
Count incidence pairs (vertex,edge) in K₅ two ways.
Worked solution
Five vertices each have four neighbors, and ten edges each have two ends. Both counts give twenty.
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`5*4`));
Checked output
20
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. Permutations or set partitions mainly of 2–12 elements for listings; much larger n may be practical when only counting.
Focal example. The code above passed its displayed check in 0.068 ms on Node.
Same arithmetic expression. Replaced its first numeral 5 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
Explain why subsets of an n-element set correspond to binary strings of length n.
Worked solution
Fix an order on the elements and use one membership bit per element. Reading the one-bits reverses the construction.
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. Permutations or set partitions mainly of 2–12 elements for listings; much larger n may be practical when only counting.
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 · Integer partitions and series
Integer partitions
Direct calculation@ratmath/discrete
Problem
Find , the number of partitions of 10.
Worked solution
(by the pentagonal-number recurrence: ).
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.partitionCount(10));
Checked output
42n
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. Compositions, integer partitions and truncated generating functions typically through degrees 5–30.
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.090 ms on Node.
Related workload in this unit.discrete.stirling2 · elements. Baseline test points across courses 2, 4, 8, 15. S(n,2)=2^(n−1)−1 from counting the two nonempty, unlabeled blocks.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 512 (181 ms, 113 MiB peak process RSS). The first sampled passing call above 100 ms used 512 (181 ms). The runs did not locate a ceiling for this family. The check holds the number of blocks at two. Keeping all possible block counts or listing partitions can be substantially more expensive.
Measured times, memory and outcomes
elements · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.174
75.3
4
Baseline
Passed
0.173
76.4
8
Baseline
Passed
0.195
74
15
Baseline
Passed
0.278
74.8
32
Stretch
Passed
0.250
74.8
128
Stretch
Passed
3.45
75.8
512
Stretch
Passed
181
113
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.partitionCount · 3 passing test cases, 7 distinct argument descriptions
How many ways can 6 be written as an ordered sum of 3 positive integers?
Worked solution
.
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.compositionCount(6, 3));
Checked output
10n
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. Compositions, integer partitions and truncated generating functions typically through degrees 5–30.
Focal example. The code above passed its displayed check in 0.061 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.compositionCount · 1 passing test case, 3 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(String(discrete.recurrence({ coefficients: [5, -6], initial: [1, 4] }).closedForm()));
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. Compositions, integer partitions and truncated generating functions typically through degrees 5–30.
Focal example. The code above passed its displayed check in 1.05 ms on Node.
Related workload in this unit.discrete.stirling2 · elements. Baseline test points across courses 2, 4, 8, 15. S(n,2)=2^(n−1)−1 from counting the two nonempty, unlabeled blocks.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 512 (181 ms, 113 MiB peak process RSS). The first sampled passing call above 100 ms used 512 (181 ms). The runs did not locate a ceiling for this family. The check holds the number of blocks at two. Keeping all possible block counts or listing partitions can be substantially more expensive.
Measured times, memory and outcomes
elements · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.174
75.3
4
Baseline
Passed
0.173
76.4
8
Baseline
Passed
0.195
74
15
Baseline
Passed
0.278
74.8
32
Stretch
Passed
0.250
74.8
128
Stretch
Passed
3.45
75.8
512
Stretch
Passed
181
113
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
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. Compositions, integer partitions and truncated generating functions typically through degrees 5–30.
Focal example. The code above passed its displayed check in 0.578 ms on Node.
Related workload in this unit.discrete.stirling2 · elements. Baseline test points across courses 2, 4, 8, 15. S(n,2)=2^(n−1)−1 from counting the two nonempty, unlabeled blocks.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 512 (181 ms, 113 MiB peak process RSS). The first sampled passing call above 100 ms used 512 (181 ms). The runs did not locate a ceiling for this family. The check holds the number of blocks at two. Keeping all possible block counts or listing partitions can be substantially more expensive.
Measured times, memory and outcomes
elements · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.174
75.3
4
Baseline
Passed
0.173
76.4
8
Baseline
Passed
0.195
74
15
Baseline
Passed
0.278
74.8
32
Stretch
Passed
0.250
74.8
128
Stretch
Passed
3.45
75.8
512
Stretch
Passed
181
113
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
In how many ways can 25 cents be made from pennies, nickels and dimes?
Worked solution
The coefficient of in : with dimes (0, 1, 2) the nickels range over : .
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 den = (k) => discrete.series(Array.from({ length: k + 1 }, (_, i) => (i === 0 ? 1 : i === k ? -1 : 0)));
console.log(String(den(1).multiply(den(5)).multiply(den(10)).reciprocal().coefficient(25)));
Checked output
12
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. Compositions, integer partitions and truncated generating functions typically through degrees 5–30.
Focal example. The code above passed its displayed check in 1.38 ms on Node.
Related workload in this unit.discrete.stirling2 · elements. Baseline test points across courses 2, 4, 8, 15. S(n,2)=2^(n−1)−1 from counting the two nonempty, unlabeled blocks.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 512 (181 ms, 113 MiB peak process RSS). The first sampled passing call above 100 ms used 512 (181 ms). The runs did not locate a ceiling for this family. The check holds the number of blocks at two. Keeping all possible block counts or listing partitions can be substantially more expensive.
Measured times, memory and outcomes
elements · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.174
75.3
4
Baseline
Passed
0.173
76.4
8
Baseline
Passed
0.195
74
15
Baseline
Passed
0.278
74.8
32
Stretch
Passed
0.250
74.8
128
Stretch
Passed
3.45
75.8
512
Stretch
Passed
181
113
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.series · 2 passing test cases, 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. Compositions, integer partitions and truncated generating functions typically through degrees 5–30.
Focal example. The code above passed its displayed check in 2.10 ms on Node.
Related workload in this unit.discrete.stirling2 · elements. Baseline test points across courses 2, 4, 8, 15. S(n,2)=2^(n−1)−1 from counting the two nonempty, unlabeled blocks.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 512 (181 ms, 113 MiB peak process RSS). The first sampled passing call above 100 ms used 512 (181 ms). The runs did not locate a ceiling for this family. The check holds the number of blocks at two. Keeping all possible block counts or listing partitions can be substantially more expensive.
Measured times, memory and outcomes
elements · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.174
75.3
4
Baseline
Passed
0.173
76.4
8
Baseline
Passed
0.195
74
15
Baseline
Passed
0.278
74.8
32
Stretch
Passed
0.250
74.8
128
Stretch
Passed
3.45
75.8
512
Stretch
Passed
181
113
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
What polynomial encodes choosing zero, one or two copies of a part of size 3?
Worked solution
Each permitted total contributes one monomial. The factor is 1+x³+x⁶.
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. Compositions, integer partitions and truncated generating functions typically through degrees 5–30.
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 · Integer partitions and series
Boundary conditions
Worked by hand
Problem
Strings of length n without consecutive ones follow a Fibonacci recurrence. What are the counts for n=0 and 1?
Worked solution
There is one empty string and two single-bit strings. These initial values determine the recurrence.
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. Compositions, integer partitions and truncated generating functions typically through degrees 5–30.
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 25 / 40 · Identities and structures
Catalan numbers
Direct calculation@ratmath/discrete
Problem
How many balanced strings of 3 pairs of brackets are there? What is ?
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.dyckWords(3).count, discrete.catalan(5)]);
Checked output
[5n, 42n]
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. A few integer parameters, small trees or designs and binomial sums of tens of terms.
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.235 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.dyckWords · 3 passing test cases, 4 distinct argument descriptions
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";
let s = 0n;
for (let k = 0; k <= 10; k++) s += discrete.binomial(10, k) ** 2n;
console.log([s, discrete.binomial(20, 10)]);
Checked output
[184756n, 184756n]
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. A few integer parameters, small trees or designs and binomial sums of tens of terms.
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.088 ms on Node.
Same API, measured input family.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. 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. 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.binomial · 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.labelledTrees(5).count);
Checked output
125n
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. A few integer parameters, small trees or designs and binomial sums of tens of terms.
Focal example. The code above passed its displayed check in 0.175 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.labelledTrees · 1 passing test case, 2 distinct argument descriptions
A Steiner triple system on 7 points has every pair in exactly one triple. How many triples does it have?
Worked solution
(the Fano plane).
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.steinerTripleSystem(7);
console.log(Object.keys(S).length);
Checked output
7
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. A few integer parameters, small trees or designs and binomial sums of tens of terms.
Focal example. The code above passed its displayed check in 0.236 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.steinerTripleSystem · 1 passing test case, 2 distinct argument descriptions
Remove the smallest leaf each time and record its neighbour: 1 (4), 2 (4), 3 (4), then 4 is a leaf (5). Code .
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.prufer(discrete.graph([[1, 4], [2, 4], [3, 4], [4, 5], [5, 6]])));
Checked output
[4, 4, 4, 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. A few integer parameters, small trees or designs and binomial sums of tens of terms.
For this problem type. Use 3–20 labeled vertices and a stated edge list. For a walk count also supply length, usually a single digit in a hand problem.
Focal example. The code above passed its displayed check in 0.359 ms on Node.
Related workload in this unit.discrete.isBipartite · cycle vertices. Baseline test points across courses 3, 4, 5, 12, 30. A cycle has a bipartition precisely when its length is even.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (21.70 ms, 92.2 MiB peak process RSS). The runs did not locate a ceiling for this family. Graph traversal depends on vertices and edges. A long sparse cycle has far fewer edges than a dense graph of the same order.
Measured times, memory and outcomes
cycle vertices · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
0.252
75.7
4
Baseline
Passed
0.382
74.8
5
Baseline
Passed
0.406
75
12
Baseline
Passed
0.424
74.9
30
Baseline
Passed
0.349
75.7
100
Stretch
Passed
0.609
75.9
1,000
Stretch
Passed
20.72
77.9
10,000
Stretch
Passed
21.70
92.2
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.prufer · 1 passing test case, 1 distinct argument description
Cayley: . A cycle loses any one of its 5 edges: 5.
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.spanningTreeCount(discrete.complete(4)), discrete.spanningTreeCount(discrete.cycleGraph(5))]
);
Checked output
[16n, 5n]
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. A few integer parameters, small trees or designs and binomial sums of tens of terms.
For this problem type. Use 3–20 labeled vertices and a stated edge list. For a walk count also supply length, usually a single digit in a hand problem.
Focal example. The code above passed its displayed check in 0.223 ms on Node.
Same API, measured input family.discrete.spanningTreeCount · complete-graph vertices. Baseline test points across courses 2, 3, 5, 8. Cayley's formula gives n^(n−2) labeled spanning trees of K_n.
Practical limit. Largest passing sample 128 (387 ms, 123.2 MiB peak process RSS). The first sampled passing call above 100 ms used 128 (387 ms). The runs did not locate a ceiling for this family. Each complete graph has n(n−1)/2 edges and a rapidly growing exact tree count. Listing the trees would be much more expensive.
Measured times, memory and outcomes
complete-graph vertices · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.230
76.4
3
Baseline
Passed
3.52
75.2
5
Baseline
Passed
0.304
75.5
8
Baseline
Passed
0.389
74.7
16
Stretch
Passed
0.809
74.9
32
Stretch
Passed
9.90
77.8
64
Stretch
Passed
23.83
88.7
128
Stretch
Passed
387
123.2
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.spanningTreeCount · 2 passing test cases, 1 distinct argument description
Count paths with three right steps and two up steps.
Worked solution
Choose positions for the two up steps among five.
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.binomial(5,2));
Checked output
10n
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. A few integer parameters, small trees or designs and binomial sums of tens of terms.
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.044 ms on Node.
Same API, measured input family.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. 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. 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.binomial · 1 passing test case, 6 distinct argument descriptions
If every pair of nine points occurs in one triple, how many triples are required?
Worked solution
Each triple accounts for three pairs. Divide the 36 total pairs by three.
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.binomial(9,2)/3n);
Checked output
12n
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. A few integer parameters, small trees or designs and binomial sums of tens of terms.
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.033 ms on Node.
Same API, measured input family.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. 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. 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.binomial · 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. Cyclic or dihedral actions on roughly 3–12 positions and a few colors. Counting orbits can avoid materializing all colorings.
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
Write the cycle index of the rotation group of a square acting on its vertices.
Worked solution
Identity , quarter turns (twice), half turn : .
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.cycleIndex(discrete.symmetry.cyclic(4))));
Checked output
(1/2) s4 + (1/4) s2^2 + (1/4) s1^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. Cyclic or dihedral actions on roughly 3–12 positions and a few colors. Counting orbits can avoid materializing all colorings.
Focal example. The code above passed its displayed check in 0.240 ms on Node.
Related workload in this unit.structures.symmetric.orderStatistics · permuted points. Baseline test points across courses 2, 3, 4, 5. Count every permutation by order; the histogram totals n! and contains one identity.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 7 (73.20 ms, 89.4 MiB peak process RSS). Library refusal at 8. The first sampled passing call above 100 ms used 6 (157 ms). An explicit order histogram visits group elements. Sₙ has n! elements. A formula for the order of Sₙ avoids this enumeration.
Measured times, memory and outcomes
permuted points · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
1.16
75.6
3
Baseline
Passed
1.36
75.1
4
Baseline
Passed
2.07
75.2
5
Baseline
Passed
10.28
80.6
6
Stretch
Passed
157
90.6
7
Stretch
Passed
73.20
89.4
8
Stretch
Library refusal · RangeError: the group has more than 20000 elements
26.99
90.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.cycleIndex · 1 passing test case, 1 distinct argument description
How many necklaces of 4 beads in 2 colours are there, up to rotation?
Worked solution
Fixed colourings: identity 16, rotation by 2 fixes 4, rotations by 1 and 3 fix 2 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 structures from "@ratmath/structures";
const C = structures.cyclic(4);
const strings = Array.from({ length: 16 }, (_, m) => m.toString(2).padStart(4, "0"));
console.log(
String(structures.burnside(structures.action(C, strings, (g, s) => s.slice(Number(g)) + s.slice(0, Number(g)))))
);
Checked output
(1/4)·(16 + 4 + 2 + 2) = 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. Cyclic or dihedral actions on roughly 3–12 positions and a few colors. Counting orbits can avoid materializing all colorings.
For this problem type. Common examples include cyclic orders under 30, polygons with 3–12 sides, and permutations on 3–5 letters. Group order and permutation degree measure different things.
Focal example. The code above passed its displayed check in 0.560 ms on Node.
Related workload in this unit.structures.cyclic.elementOrder · group order. Baseline test points across courses 2, 4, 6, 12, 24. The element 2 of Z/n has order n/gcd(2,n).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000 (116 ms, 80.6 MiB peak process RSS). RSS cutoff at 10,000. The first sampled passing call above 100 ms used 1,000 (116 ms). Element orders are cheap compared with constructing every subgroup. Check the representation and group operation before transferring a timing.
Measured times, memory and outcomes
group order · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.739
74.6
4
Baseline
Passed
0.827
75.3
6
Baseline
Passed
0.937
75.2
12
Baseline
Passed
0.954
76.2
24
Baseline
Passed
1.52
75.9
100
Stretch
Passed
7.19
76.4
1,000
Stretch
Passed
116
80.6
10,000
Stretch
RSS cutoff
—
393.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.
structures.cyclic · 31 passing test cases, 11 distinct argument descriptions
How many length-three binary necklaces remain distinct under rotations and reflections?
Worked solution
The dihedral group on three positions realizes every permutation. Only the number of black beads matters, so the four possibilities have zero, one, two or three black beads.
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+2*2+3*4)/6`));
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. Cyclic or dihedral actions on roughly 3–12 positions and a few colors. Counting orbits can avoid materializing all colorings.
Focal example. The code above passed its displayed check in 0.104 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
In a group of 23 people, what is the probability that two share a birthday (365 equally likely days)?
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.
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. Cyclic or dihedral actions on roughly 3–12 positions and a few colors. Counting orbits can avoid materializing all colorings.
Focal example. The code above passed its displayed check in 0.368 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.core.range · terms. Baseline test points across courses 1, 10, 100, 1,000. Check length and every consecutive integer from 1 through n.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000 (141 ms, 277.5 MiB peak process RSS). The first sampled passing call above 100 ms used 1,000,000 (141 ms). The runs did not locate a ceiling for this family. Keeping the entire result requires storage proportional to its length. Shortening the displayed list after construction still pays that cost.
Measured times, memory and outcomes
terms · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.173
75.5
10
Baseline
Passed
0.192
74.9
100
Baseline
Passed
0.269
74.7
1,000
Baseline
Passed
1.52
75.6
10,000
Stretch
Passed
5.29
80.9
100,000
Stretch
Passed
11.57
109.6
1,000,000
Stretch
Passed
141
277.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.
core.R · 2 passing test cases, 10 distinct argument descriptions
A box has 8 red and 12 blue balls. Five are drawn without replacement. Find .
Worked solution
.
Using RatMath
Set the distribution parameters first. Distinguish a point probability, a lower cumulative probability and its complementary tail when reading the result.
JavaScript module
import * as stats from "@ratmath/stats";
console.log(String(stats.hypergeometric(20, 8, 5).pmf(2)));
Checked output
385/969
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. Cyclic or dihedral actions on roughly 3–12 positions and a few colors. Counting orbits can avoid materializing all colorings.
For this problem type. Typical examples use small integer counts, trial or population sizes from a few to about 100, and probabilities strictly between 0 and 1 unless studying an endpoint.
Focal example. The code above passed its displayed check in 0.235 ms on Node.
Related workload in this unit.stats.binomial.pmf · trials. Baseline test points across courses 1, 5, 20, 100. For fair trials, P(exactly one success)=n/2^n.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (0.836 ms, 74.4 MiB peak process RSS). The runs did not locate a ceiling for this family. Very large trial counts create long rational probabilities. Near the tails, converting to floating point can erase small positive probabilities.
Measured times, memory and outcomes
trials · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.527
76.3
5
Baseline
Passed
0.495
74.4
20
Baseline
Passed
0.723
75.1
100
Baseline
Passed
10.61
75.4
500
Stretch
Passed
0.559
75.8
2,000
Stretch
Passed
0.536
75.1
10,000
Stretch
Passed
0.836
74.4
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.hypergeometric · 2 passing test cases, 2 distinct argument descriptions
How many two-colorings of four labelled positions are unchanged by a half turn?
Worked solution
Opposite positions must match, leaving two independent color choices.
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^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. Cyclic or dihedral actions on roughly 3–12 positions and a few colors. Counting orbits can avoid materializing all colorings.
Focal example. The code above passed its displayed check in 0.063 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.multiply · operand bits. Baseline test points across courses 8, 32, 64, 256. Cross-multiply the unreduced integer products; operands have unlike denominators.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 131,072 (1.53 ms, 75.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Intermediate products can have twice the bit length of their factors. Repeated squaring can exhaust the engine’s BigInt allocation limit in a small number of steps.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
8
Baseline
Passed
0.317
74.6
32
Baseline
Passed
0.035
75.5
64
Baseline
Passed
0.045
75.1
256
Baseline
Passed
0.106
74
1,024
Stretch
Passed
0.035
75.3
8,192
Stretch
Passed
0.075
75.8
32,768
Stretch
Passed
0.245
75
131,072
Stretch
Passed
1.53
75.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.
core.R · 2 passing test cases, 10 distinct argument descriptions
How many fixed points does a uniformly random permutation of n≥1 objects have on average?
Worked solution
Each position is fixed with probability 1/n. The sum of n indicator expectations is one regardless of dependence.
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. Cyclic or dihedral actions on roughly 3–12 positions and a few colors. Counting orbits can avoid materializing all colorings.
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.