35 of 40 focal problems use RatMath for a calculation or a substantive step.
Direct calculation
33 · 82.5%
Assisted
2 · 5%
Worked by hand
5 · 12.5%
Using the packages
Exact counts and graph algorithms are convenient. Turning language into quantifiers or identifying a bijection is the difficult step, and a finite check cannot establish an inductive claim.
Calculator interface
Switch among set, graph and formula views while preserving the student's labels. Let a proof request record the base case, induction hypothesis and step separately.
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
35 of 40 days include a checked executable example. On 7 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 · Logic and proof. Two to six proposition letters, short proofs and one or two nested quantifiers or induction indices.
Unit benchmark · logic.entails, successive implications. Largest passing sample 128 (20.49 ms, 89.4 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 9–16 · Counting. Finite sets usually under 100 elements when only a count is wanted; listing examples is normally restricted to much smaller sets.
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 17–24 · Recurrences and arithmetic. One- or two-term recurrences, moduli from single digits to hundreds and modest exponents for hand checks.
Unit benchmark · numtheory.modPow, exponent bits. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 25–32 · Graphs and trees. Graphs with roughly 3–20 vertices and tens of edges; counting paths differs greatly from listing every path.
Unit benchmark · discrete.isBipartite, cycle vertices. Largest passing sample 10,000 (21.70 ms, 92.2 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 33–40 · Relations and representations. Small finite sets, relations and functions, or asymptotic families described symbolically by one size parameter.
Unit benchmark · logic.countModels, Boolean atoms. Largest passing sample 20 (21.16 ms, 97.1 MiB peak process RSS). Library refusal at 24.
Yes (hypothetical syllogism): the only way to make false is true, false, and then one of the hypotheses is false.
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 logic from "@ratmath/logic";
console.log(logic.classify("((p -> q) & (q -> r)) -> (p -> r)").kind);
Checked output
tautology
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to six proposition letters, short proofs and one or two nested quantifiers or induction indices.
For this problem type. Typical written truth tables have 1–6 atoms and therefore 2–64 rows. Proof search and identifying a single model have different scaling.
Focal example. The code above passed its displayed check in 2.53 ms on Node.
Related workload in this unit.logic.countModels · Boolean atoms. Baseline test points across courses 1, 2, 4, 8. A disjunction of n distinct atoms is false in exactly one of its 2^n valuations.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 20 (21.16 ms, 97.1 MiB peak process RSS). Library refusal at 24. An n-atom truth table has 2ⁿ rows. This implementation guards tables above 22 atoms. SAT search has different resource costs.
Measured times, memory and outcomes
Boolean atoms · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.290
75.3
2
Baseline
Passed
0.268
74.6
4
Baseline
Passed
0.426
76.4
8
Baseline
Passed
0.371
75.4
12
Stretch
Passed
0.720
75.6
16
Stretch
Passed
2.33
78
19
Stretch
Passed
10.50
88.2
20
Stretch
Passed
21.16
97.1
24
Stretch
Library refusal · LogicError: a table over 24 atoms has 2^24 rows; use satisfiable() or valid() instead
0.440
75.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.
logic.classify · 2 passing test cases, 5 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 logic from "@ratmath/logic";
console.log(logic.equivalent("!(p & q)", "!p | !q").status);
Checked output
equivalent
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to six proposition letters, short proofs and one or two nested quantifiers or induction indices.
For this problem type. Typical written truth tables have 1–6 atoms and therefore 2–64 rows. Proof search and identifying a single model have different scaling.
Focal example. The code above passed its displayed check in 0.330 ms on Node.
Related workload in this unit.logic.countModels · Boolean atoms. Baseline test points across courses 1, 2, 4, 8. A disjunction of n distinct atoms is false in exactly one of its 2^n valuations.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 20 (21.16 ms, 97.1 MiB peak process RSS). Library refusal at 24. An n-atom truth table has 2ⁿ rows. This implementation guards tables above 22 atoms. SAT search has different resource costs.
Measured times, memory and outcomes
Boolean atoms · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.290
75.3
2
Baseline
Passed
0.268
74.6
4
Baseline
Passed
0.426
76.4
8
Baseline
Passed
0.371
75.4
12
Stretch
Passed
0.720
75.6
16
Stretch
Passed
2.33
78
19
Stretch
Passed
10.50
88.2
20
Stretch
Passed
21.16
97.1
24
Stretch
Library refusal · LogicError: a table over 24 atoms has 2^24 rows; use satisfiable() or valid() instead
0.440
75.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.
logic.equivalent · 3 passing test cases, 4 distinct argument descriptions
Enter the expression in the form given. Expand or factor the result in reverse to check that it represents the original expression.
JavaScript module
import * as symbolic from "@ratmath/symbolic";
console.log(String(symbolic.factor(symbolic.sum("k^3", "k", 1, "n").value)));
Checked output
n^2*(n + 1)^2/4
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to six proposition letters, short proofs and one or two nested quantifiers or induction indices.
For this problem type. Use one or two variables and polynomial degrees roughly 2–6. Rational expressions often have two or three denominator factors.
Focal example. The code above passed its displayed check in 1.83 ms on Node.
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.
symbolic.factor · 1 passing test case, 4 distinct argument descriptions
How many people must be in a room to be sure that three share a birth month?
Worked solution
.
Using RatMath
The call tests the proposed threshold of 25. To show minimality, distribute 24 people evenly across the 12 months.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(discrete.pigeonhole(25, 12));
Checked output
{ atLeast: 3n, atMost: 2n, forced: true, statement: "25 items in 12 boxes: some box holds at least 3" }
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to six proposition letters, short proofs and one or two nested quantifiers or induction indices.
Focal example. The code above passed its displayed check in 0.179 ms on Node.
Related workload in this unit.logic.entails · successive implications. Baseline test points across courses 1, 2, 4, 8. The assumptions p₀, p₀→p₁, … imply pₙ by repeated modus ponens.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 128 (20.49 ms, 89.4 MiB peak process RSS). The runs did not locate a ceiling for this family. A chain of implications is a favorable entailment instance. Search depth, branching and quantifiers can be decisive even for short formulas.
Measured times, memory and outcomes
successive implications · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.84
75.5
2
Baseline
Passed
1.91
75.9
4
Baseline
Passed
2.18
75.8
8
Baseline
Passed
2.75
76.8
16
Stretch
Passed
3.05
76.1
32
Stretch
Passed
9.72
75.9
64
Stretch
Passed
6.86
78.4
128
Stretch
Passed
20.49
89.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.
discrete.pigeonhole · 1 passing test case, 3 distinct argument descriptions
In any valuation with true, forces true, contradicting . So is false (modus tollens).
Using RatMath
Translate the statement into the propositional syntax in the example. Parenthesize the intended scope and read a valuation as an assignment to those named propositions.
JavaScript module
import * as logic from "@ratmath/logic";
console.log(logic.entails("p -> q, ~q", "~p").status);
Checked output
valid
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to six proposition letters, short proofs and one or two nested quantifiers or induction indices.
For this problem type. Typical written truth tables have 1–6 atoms and therefore 2–64 rows. Proof search and identifying a single model have different scaling.
Focal example. The code above passed its displayed check in 0.321 ms on Node.
Same API, measured input family.logic.entails · successive implications. Baseline test points across courses 1, 2, 4, 8. The assumptions p₀, p₀→p₁, … imply pₙ by repeated modus ponens.
Practical limit. Largest passing sample 128 (20.49 ms, 89.4 MiB peak process RSS). The runs did not locate a ceiling for this family. A chain of implications is a favorable entailment instance. Search depth, branching and quantifiers can be decisive even for short formulas.
Measured times, memory and outcomes
successive implications · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.84
75.5
2
Baseline
Passed
1.91
75.9
4
Baseline
Passed
2.18
75.8
8
Baseline
Passed
2.75
76.8
16
Stretch
Passed
3.05
76.1
32
Stretch
Passed
9.72
75.9
64
Stretch
Passed
6.86
78.4
128
Stretch
Passed
20.49
89.4
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.
logic.entails · 2 passing test cases, 3 distinct argument descriptions
Negate “every student submitted at least one exercise.”
Worked solution
Some student submitted no exercises. Swap the universal and existential quantifiers and negate the predicate.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Two to six proposition letters, short proofs and one or two nested quantifiers or induction indices.
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 07 / 40 · Logic and proof
Vacuous truth
Worked by hand
Problem
Is “every element of the empty set is even” true?
Worked solution
Yes. A counterexample would have to be an element of the empty set.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Two to six proposition letters, short proofs and one or two nested quantifiers or induction indices.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 08 / 40 · Logic and proof
The induction step
Assisted@ratmath/symbolic
Problem
To prove 1+3+⋯+(2n−1)=n², what identity closes the step?
Worked solution
Starting from k², the next odd term is 2k+1. Their sum is (k+1)². The base case n=1 must also hold.
Using RatMath
Compare the two expressions symbolically. Work on their common domain, including any restrictions introduced by division.
JavaScript module
import * as symbolic from "@ratmath/symbolic";
console.log(String(symbolic.equal("k^2+2*k+1","(k+1)^2")));
Checked output
equal (normal form)
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to six proposition letters, short proofs and one or two nested quantifiers or induction indices.
Focal example. The code above passed its displayed check in 0.263 ms on Node.
Related workload in this unit.symbolic.expand · degree. Baseline test points across courses 1, 2, 4, 8. Sum the expanded coefficients at x=1 by direct substitution; result 2^n. Also check at x=0 and 2.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 128 (47.68 ms, 96.3 MiB peak process RSS). The runs did not locate a ceiling for this family. A univariate binomial has n+1 terms. With several variables the number of monomials can grow combinatorially even at modest degree.
Measured times, memory and outcomes
degree · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
26.10
75.9
2
Baseline
Passed
3.05
75.5
4
Baseline
Passed
2.75
77.3
8
Baseline
Passed
4.23
79.5
16
Stretch
Passed
5.88
82.6
32
Stretch
Passed
6.12
87.9
64
Stretch
Passed
15.73
89.5
128
Stretch
Passed
47.68
96.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.
symbolic.equal · 8 passing test cases, 28 distinct argument descriptions
{type="op", op="-", args=[Object, Object] (n=2)}, "x*exp(x)", {assume={x="x > 1"}} or {type="op", op="+", args=[Object, Object] (n=2)}, "1/(x^2+1)^2", {assume={x="x > 1"}} · every result differentiates back to the integrand
Direct calculation@ratmath/discrete · @ratmath/core
Problem
How many integers from 1 to 1000 are divisible by 3, 5 or 7?
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";
import { range } from "@ratmath/core";
const upTo = (d) => range(d, 1000, d);
console.log(
discrete.inclusionExclusion([upTo(3), upTo(5), upTo(7)].map((l) => l.map(String))).union
);
Checked output
543n
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. Finite sets usually under 100 elements when only a count is wanted; listing examples is normally restricted to much smaller sets.
Focal example. The code above passed its displayed check in 1.00 ms on Node.
Same API, measured input family.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. 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. 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.inclusionExclusion · 1 passing test case, 4 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. Finite sets usually under 100 elements when only a count is wanted; listing examples is normally restricted to much smaller sets.
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 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. Finite sets usually under 100 elements when only a count is wanted; listing examples is normally restricted to much smaller sets.
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
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. Finite sets usually under 100 elements when only a count is wanted; listing examples is normally restricted to much smaller sets.
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.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
In how many ways can 6 letters go into 6 envelopes with none in its own envelope?
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(6));
Checked output
265n
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. Finite sets usually under 100 elements when only a count is wanted; listing examples is normally restricted to much smaller sets.
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.089 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 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. Finite sets usually under 100 elements when only a count is wanted; listing examples is normally restricted to much smaller sets.
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
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. Finite sets usually under 100 elements when only a count is wanted; listing examples is normally restricted to much smaller sets.
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
How many length-five binary strings contain at least one 1?
Worked solution
Remove the all-zero word from all 32 strings.
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^5-1`));
Checked output
31
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. Finite sets usually under 100 elements when only a count is wanted; listing examples is normally restricted to much smaller sets.
Focal example. The code above passed its displayed check in 0.095 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
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. One- or two-term recurrences, moduli from single digits to hundreds and modest exponents for hand checks.
Focal example. The code above passed its displayed check in 2.10 ms on Node.
Related workload in this unit.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.recurrence · 2 passing test cases, 5 distinct argument descriptions
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.modPow(7n, 222n, 11n));
Checked output
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. One- or two-term recurrences, moduli from single digits to hundreds and modest exponents for hand checks.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.128 ms on Node.
Same API, measured input family.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
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.
numtheory.modPow · 4 passing test cases, 22 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 numtheory from "@ratmath/numtheory";
console.log(numtheory.egcd(252n, 198n));
Checked output
{ g: 18n, x: 4n, y: -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. One- or two-term recurrences, moduli from single digits to hundreds and modest exponents for hand checks.
Focal example. The code above passed its displayed check in 0.113 ms on Node.
Related workload in this unit.numtheory.gcd · operand bits. Baseline test points across courses 4, 8, 16, 32. Consecutive integers m,m+1 are coprime, so gcd(7m,7(m+1))=7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 32,768 (0.183 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Euclidean reduction depends on operand size and their quotient sequence. Consecutive Fibonacci numbers need more steps than many inputs of the same bit length.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
4
Baseline
Passed
0.171
74.8
8
Baseline
Passed
0.132
74.7
16
Baseline
Passed
0.129
74.8
32
Baseline
Passed
0.131
76.2
256
Stretch
Passed
0.124
74.5
4,096
Stretch
Passed
0.165
74.9
32,768
Stretch
Passed
0.183
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.
numtheory.egcd · 1 passing test case, 3 distinct argument descriptions
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.modInverse(17n, 43n));
Checked output
38n
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. One- or two-term recurrences, moduli from single digits to hundreds and modest exponents for hand checks.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.144 ms on Node.
Related workload in this unit.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.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.
numtheory.modInverse · 1 passing test case, 6 distinct argument descriptions
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.crt([2, 3, 2], [3, 5, 7]));
Checked output
{ x: 23n, modulus: 105n }
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. One- or two-term recurrences, moduli from single digits to hundreds and modest exponents for hand checks.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.193 ms on Node.
Related workload in this unit.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.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.
numtheory.crt · 2 passing test cases, 12 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 numtheory from "@ratmath/numtheory";
console.log(numtheory.solveLinear(17, 3, 29).solutions);
Checked output
[7n]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One- or two-term recurrences, moduli from single digits to hundreds and modest exponents for hand checks.
Focal example. The code above passed its displayed check in 0.189 ms on Node.
Related workload in this unit.numtheory.gcd · operand bits. Baseline test points across courses 4, 8, 16, 32. Consecutive integers m,m+1 are coprime, so gcd(7m,7(m+1))=7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 32,768 (0.183 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Euclidean reduction depends on operand size and their quotient sequence. Consecutive Fibonacci numbers need more steps than many inputs of the same bit length.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
4
Baseline
Passed
0.171
74.8
8
Baseline
Passed
0.132
74.7
16
Baseline
Passed
0.129
74.8
32
Baseline
Passed
0.131
76.2
256
Stretch
Passed
0.124
74.5
4,096
Stretch
Passed
0.165
74.9
32,768
Stretch
Passed
0.183
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.
numtheory.solveLinear · 1 passing test case, 6 distinct argument descriptions
A move changes a counter by ±2. Can a path from 3 reach 8?
Worked solution
Each move preserves parity. The start is odd and the proposed endpoint is even.
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. One- or two-term recurrences, moduli from single digits to hundreds and modest exponents for hand checks.
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 · Recurrences and arithmetic
Euclidean remainders
Direct calculation@ratmath/core
Problem
Find the nonnegative residue of −17 modulo 5.
Worked solution
Add a multiple of 5 to enter [0,5).
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`-17+4*5`));
Checked output
3
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One- or two-term recurrences, moduli from single digits to hundreds and modest exponents for hand checks.
Focal example. The code above passed its displayed check in 0.082 ms on Node.
Same arithmetic expression. Replaced its first numeral 17 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
: every degree is 4 (even) and it is connected, so yes. : degrees are 3, so no.
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.eulerTour(discrete.complete(5)).exists, discrete.eulerTour(discrete.complete(4)).exists]
);
Checked output
[true, false]
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. Graphs with roughly 3–20 vertices and tens of edges; counting paths differs greatly from listing every path.
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 1.19 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.eulerTour · 1 passing test case, 3 distinct argument descriptions
Graph, {closed=false} or Graph, {closed=true} · Euler tours
discrete.complete · 14 passing test cases, 9 distinct argument descriptions
Edges with weights: AB 4, AC 2, BC 1, BD 5, CD 8, CE 10, DE 2. Find the shortest path from A to E.
Worked solution
A–C–B–D–E, length .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const g = discrete.graph([["A", "B", 4], ["A", "C", 2], ["B", "C", 1], ["B", "D", 5], ["C", "D", 8], ["C", "E", 10], ["D", "E", 2]]);
const p = discrete.shortestPath(g, "A", "E");
console.log([p.path, p.distance]);
Checked output
[["A", "C", "B", "D", "E"], 10]
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. Graphs with roughly 3–20 vertices and tens of edges; counting paths differs greatly from listing every path.
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 1.06 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.graph · 10 passing test cases, 21 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. Graphs with roughly 3–20 vertices and tens of edges; counting paths differs greatly from listing every path.
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.494 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.graph · 10 passing test cases, 21 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.spanningTreeCount(discrete.complete(5)));
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. Graphs with roughly 3–20 vertices and tens of edges; counting paths differs greatly from listing every path.
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.304 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
A graph has degree sequence . How many edges does it have? Build one and check.
Worked solution
, so 6 edges. For example a 5-cycle plus one chord.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const g = discrete.graph([[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3]]);
console.log([g.size, g.degreeSequence()]);
Checked output
[6, [3, 3, 2, 2, 2]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Graphs with roughly 3–20 vertices and tens of edges; counting paths differs greatly from listing every path.
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.135 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.graph · 10 passing test cases, 21 distinct argument descriptions
Two triangles and are joined by the edge . Find the bridges and cut vertices.
Worked solution
Only lies on no cycle: it is the one bridge. Removing 3 or 4 disconnects the graph: the cut vertices are 3 and 4.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const g = discrete.graph([[1, 2], [2, 3], [3, 1], [3, 4], [4, 5], [5, 6], [6, 4]]);
console.log([discrete.bridges(g).map((e) => [e.from, e.to]), discrete.cutVertices(g)]);
Checked output
[[[3, 4]], [3, 4]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Graphs with roughly 3–20 vertices and tens of edges; counting paths differs greatly from listing every path.
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.463 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.graph · 10 passing test cases, 21 distinct argument descriptions
A forest has 11 vertices and 3 components. How many edges does it have?
Worked solution
Each tree contributes one fewer edge than vertex.
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`11-3`));
Checked output
8
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. Graphs with roughly 3–20 vertices and tens of edges; counting paths differs greatly from listing every path.
Focal example. The code above passed its displayed check in 0.079 ms on Node.
Same arithmetic expression. Replaced its first numeral 11 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
Why can no edge of a simple cycle be a bridge in its graph?
Worked solution
The remaining arc of the cycle still connects the two endpoints after deletion.
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. Graphs with roughly 3–20 vertices and tens of edges; counting paths differs greatly from listing every path.
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 33 / 40 · Relations and representations
Equivalence relations
Direct calculation@ratmath/discrete
Problem
Is an equivalence relation on ? If so, give its classes.
Worked solution
Yes (reflexive, symmetric, transitive): classes and .
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.relation([1, 2, 3], [[1, 1], [2, 2], [3, 3], [1, 2], [2, 1]]).classes());
Checked output
[[1, 2], [3]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small finite sets, relations and functions, or asymptotic families described symbolically by one size parameter.
Focal example. The code above passed its displayed check in 0.400 ms on Node.
Related workload in this unit.logic.countModels · Boolean atoms. Baseline test points across courses 1, 2, 4, 8. A disjunction of n distinct atoms is false in exactly one of its 2^n valuations.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 20 (21.16 ms, 97.1 MiB peak process RSS). Library refusal at 24. An n-atom truth table has 2ⁿ rows. This implementation guards tables above 22 atoms. SAT search has different resource costs.
Measured times, memory and outcomes
Boolean atoms · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.290
75.3
2
Baseline
Passed
0.268
74.6
4
Baseline
Passed
0.426
76.4
8
Baseline
Passed
0.371
75.4
12
Stretch
Passed
0.720
75.6
16
Stretch
Passed
2.33
78
19
Stretch
Passed
10.50
88.2
20
Stretch
Passed
21.16
97.1
24
Stretch
Library refusal · LogicError: a table over 24 atoms has 2^24 rows; use satisfiable() or valid() instead
0.440
75.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.
discrete.relation · 1 passing test case, 2 distinct argument descriptions
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 { BaseSystem, R } from "@ratmath/core";
console.log(R`2026`.toBase(BaseSystem.fromBase(2)));
Checked output
11111101010
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. Small finite sets, relations and functions, or asymptotic families described symbolically by one size parameter.
Focal example. The code above passed its displayed check in 0.280 ms on Node.
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.BaseSystem · 15 passing test cases, 16 distinct argument descriptions
Is the cube graph bipartite? Is the Petersen graph?
Worked solution
: yes, split by the parity of the number of 1s. Petersen: no, it has 5-cycles.
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.isBipartite(discrete.hypercube(3)), discrete.isBipartite(discrete.petersen())]
);
Checked output
[true, false]
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. Small finite sets, relations and functions, or asymptotic families described symbolically by one size parameter.
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.791 ms on Node.
Same API, measured input family.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. 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. 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.hypercube · 7 passing test cases, 2 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small finite sets, relations and functions, or asymptotic families described symbolically by one size parameter.
Focal example. The code above passed its displayed check in 0.284 ms on Node.
Related workload in this unit.logic.countModels · Boolean atoms. Baseline test points across courses 1, 2, 4, 8. A disjunction of n distinct atoms is false in exactly one of its 2^n valuations.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 20 (21.16 ms, 97.1 MiB peak process RSS). Library refusal at 24. An n-atom truth table has 2ⁿ rows. This implementation guards tables above 22 atoms. SAT search has different resource costs.
Measured times, memory and outcomes
Boolean atoms · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.290
75.3
2
Baseline
Passed
0.268
74.6
4
Baseline
Passed
0.426
76.4
8
Baseline
Passed
0.371
75.4
12
Stretch
Passed
0.720
75.6
16
Stretch
Passed
2.33
78
19
Stretch
Passed
10.50
88.2
20
Stretch
Passed
21.16
97.1
24
Stretch
Library refusal · LogicError: a table over 24 atoms has 2^24 rows; use satisfiable() or valid() instead
0.440
75.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.
discrete.masterTheorem · 1 passing test case, 5 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 structures from "@ratmath/structures";
const G = structures.cyclic(20);
console.log(G.elementOrder(G.element(8)));
Checked output
5
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small finite sets, relations and functions, or asymptotic families described symbolically by one size parameter.
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 1.20 ms on Node.
Same API, measured input family.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. 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. 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.
structures.cyclic · 31 passing test cases, 11 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. Small finite sets, relations and functions, or asymptotic families described symbolically by one size parameter.
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
In the divisibility order on positive integers, must 6 and 10 be comparable?
Worked solution
Neither divides the other. Antisymmetry and transitivity do not imply totality.
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. Small finite sets, relations and functions, or asymptotic families described symbolically by one size parameter.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 40 / 40 · Relations and representations
Function counting
Direct calculation@ratmath/core
Problem
How many functions from a three-element labelled set to a two-element set are there?
Worked solution
Each of three inputs independently selects one of two outputs.
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^3`));
Checked output
8
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. Small finite sets, relations and functions, or asymptotic families described symbolically by one size parameter.
Focal example. The code above passed its displayed check in 0.072 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