30 of 40 focal problems use RatMath for a calculation or a substantive step.
Direct calculation
27 · 67.5%
Assisted
3 · 7.5%
Worked by hand
10 · 25%
Using the packages
Automata and bounded simulations give immediate witnesses on small inputs. A terminating trace cannot establish universality, a pumping argument or an asymptotic bound.
Calculator interface
Provide a state-diagram editor, a synchronized tape or stack trace and a product-automaton view that can display a distinguishing word. Mark the step limit on simulations.
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
30 of 40 days include a checked executable example. On 12 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 · Finite automata. Two to ten states and one to three alphabet symbols; a determinized NFA can require exponentially more states.
Unit benchmark · logic.regexToNFA / logic.toDFA, literal word length. Largest passing sample 128 (5.46 ms, 78.5 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 9–16 · Grammars and language families. A small grammar or PDA and words usually of length 0–20; ambiguity, branching and ε-productions affect parsing.
Unit benchmark · logic.regexToNFA / logic.toDFA, literal word length. Largest passing sample 128 (5.46 ms, 78.5 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 17–24 · Machines and computability. Turing machines with a handful of states, short inputs and an explicit simulation budget. A finite trace cannot establish nontermination.
Unit benchmark · logic.binaryIncrement.run, input bits. Largest passing sample 2,048 (21.81 ms, 75.1 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 25–32 · Complexity and reductions. Circuits with a few to tens of gates, or symbolic recurrences over an unbounded size n; proof is required for general complexity claims.
Unit benchmark · logic.countModels, Boolean atoms. Largest passing sample 20 (21.16 ms, 97.1 MiB peak process RSS). Library refusal at 24.
Days 33–40 · Counting and verification. Small automata and short words for explicit checking; the number of words grows exponentially with word length.
Unit benchmark · logic.binaryIncrement.run, input bits. Largest passing sample 2,048 (21.81 ms, 75.1 MiB peak process RSS). The runs did not locate a ceiling for this family.
Accuracy notes (1)
Fixed · The 20-atom model count passes. The disjunction of 20 distinct atoms has 2²⁰−1 = 1048575 satisfying assignments. Both runtimes now return that count. Logic also removed the extra bit required by its earlier intermediate mask.
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to ten states and one to three alphabet symbols; a determinized NFA can require exponentially more states.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.395 ms on Node.
Related workload in this unit.logic.regexToNFA / logic.toDFA · literal word length. Baseline test points across courses 1, 2, 4, 8. A recognizer for a literal word accepts that word and rejects the shorter and longer neighbours.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 128 (5.46 ms, 78.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Determinization may require up to 2ⁿ subsets of n NFA states. Literal words are a favorable family without that branching.
Measured times, memory and outcomes
literal word length · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.700
74.6
2
Baseline
Passed
0.847
75.5
4
Baseline
Passed
1.000
75.6
8
Baseline
Passed
1.11
75
16
Stretch
Passed
7.06
75.8
32
Stretch
Passed
4.56
75.7
64
Stretch
Passed
2.32
76.7
128
Stretch
Passed
5.46
78.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.
logic.automaton · 1 passing test case, 1 distinct argument description
How many states does the minimal DFA for binary words ending in 01 have?
Worked solution
It must remember whether the word ends in nothing useful, in 0, or in 01: three states, which are pairwise distinguishable (by the suffixes 01, 1, 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 logic from "@ratmath/logic";
console.log(logic.minimizeAutomaton(logic.toDFA(logic.regexToNFA("(0|1)*01"))).states.length);
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. Two to ten states and one to three alphabet symbols; a determinized NFA can require exponentially more states.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 1.30 ms on Node.
Same API, measured input family.logic.minimizeAutomaton · literal word length. Baseline test points across courses 1, 2, 4, 8. Minimizing a DFA for a singleton word preserves acceptance of the word and rejects every strict prefix and its one-letter extension.
Practical limit. Largest passing sample 64 (4.99 ms, 82.1 MiB peak process RSS). The runs did not locate a ceiling for this family. The determinized automaton may already be large before minimization starts. Count reachable states and verify acceptance at boundary words.
Measured times, memory and outcomes
literal word length · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.793
75.8
2
Baseline
Passed
0.654
75.4
4
Baseline
Passed
0.509
74.8
8
Baseline
Passed
0.917
75.3
16
Stretch
Passed
1.55
76.1
32
Stretch
Passed
6.95
76.8
64
Stretch
Passed
4.99
82.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.
logic.minimizeAutomaton · 1 passing test case, 1 distinct argument description
Convert to a DFA and minimise it. How many states? Does it accept and ?
Worked solution
The minimal DFA tracks the longest suffix that is a prefix of : : 4 states. ends in : yes; : 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 logic from "@ratmath/logic";
const D = logic.minimizeAutomaton(logic.toDFA(logic.regexToNFA("(a|b)*abb")));
console.log([D.states.length, D.accepts("aababb"), D.accepts("abab")]);
Checked output
[4, 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. Two to ten states and one to three alphabet symbols; a determinized NFA can require exponentially more states.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.523 ms on Node.
Same API, measured input family.logic.minimizeAutomaton · literal word length. Baseline test points across courses 1, 2, 4, 8. Minimizing a DFA for a singleton word preserves acceptance of the word and rejects every strict prefix and its one-letter extension.
Practical limit. Largest passing sample 64 (4.99 ms, 82.1 MiB peak process RSS). The runs did not locate a ceiling for this family. The determinized automaton may already be large before minimization starts. Count reachable states and verify acceptance at boundary words.
Measured times, memory and outcomes
literal word length · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.793
75.8
2
Baseline
Passed
0.654
75.4
4
Baseline
Passed
0.509
74.8
8
Baseline
Passed
0.917
75.3
16
Stretch
Passed
1.55
76.1
32
Stretch
Passed
6.95
76.8
64
Stretch
Passed
4.99
82.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.
logic.minimizeAutomaton · 1 passing test case, 1 distinct argument description
Yes: both denote all words over (every letter is an block).
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.equivalentAutomata(logic.regexToNFA("(a|b)*"), logic.regexToNFA("(a*b*)*")).equivalent
);
Checked output
true
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to ten states and one to three alphabet symbols; a determinized NFA can require exponentially more states.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.440 ms on Node.
Related workload in this unit.logic.regexToNFA / logic.toDFA · literal word length. Baseline test points across courses 1, 2, 4, 8. A recognizer for a literal word accepts that word and rejects the shorter and longer neighbours.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 128 (5.46 ms, 78.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Determinization may require up to 2ⁿ subsets of n NFA states. Literal words are a favorable family without that branching.
Measured times, memory and outcomes
literal word length · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.700
74.6
2
Baseline
Passed
0.847
75.5
4
Baseline
Passed
1.000
75.6
8
Baseline
Passed
1.11
75
16
Stretch
Passed
7.06
75.8
32
Stretch
Passed
4.56
75.7
64
Stretch
Passed
2.32
76.7
128
Stretch
Passed
5.46
78.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.
logic.equivalentAutomata · 2 passing test cases, 3 distinct argument descriptions
Build an automaton for words over with an even number of s and an odd number of s. Test and .
Worked solution
Pair the two 2-state parity automata: 4 states, accepting (even, odd). : 2 s, 1 : yes. : 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 logic from "@ratmath/logic";
const par = (letter, acc) => logic.automaton({ states: ["e", "o"], alphabet: "ab", start: "e", accept: [acc],
delta: { e: { a: letter === "a" ? "o" : "e", b: letter === "b" ? "o" : "e" }, o: { a: letter === "a" ? "e" : "o", b: letter === "b" ? "e" : "o" } } });
const P = logic.product(par("a", "e"), par("b", "o"));
console.log([P.states.length, P.accepts("aab"), P.accepts("ab")]);
Checked output
[4, 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. Two to ten states and one to three alphabet symbols; a determinized NFA can require exponentially more states.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.392 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.
logic.automaton · 1 passing test case, 1 distinct argument description
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to ten states and one to three alphabet symbols; a determinized NFA can require exponentially more states.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.889 ms on Node.
Related workload in this unit.logic.regexToNFA / logic.toDFA · literal word length. Baseline test points across courses 1, 2, 4, 8. A recognizer for a literal word accepts that word and rejects the shorter and longer neighbours.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 128 (5.46 ms, 78.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Determinization may require up to 2ⁿ subsets of n NFA states. Literal words are a favorable family without that branching.
Measured times, memory and outcomes
literal word length · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.700
74.6
2
Baseline
Passed
0.847
75.5
4
Baseline
Passed
1.000
75.6
8
Baseline
Passed
1.11
75
16
Stretch
Passed
7.06
75.8
32
Stretch
Passed
4.56
75.7
64
Stretch
Passed
2.32
76.7
128
Stretch
Passed
5.46
78.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.
logic.automaton · 1 passing test case, 1 distinct argument description
How should a DFA handle an unspecified transition before complementation?
Worked solution
Complete the transition table with a rejecting sink for missing edges. Swapping final and nonfinal states then complements the language over the specified alphabet.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Two to ten states and one to three alphabet symbols; a determinized NFA can require exponentially more states.
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 · Finite automata
Closure under reversal
Worked by hand
Problem
How can an NFA for the reversal of a regular language be constructed?
Worked solution
Reverse every edge, make the old start accepting and use a fresh start with ε-edges to all old accepting states.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Two to ten states and one to three alphabet symbols; a determinized NFA can require exponentially more states.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 09 / 40 · Grammars and language families
Context-free grammars
Direct calculation@ratmath/logic
Problem
Give a grammar for . Does it generate ? ? List its words of length at most 6.
Worked solution
. : yes; : no. Words: .
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";
const g = logic.grammar("S -> a S b | ε");
console.log([g.accepts("aabb"), g.accepts("aab"), g.words(6).words]);
Checked output
[true, false, ["", "ab", "aabb", "aaabbb"]]
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 small grammar or PDA and words usually of length 0–20; ambiguity, branching and ε-productions affect parsing.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 1.65 ms on Node.
Related workload in this unit.logic.regexToNFA / logic.toDFA · literal word length. Baseline test points across courses 1, 2, 4, 8. A recognizer for a literal word accepts that word and rejects the shorter and longer neighbours.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 128 (5.46 ms, 78.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Determinization may require up to 2ⁿ subsets of n NFA states. Literal words are a favorable family without that branching.
Measured times, memory and outcomes
literal word length · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.700
74.6
2
Baseline
Passed
0.847
75.5
4
Baseline
Passed
1.000
75.6
8
Baseline
Passed
1.11
75
16
Stretch
Passed
7.06
75.8
32
Stretch
Passed
4.56
75.7
64
Stretch
Passed
2.32
76.7
128
Stretch
Passed
5.46
78.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.
logic.grammar · 5 passing test cases, 4 distinct argument descriptions
New start ; remove : ; terminals , ; split: , , 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 logic from "@ratmath/logic";
console.log(String(logic.grammar("S -> a S b | ε").toCNF()));
Checked output
S → T0 X0 | T0 T1
X0 → S T1
S0 → ε | T0 X0 | T0 T1
T0 → a
T1 → b
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 small grammar or PDA and words usually of length 0–20; ambiguity, branching and ε-productions affect parsing.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.294 ms on Node.
Related workload in this unit.logic.regexToNFA / logic.toDFA · literal word length. Baseline test points across courses 1, 2, 4, 8. A recognizer for a literal word accepts that word and rejects the shorter and longer neighbours.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 128 (5.46 ms, 78.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Determinization may require up to 2ⁿ subsets of n NFA states. Literal words are a favorable family without that branching.
Measured times, memory and outcomes
literal word length · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.700
74.6
2
Baseline
Passed
0.847
75.5
4
Baseline
Passed
1.000
75.6
8
Baseline
Passed
1.11
75
16
Stretch
Passed
7.06
75.8
32
Stretch
Passed
4.56
75.7
64
Stretch
Passed
2.32
76.7
128
Stretch
Passed
5.46
78.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.
logic.grammar · 5 passing test cases, 4 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. A small grammar or PDA and words usually of length 0–20; ambiguity, branching and ε-productions affect parsing.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.343 ms on Node.
Same API, measured input family.logic.pda · balanced block length. Baseline test points across courses 0, 1, 2, 5, 10. The PDA accepts aⁿbⁿ (including ε) and rejects aⁿbⁿ⁺¹.
Practical limit. Largest passing sample 500 (8.81 ms, 76.7 MiB peak process RSS). The runs did not locate a ceiling for this family. The sample PDA is nearly deterministic. Epsilon moves and a branching stack can generate many more configurations for words of the same length.
Measured times, memory and outcomes
balanced block length · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
0.143
74.8
1
Baseline
Passed
0.196
75.5
2
Baseline
Passed
0.225
75.9
5
Baseline
Passed
0.229
75.3
10
Baseline
Passed
0.252
75.7
25
Stretch
Passed
0.365
74.8
100
Stretch
Passed
2.34
75.3
500
Stretch
Passed
8.81
76.7
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.
Day 12 / 40 · Grammars and language families
Pumping lemma
Assisted@ratmath/logic
Problem
Prove that is not regular.
Worked solution
If it were, with pumping length , write with , . Then , and is not in the language. Contradiction.
Using RatMath
These bounded languages illustrate increasing state counts. Use the pumping argument to handle every possible pumping length.
JavaScript module
import * as logic from "@ratmath/logic";
// No proof tool: a finite check only. The minimal DFA for words a^n b^n with n ≤ N needs more states as N grows.
console.log(
[2, 4, 6].map((N) => logic.minimizeAutomaton(logic.toDFA(logic.regexToNFA(Array.from({ length: N + 1 }, (_, n) => "a".repeat(n) + "b".repeat(n) || "ε").join("|")))).states.length)
);
Checked output
[6, 10, 14]
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 small grammar or PDA and words usually of length 0–20; ambiguity, branching and ε-productions affect parsing.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 2.13 ms on Node.
Same API, measured input family.logic.minimizeAutomaton · literal word length. Baseline test points across courses 1, 2, 4, 8. Minimizing a DFA for a singleton word preserves acceptance of the word and rejects every strict prefix and its one-letter extension.
Practical limit. Largest passing sample 64 (4.99 ms, 82.1 MiB peak process RSS). The runs did not locate a ceiling for this family. The determinized automaton may already be large before minimization starts. Count reachable states and verify acceptance at boundary words.
Measured times, memory and outcomes
literal word length · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.793
75.8
2
Baseline
Passed
0.654
75.4
4
Baseline
Passed
0.509
74.8
8
Baseline
Passed
0.917
75.3
16
Stretch
Passed
1.55
76.1
32
Stretch
Passed
6.95
76.8
64
Stretch
Passed
4.99
82.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.
logic.minimizeAutomaton · 1 passing test case, 1 distinct argument description
Split after the first or second operand, producing a+(a+a) or (a+a)+a. These are different parse trees for the same string.
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. A small grammar or PDA and words usually of length 0–20; ambiguity, branching and ε-productions affect parsing.
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 14 / 40 · Grammars and language families
Stack invariant
Worked by hand
Problem
Why can a single stack recognize properly nested parentheses?
Worked solution
Push for each open and pop for each close. Reject a pop on empty and accept at end only when the stack is empty.
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. A small grammar or PDA and words usually of length 0–20; ambiguity, branching and ε-productions affect parsing.
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 15 / 40 · Grammars and language families
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 small grammar or PDA and words usually of length 0–20; ambiguity, branching and ε-productions affect parsing.
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
Are context-free languages closed under intersection with regular languages?
Worked solution
Combine a pushdown automaton with a finite automaton in a product state. The pushdown stack remains the only stack, and both component acceptance conditions must hold.
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. A small grammar or PDA and words usually of length 0–20; ambiguity, branching and ε-productions affect parsing.
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 · Machines and computability
Turing machines
Direct calculation@ratmath/logic
Problem
Run a Turing machine that adds one to a binary number on the input 1011.
Worked solution
Move to the right end, turn trailing 1s into 0s moving left, then turn the first 0 into 1: .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as logic from "@ratmath/logic";
const r = logic.binaryIncrement().run("1011");
console.log([r.status, r.tape]);
Checked output
["accepted", "1100"]
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. Turing machines with a handful of states, short inputs and an explicit simulation budget. A finite trace cannot establish nontermination.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.220 ms on Node.
Same API, measured input family.logic.binaryIncrement.run · input bits. Baseline test points across courses 1, 2, 4, 8. Incrementing a string of n ones gives 1 followed by n zeroes.
Practical limit. Largest passing sample 2,048 (21.81 ms, 75.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Simulation cost depends on executed transitions and tape use. Reaching a step budget establishes an incomplete trace only.
Measured times, memory and outcomes
input bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.248
75.8
2
Baseline
Passed
0.141
74.4
4
Baseline
Passed
0.141
76
8
Baseline
Passed
0.149
74.7
32
Stretch
Passed
0.201
74.9
128
Stretch
Passed
0.349
75.1
512
Stretch
Passed
1.56
75.1
2,048
Stretch
Passed
21.81
75.1
Each row measures the stated fixture. 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.binaryIncrement · 1 passing test case, 1 distinct argument description
Using only primitive recursive building blocks, compute , and .
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 logic from "@ratmath/logic";
const { add, power, factorial } = logic.recursive.examples;
console.log([add.at(3, 4), power.at(2, 10), factorial.at(7)]);
Checked output
[7n, 1024n, 5040n]
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. Turing machines with a handful of states, short inputs and an explicit simulation budget. A finite trace cannot establish nontermination.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 68.14 ms on Node.
Same API, measured input family.logic.recursive.examples.factorial.at · natural-number argument. Baseline test points across courses 0, 1, 4, 7. Compare primitive-recursive factorial with the integer product 1⋯n.
Practical limit. Largest passing sample 7 (28.86 ms, 88 MiB peak process RSS). Time cutoff at 12, 20, 50, 100. A definition by primitive recursion can be much slower than direct integer multiplication. Track recursion depth or the evaluator’s budget.
Measured times, memory and outcomes
natural-number argument · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
0.125
74.5
1
Baseline
Passed
0.148
75.1
4
Baseline
Passed
0.249
74.6
7
Baseline
Passed
28.86
88
12
Stretch
Time cutoff
—
89.4
20
Stretch
Time cutoff
—
88.4
50
Stretch
Time cutoff
—
88.1
100
Stretch
Time cutoff
—
88.9
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.
Day 19 / 40 · Machines and computability
Composition of recursive functions
Direct calculation@ratmath/logic
Problem
Define by composing addition with projections, and evaluate .
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 logic from "@ratmath/logic";
const { compose, proj, examples } = logic.recursive;
console.log(compose(examples.add, [proj(1, 1), proj(1, 1)]).at(21));
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. Turing machines with a handful of states, short inputs and an explicit simulation budget. A finite trace cannot establish nontermination.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.111 ms on Node.
Same API, measured input family.logic.recursive.compose · natural-number input. Baseline test points across courses 0, 1, 5, 21. Compose addition with two identical projections; the result must equal 2n.
Practical limit. Largest passing sample 1,000 (1.33 ms, 75.4 MiB peak process RSS). The runs did not locate a ceiling for this family. Doubling has a simple answer, though recursive evaluation depends on depth and on the chosen building blocks.
Measured times, memory and outcomes
natural-number input · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
0.092
74.7
1
Baseline
Passed
0.108
74.8
5
Baseline
Passed
0.114
76.3
21
Baseline
Passed
0.918
75.4
100
Stretch
Passed
0.255
75.1
500
Stretch
Passed
5.16
75.1
1,000
Stretch
Passed
1.33
75.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.
Day 20 / 40 · Machines and computability
Minimisation
Direct calculation@ratmath/logic
Problem
Use the operator to compute the integer square root of 30: the least with .
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 logic from "@ratmath/logic";
const { mu } = logic.recursive;
// mu(f) finds the least y with f(y, x) = 0 (the searched argument comes first); here f = 0 exactly when (y + 1)^2 > x
const f = { arity: 2, name: "gt", at: (y, x) => ((y + 1n) * (y + 1n) > x ? 0n : 1n) };
console.log(mu(f).at(30));
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. Turing machines with a handful of states, short inputs and an explicit simulation budget. A finite trace cannot establish nontermination.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.220 ms on Node.
Same API, measured input family.logic.recursive.mu · nonnegative radicand. Baseline test points across courses 0, 1, 9, 30. Unbounded minimization with the predicate (y+1)²>n computes floor(√n). Check adjacent integer squares.
Practical limit. Largest passing sample 1,000,000 (0.488 ms, 74.2 MiB peak process RSS). The runs did not locate a ceiling for this family. This test has a witness within the square root of the input. For an arbitrary partial recursive predicate there may be no witness at all.
Measured times, memory and outcomes
nonnegative radicand · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
0.068
74.7
1
Baseline
Passed
0.058
74.1
9
Baseline
Passed
0.058
74.7
30
Baseline
Passed
0.062
75.3
100
Stretch
Passed
0.066
74.8
10,000
Stretch
Passed
0.078
74.8
1,000,000
Stretch
Passed
0.488
74.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.
Day 21 / 40 · Machines and computability
The halting problem
Assisted@ratmath/logic
Problem
Is there an algorithm that decides, for every program and input, whether the program halts?
Worked solution
No (Turing). If decided halting, the program that runs on its own code and does the opposite would halt exactly when it does not.
Using RatMath
A budget of 1000 steps gives a finite trace. The diagonal contradiction in the solution establishes undecidability.
JavaScript module
import * as logic from "@ratmath/logic";
// A run with a budget can only report "running" for a machine that has not stopped yet.
const loop = logic.turing({ start: "s", accept: "y", reject: "n", delta: { "s,_": ["s", "_", "R"] } });
console.log(loop.run("", { budget: 1000 }).status);
Checked output
running
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. Turing machines with a handful of states, short inputs and an explicit simulation budget. A finite trace cannot establish nontermination.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.618 ms on Node.
Related workload in this unit.logic.binaryIncrement.run · input bits. Baseline test points across courses 1, 2, 4, 8. Incrementing a string of n ones gives 1 followed by n zeroes.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 2,048 (21.81 ms, 75.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Simulation cost depends on executed transitions and tape use. Reaching a step budget establishes an incomplete trace only.
Measured times, memory and outcomes
input bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.248
75.8
2
Baseline
Passed
0.141
74.4
4
Baseline
Passed
0.141
76
8
Baseline
Passed
0.149
74.7
32
Stretch
Passed
0.201
74.9
128
Stretch
Passed
0.349
75.1
512
Stretch
Passed
1.56
75.1
2,048
Stretch
Passed
21.81
75.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
logic.turing · 1 passing test case, 1 distinct argument description
The four clauses rule out each of the four assignments to : unsatisfiable.
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.
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. Turing machines with a handful of states, short inputs and an explicit simulation budget. A finite trace cannot establish nontermination.
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.397 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.satisfiable · 4 passing test cases, 7 distinct argument descriptions
What may a recognizer do on a nonmember that a decider may not?
Worked solution
A recognizer may loop forever on a nonmember. A decider must halt on every input.
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. Turing machines with a handful of states, short inputs and an explicit simulation budget. A finite trace cannot establish nontermination.
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 · Machines and computability
Diagonal language
Worked by hand
Problem
Why cannot a total halting tester be used consistently in the usual self-reference program?
Worked solution
Define D(x) to loop when the tester predicts x(x) halts and halt otherwise. Both predictions for D(D) contradict its actual behavior.
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. Turing machines with a handful of states, short inputs and an explicit simulation budget. A finite trace cannot establish nontermination.
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 · Complexity and reductions
Circuits
Direct calculation@ratmath/logic
Problem
A full adder adds bits and a carry . What are the sum and carry for ?
Worked solution
: sum 1, carry 1.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as logic from "@ratmath/logic";
console.log(logic.adders.full().evaluate({ a: 1, b: 1, cin: 1 }));
Checked output
{ sum: 1, cout: 1 }
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Circuits with a few to tens of gates, or symbolic recurrences over an unbounded size n; proof is required for general complexity claims.
Focal example. The code above passed its displayed check in 0.449 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.adders.full · 1 passing test case, 1 distinct argument description
A four-bit ripple adder has no carry input. It uses one half adder (XOR, AND) and three five-gate full adders. Count the gates and the longest input-to-output gate depth.
Worked solution
There are 2+3×5=17 gates. The half adder produces its carry at depth 1. Each further carry adds an AND and an OR along the critical path, giving depth 1+2×3=7.
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";
const c = logic.adders.ripple(4);
console.log([c.size, c.depth]);
Checked output
[17, 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. Circuits with a few to tens of gates, or symbolic recurrences over an unbounded size n; proof is required for general complexity claims.
Focal example. The code above passed its displayed check in 0.487 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.adders.ripple · 1 passing test case, 1 distinct argument description
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. Circuits with a few to tens of gates, or symbolic recurrences over an unbounded size n; proof is required for general complexity claims.
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
Try : then (clause 2), so (clause 3); clause 1 holds by , clause 4 by . Satisfiable with .
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";
const r = logic.satisfiable("(x1 | x2) & (~x1 | x3) & (~x2 | ~x3) & (x1 | ~x3)");
console.log([r.status, r.model ?? r.assignment]);
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. Circuits with a few to tens of gates, or symbolic recurrences over an unbounded size n; proof is required for general complexity claims.
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.289 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.satisfiable · 4 passing test cases, 7 distinct argument descriptions
Add . Resolve with on : . Resolve with : the empty clause.
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";
const r = logic.entails("p | q, ~p | q", "q");
console.log(
[r.status, logic.checkResolution(r.refutation).ok ?? logic.checkResolution(r.refutation).status]
);
Checked output
["valid", true]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Circuits with a few to tens of gates, or symbolic recurrences over an unbounded size n; proof is required for general complexity claims.
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.235 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
logic.checkResolution · 2 passing test cases, 9 distinct argument descriptions
"1. p | q premise\n2. ~p | q premise\n3. ~q … (106 chars)", {premises=["p | q", "~p | q", "~q"] (n=3)} or "1. p | q premise\n2. ~p | q premise\n3. ~q … (106 chars)", {premises=["p | q", "~q"] (n=2)} · a proof written by hand is checked line by line
"p | q premise\n~p premise\nq | r res 1, 2" or "p | q\nr\nq res 1, 2" · what is wrong is named
Day 30 / 40 · Complexity and reductions
Counting models
Direct calculation@ratmath/logic
Problem
How many of the 8 valuations of satisfy ?
Worked solution
All but the all-false one: 7.
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.countModels("p | q | r", ["p", "q", "r"]));
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. Circuits with a few to tens of gates, or symbolic recurrences over an unbounded size n; proof is required for general complexity claims.
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.402 ms on Node.
Same API, measured input family.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. 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. 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.countModels · 1 passing test case, 2 distinct argument descriptions
Implementation limit. A displayed truth table is capped at 16 atoms. Packed bit-table operations have a 22-atom library limit and can hit an engine limit sooner. Source at the tested revision
Accuracy notes (1)
Fixed · The 20-atom model count passes. The disjunction of 20 distinct atoms has 2²⁰−1 = 1048575 satisfying assignments. Both runtimes now return that count. Logic also removed the extra bit required by its earlier intermediate mask.
Day 31 / 40 · Complexity and reductions
Encoding length
Worked by hand
Problem
For a positive integer written in binary, why is a loop of n iterations potentially exponential?
Worked solution
Inputs with b bits can be as large as 2ᵇ−1. Running time must be measured in bits of input.
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. Circuits with a few to tens of gates, or symbolic recurrences over an unbounded size n; proof is required for general complexity claims.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 32 / 40 · Complexity and reductions
Reduction direction
Worked by hand
Problem
To show B is NP-hard starting with known NP-hard A, which way must a polynomial reduction run?
Worked solution
Map instances of A to instances of B preserving yes and no. A solver for B would then solve A.
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. Circuits with a few to tens of gates, or symbolic recurrences over an unbounded size n; proof is required for general complexity claims.
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 · Counting and verification
Counting accepted words
Direct calculation@ratmath/logic
Problem
How many binary words of length 4 have an even number of 1s?
Worked solution
Half of the 16: .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small automata and short words for explicit checking; the number of words grows exponentially with word length.
For this problem type. Use a handful of states or rules, an alphabet of 1–3 symbols and words commonly of length 0–20. State a step budget for search or simulation.
Focal example. The code above passed its displayed check in 0.364 ms on Node.
Related workload in this unit.logic.regexToNFA / logic.toDFA · literal word length. Baseline test points across courses 1, 2, 4, 8. A recognizer for a literal word accepts that word and rejects the shorter and longer neighbours.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 128 (5.46 ms, 78.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Determinization may require up to 2ⁿ subsets of n NFA states. Literal words are a favorable family without that branching.
Measured times, memory and outcomes
literal word length · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.700
74.6
2
Baseline
Passed
0.847
75.5
4
Baseline
Passed
1.000
75.6
8
Baseline
Passed
1.11
75
16
Stretch
Passed
7.06
75.8
32
Stretch
Passed
4.56
75.7
64
Stretch
Passed
2.32
76.7
128
Stretch
Passed
5.46
78.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.
logic.automaton · 1 passing test case, 1 distinct argument description
How many closed walks of length 3 start and end at a given vertex of ? How many walks of length 3 join two different vertices?
Worked solution
With and : . So (the ordered triangles through ) 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";
const W = discrete.walks(discrete.complete(4), 3).matrix;
console.log([W[0][0], W[0][1]]);
Checked output
[6n, 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. Small automata and short words for explicit checking; the number of words grows exponentially with word length.
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.357 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.walks · 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.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. Small automata and short words for explicit checking; the number of words grows exponentially with word length.
Focal example. The code above passed its displayed check in 2.10 ms on Node.
Related workload in this unit.logic.binaryIncrement.run · input bits. Baseline test points across courses 1, 2, 4, 8. Incrementing a string of n ones gives 1 followed by n zeroes.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 2,048 (21.81 ms, 75.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Simulation cost depends on executed transitions and tape use. Reaching a step budget establishes an incomplete trace only.
Measured times, memory and outcomes
input bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.248
75.8
2
Baseline
Passed
0.141
74.4
4
Baseline
Passed
0.141
76
8
Baseline
Passed
0.149
74.7
32
Stretch
Passed
0.201
74.9
128
Stretch
Passed
0.349
75.1
512
Stretch
Passed
1.56
75.1
2,048
Stretch
Passed
21.81
75.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.recurrence · 2 passing test cases, 5 distinct argument descriptions
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. Small automata and short words for explicit checking; the number of words grows exponentially with word length.
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
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. Small automata and short words for explicit checking; the number of words grows exponentially with word length.
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
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. Small automata and short words for explicit checking; the number of words grows exponentially with word length.
Focal example. The code above passed its displayed check in 0.179 ms on Node.
Related workload in this unit.logic.binaryIncrement.run · input bits. Baseline test points across courses 1, 2, 4, 8. Incrementing a string of n ones gives 1 followed by n zeroes.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 2,048 (21.81 ms, 75.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Simulation cost depends on executed transitions and tape use. Reaching a step budget establishes an incomplete trace only.
Measured times, memory and outcomes
input bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.248
75.8
2
Baseline
Passed
0.141
74.4
4
Baseline
Passed
0.141
76
8
Baseline
Passed
0.149
74.7
32
Stretch
Passed
0.201
74.9
128
Stretch
Passed
0.349
75.1
512
Stretch
Passed
1.56
75.1
2,048
Stretch
Passed
21.81
75.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.pigeonhole · 1 passing test case, 3 distinct argument descriptions
What certificate demonstrates a Hamiltonian cycle in a simple graph with at least three vertices?
Worked solution
Give a permutation of the vertices. Check distinctness, every consecutive edge and the closing edge in polynomial time.
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 automata and short words for explicit checking; the number of words grows exponentially with word length.
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 · Counting and verification
Powerset growth
Direct calculation@ratmath/core
Problem
What is the standard upper bound on DFA states obtained from an NFA with 12 states?
Worked solution
Each DFA state represents a subset of the 12 states. The bound includes the empty subset.
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^12`));
Checked output
4096
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 automata and short words for explicit checking; the number of words grows exponentially with word length.
Focal example. The code above passed its displayed check in 0.150 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