32 of 40 focal problems use RatMath for a calculation or a substantive step.
Direct calculation
26 · 65%
Assisted
6 · 15%
Worked by hand
8 · 20%
Using the packages
Exact linear programs and small combinatorial models make certificates and shadow prices concrete. Local derivatives need domain checks, constraint qualifications and global reasoning before they establish an optimum.
Calculator interface
Provide a constraint editor with active constraints, feasible-set shading and explicit statuses for infeasible or unbounded models. Display primal and dual objectives and distinguish local candidates from certified global optima.
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
32 of 40 days include a checked executable example. On 13 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 · Linear modeling. About 2–5 variables and 2–10 constraints for teaching linear programs, with small rational or integer coefficients.
Unit benchmark · discrete.linearProgram, variables. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 9–16 · Discrete optimization. Roughly 2–10 binary decisions or a 2×2 to 8×8 assignment; feasibility, integrality and optimality are separate questions.
Unit benchmark · discrete.integerProgram, binary choices. Largest passing sample 32 (38.64 ms, 90.8 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 17–24 · Smooth unconstrained optimization. One or two real variables, simple polynomials and a few starting points; local stationary conditions need global checks.
Unit benchmark · analytic.gradientDescent, iterations. Largest passing sample 300 (7.03 ms, 81.6 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 25–32 · Constrained optimization. One or two active constraints and up to three continuous unknowns in hand calculations; check constraint qualifications.
Unit benchmark · discrete.linearProgram, variables. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 33–40 · Methods and sensitivity. Small least-squares matrices or about 1–50 numerical iterations; inspect scaling, gradient norm and feasibility as well as objective change.
Unit benchmark · analytic.gradientDescent, iterations. Largest passing sample 300 (7.03 ms, 81.6 MiB peak process RSS). The runs did not locate a ceiling for this family.
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. About 2–5 variables and 2–10 constraints for teaching linear programs, with small rational or integer coefficients.
For this problem type. Use 2–5 variables for a worked linear program or about 2–10 binary choices, a handful of constraints and small exact coefficients.
Focal example. The code above passed its displayed check in 0.263 ms on Node.
Same API, measured input family.discrete.linearProgram · variables. Baseline test points across courses 1, 2, 3, 5. Maximize Σxᵢ under xᵢ≤i+1 and x≥0. The positive objective saturates every coordinate.
Practical limit. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family. A bounded box gives an easy linear program. Constraint count, degeneracy and intermediate rational bit lengths affect pivot cost.
Measured times, memory and outcomes
variables · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.30
75.3
2
Baseline
Passed
1.28
75.1
3
Baseline
Passed
3.76
74
5
Baseline
Passed
1.98
75.1
10
Stretch
Passed
2.83
75.6
25
Stretch
Passed
3.71
75.6
50
Stretch
Passed
9.66
78.2
100
Stretch
Passed
57.90
84.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.linearProgram · 7 passing test cases, 14 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. About 2–5 variables and 2–10 constraints for teaching linear programs, with small rational or integer coefficients.
For this problem type. Use 2–5 variables for a worked linear program or about 2–10 binary choices, a handful of constraints and small exact coefficients.
Focal example. The code above passed its displayed check in 0.278 ms on Node.
Same API, measured input family.discrete.linearProgram · variables. Baseline test points across courses 1, 2, 3, 5. Maximize Σxᵢ under xᵢ≤i+1 and x≥0. The positive objective saturates every coordinate.
Practical limit. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family. A bounded box gives an easy linear program. Constraint count, degeneracy and intermediate rational bit lengths affect pivot cost.
Measured times, memory and outcomes
variables · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.30
75.3
2
Baseline
Passed
1.28
75.1
3
Baseline
Passed
3.76
74
5
Baseline
Passed
1.98
75.1
10
Stretch
Passed
2.83
75.6
25
Stretch
Passed
3.71
75.6
50
Stretch
Passed
9.66
78.2
100
Stretch
Passed
57.90
84.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.linearProgram · 7 passing test cases, 14 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. About 2–5 variables and 2–10 constraints for teaching linear programs, with small rational or integer coefficients.
For this problem type. Use 2–5 variables for a worked linear program or about 2–10 binary choices, a handful of constraints and small exact coefficients.
Focal example. The code above passed its displayed check in 0.152 ms on Node.
Same API, measured input family.discrete.linearProgram · variables. Baseline test points across courses 1, 2, 3, 5. Maximize Σxᵢ under xᵢ≤i+1 and x≥0. The positive objective saturates every coordinate.
Practical limit. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family. A bounded box gives an easy linear program. Constraint count, degeneracy and intermediate rational bit lengths affect pivot cost.
Measured times, memory and outcomes
variables · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.30
75.3
2
Baseline
Passed
1.28
75.1
3
Baseline
Passed
3.76
74
5
Baseline
Passed
1.98
75.1
10
Stretch
Passed
2.83
75.6
25
Stretch
Passed
3.71
75.6
50
Stretch
Passed
9.66
78.2
100
Stretch
Passed
57.90
84.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.linearProgram · 7 passing test cases, 14 distinct argument descriptions
Along every constraint holds and grows without bound.
Using RatMath
Supply a feasible ray, for example x=y=t with t≥0. Along it the objective grows as 2t, proving the solver status.
JavaScript module
import * as discrete from "@ratmath/discrete";
console.log(
discrete.linearProgram({ maximize: [1, 1], constraints: [[[1, -1], "<=", 1]] }).status
);
Checked output
unbounded
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. About 2–5 variables and 2–10 constraints for teaching linear programs, with small rational or integer coefficients.
For this problem type. Use 2–5 variables for a worked linear program or about 2–10 binary choices, a handful of constraints and small exact coefficients.
Focal example. The code above passed its displayed check in 0.147 ms on Node.
Same API, measured input family.discrete.linearProgram · variables. Baseline test points across courses 1, 2, 3, 5. Maximize Σxᵢ under xᵢ≤i+1 and x≥0. The positive objective saturates every coordinate.
Practical limit. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family. A bounded box gives an easy linear program. Constraint count, degeneracy and intermediate rational bit lengths affect pivot cost.
Measured times, memory and outcomes
variables · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.30
75.3
2
Baseline
Passed
1.28
75.1
3
Baseline
Passed
3.76
74
5
Baseline
Passed
1.98
75.1
10
Stretch
Passed
2.83
75.6
25
Stretch
Passed
3.71
75.6
50
Stretch
Passed
9.66
78.2
100
Stretch
Passed
57.90
84.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.linearProgram · 7 passing test cases, 14 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. About 2–5 variables and 2–10 constraints for teaching linear programs, with small rational or integer coefficients.
For this problem type. Use 2–5 variables for a worked linear program or about 2–10 binary choices, a handful of constraints and small exact coefficients.
Focal example. The code above passed its displayed check in 1.07 ms on Node.
Same API, measured input family.discrete.linearProgram · variables. Baseline test points across courses 1, 2, 3, 5. Maximize Σxᵢ under xᵢ≤i+1 and x≥0. The positive objective saturates every coordinate.
Practical limit. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family. A bounded box gives an easy linear program. Constraint count, degeneracy and intermediate rational bit lengths affect pivot cost.
Measured times, memory and outcomes
variables · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.30
75.3
2
Baseline
Passed
1.28
75.1
3
Baseline
Passed
3.76
74
5
Baseline
Passed
1.98
75.1
10
Stretch
Passed
2.83
75.6
25
Stretch
Passed
3.71
75.6
50
Stretch
Passed
9.66
78.2
100
Stretch
Passed
57.90
84.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.linearProgram · 7 passing test cases, 14 distinct argument descriptions
Write the dual of: maximise subject to , , ; show both optimal values agree.
Worked solution
Dual: minimise with , , . Primal optimum at is ; dual optimum at is .
Using RatMath
Transpose the constraint matrix, exchange objective and right-hand sides, and set the dual inequality directions. The two solver calls check the proposed dual on this instance.
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. About 2–5 variables and 2–10 constraints for teaching linear programs, with small rational or integer coefficients.
For this problem type. Use 2–5 variables for a worked linear program or about 2–10 binary choices, a handful of constraints and small exact coefficients.
Focal example. The code above passed its displayed check in 0.282 ms on Node.
Same API, measured input family.discrete.linearProgram · variables. Baseline test points across courses 1, 2, 3, 5. Maximize Σxᵢ under xᵢ≤i+1 and x≥0. The positive objective saturates every coordinate.
Practical limit. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family. A bounded box gives an easy linear program. Constraint count, degeneracy and intermediate rational bit lengths affect pivot cost.
Measured times, memory and outcomes
variables · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.30
75.3
2
Baseline
Passed
1.28
75.1
3
Baseline
Passed
3.76
74
5
Baseline
Passed
1.98
75.1
10
Stretch
Passed
2.83
75.6
25
Stretch
Passed
3.71
75.6
50
Stretch
Passed
9.66
78.2
100
Stretch
Passed
57.90
84.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.linearProgram · 7 passing test cases, 14 distinct argument descriptions
How is x−y≤4 written as an equality for a standard-form LP?
Worked solution
Add slack s≥0 to get x−y+s=4. The sign restrictions on x and y are separate modeling choices.
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. About 2–5 variables and 2–10 constraints for teaching linear programs, with small rational or integer coefficients.
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 · Linear modeling
Weak duality
Assisted@ratmath/core
Problem
A feasible maximization LP point has value 17 and a feasible dual point has value 20. What can be certified?
Worked solution
The optimum lies in [17,20] if an optimum exists. A gap of three remains between the two witnesses.
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`20-17`));
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. About 2–5 variables and 2–10 constraints for teaching linear programs, with small rational or integer coefficients.
Focal example. The code above passed its displayed check in 0.091 ms on Node.
Same arithmetic expression. Replaced its first numeral 20 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
Maximise subject to , , integers. Compare with the LP relaxation.
Worked solution
The relaxation peaks at with value 21. Among integer points, gives 20, 19, 18: the integer optimum is 20 at .
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 ip = discrete.integerProgram({ maximize: [5, 4], constraints: [[[6, 4], "<=", 24], [[1, 2], "<=", 6]] });
console.log([ip.value, ip.x, ip.relaxation.value]);
Checked output
[20, [4, 0], 21]
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. Roughly 2–10 binary decisions or a 2×2 to 8×8 assignment; feasibility, integrality and optimality are separate questions.
For this problem type. Use 2–5 variables for a worked linear program or about 2–10 binary choices, a handful of constraints and small exact coefficients.
Focal example. The code above passed its displayed check in 0.722 ms on Node.
Same API, measured input family.discrete.integerProgram · binary choices. Baseline test points across courses 2, 4, 6, 10. With equal unit weights and capacity n/2, the optimum takes the largest floor(n/2) profits.
Practical limit. Largest passing sample 32 (38.64 ms, 90.8 MiB peak process RSS). The runs did not locate a ceiling for this family. This fixture has an easy relaxation. Branch-and-bound can take exponentially many nodes on indivisible or tightly coupled choices.
Measured times, memory and outcomes
binary choices · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
2.06
75.6
4
Baseline
Passed
3.07
75.2
6
Baseline
Passed
4.17
75.4
10
Baseline
Passed
4.84
76.8
16
Stretch
Passed
13.44
81.5
24
Stretch
Passed
30.45
90.7
32
Stretch
Passed
38.64
90.8
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.integerProgram · 4 passing test cases, 4 distinct argument descriptions
Implementation limit. The default branch-and-bound budget is 20,000 subproblems. A difficult instance can exhaust it with few variables. Source at the tested revision
Day 10 / 40 · Discrete optimization
Knapsack
Direct calculation@ratmath/discrete
Problem
Items weigh 2, 3, 4, 5 and are worth 3, 4, 5, 6. Which should go in a knapsack holding weight 5?
Worked solution
The pairs within weight 5: only (weight 5, worth 7); single items are worth at most 6. Take items 1 and 2, worth 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 discrete from "@ratmath/discrete";
const ip = discrete.integerProgram({ maximize: [3, 4, 5, 6], constraints: [[[2, 3, 4, 5], "<=", 5]] }, { binary: true });
console.log([ip.value, ip.x]);
Checked output
[7, [1, 1, 0, 0]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Roughly 2–10 binary decisions or a 2×2 to 8×8 assignment; feasibility, integrality and optimality are separate questions.
For this problem type. Use 2–5 variables for a worked linear program or about 2–10 binary choices, a handful of constraints and small exact coefficients.
Focal example. The code above passed its displayed check in 0.271 ms on Node.
Same API, measured input family.discrete.integerProgram · binary choices. Baseline test points across courses 2, 4, 6, 10. With equal unit weights and capacity n/2, the optimum takes the largest floor(n/2) profits.
Practical limit. Largest passing sample 32 (38.64 ms, 90.8 MiB peak process RSS). The runs did not locate a ceiling for this family. This fixture has an easy relaxation. Branch-and-bound can take exponentially many nodes on indivisible or tightly coupled choices.
Measured times, memory and outcomes
binary choices · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
2.06
75.6
4
Baseline
Passed
3.07
75.2
6
Baseline
Passed
4.17
75.4
10
Baseline
Passed
4.84
76.8
16
Stretch
Passed
13.44
81.5
24
Stretch
Passed
30.45
90.7
32
Stretch
Passed
38.64
90.8
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.integerProgram · 4 passing test cases, 4 distinct argument descriptions
Implementation limit. The default branch-and-bound budget is 20,000 subproblems. A difficult instance can exhaust it with few variables. Source at the tested revision
Day 11 / 40 · Discrete optimization
Assignment problem
Direct calculation@ratmath/discrete
Problem
Assign four workers to four jobs at least total cost, with costs .
Worked solution
By the Hungarian method: worker 1 → job 2, 2 → 1, 3 → 3, 4 → 4, cost .
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 a = discrete.assignment([[9, 2, 7, 8], [6, 4, 3, 7], [5, 8, 1, 8], [7, 6, 9, 4]]);
console.log([a.cost, a.assignment]);
Checked output
[13, [1, 0, 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. Roughly 2–10 binary decisions or a 2×2 to 8×8 assignment; feasibility, integrality and optimality are separate questions.
For this problem type. Use about 2–8 agents on each side or 3–12 network vertices. Store costs, capacities and missing or forbidden edges explicitly.
Focal example. The code above passed its displayed check in 1.00 ms on Node.
Same API, measured input family.discrete.assignment · rows and columns. Baseline test points across courses 1, 2, 4, 8. Unit diagonal and strictly larger off-diagonal costs force the unique identity assignment, cost n.
Practical limit. Largest passing sample 16 (565 ms, 127.2 MiB peak process RSS). Time cutoff at 32, 64, 128. The first sampled passing call above 100 ms used 16 (565 ms). Materializing the cost table takes n² entries. Exact optimization can take much longer than evaluating the cost of a proposed assignment.
Measured times, memory and outcomes
rows and columns · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
2.62
74.8
2
Baseline
Passed
2.05
75.5
4
Baseline
Passed
10.52
77.3
8
Baseline
Passed
52.50
92.3
16
Stretch
Passed
565
127.2
32
Stretch
Time cutoff
—
271.4
64
Stretch
Time cutoff
—
315.2
128
Stretch
Time cutoff
—
333.5
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.assignment · 1 passing test case, 2 distinct argument descriptions
Two warehouses hold 20 and 30 units; three stores need 10, 25 and 15. Shipping costs per unit are . Find the cheapest plan's cost.
Worked solution
Warehouse 1 sends 20 to store 2; warehouse 2 sends 10, 5, 15. Cost (checked by the stepping-stone test: every unused route has nonnegative reduced cost).
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 t = discrete.transportation([20, 30], [10, 25, 15], [[8, 6, 10], [9, 12, 13]]);
console.log([t.cost, t.plan]);
Checked output
[465, [[0, 20, 0], [10, 5, 15]]]
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. Roughly 2–10 binary decisions or a 2×2 to 8×8 assignment; feasibility, integrality and optimality are separate questions.
For this problem type. Use about 2–8 agents on each side or 3–12 network vertices. Store costs, capacities and missing or forbidden edges explicitly.
Focal example. The code above passed its displayed check in 0.606 ms on Node.
Related workload in this unit.discrete.linearProgram · variables. Baseline test points across courses 1, 2, 3, 5. Maximize Σxᵢ under xᵢ≤i+1 and x≥0. The positive objective saturates every coordinate.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 100 (57.90 ms, 84.5 MiB peak process RSS). The runs did not locate a ceiling for this family. A bounded box gives an easy linear program. Constraint count, degeneracy and intermediate rational bit lengths affect pivot cost.
Measured times, memory and outcomes
variables · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.30
75.3
2
Baseline
Passed
1.28
75.1
3
Baseline
Passed
3.76
74
5
Baseline
Passed
1.98
75.1
10
Stretch
Passed
2.83
75.6
25
Stretch
Passed
3.71
75.6
50
Stretch
Passed
9.66
78.2
100
Stretch
Passed
57.90
84.5
Each row measures the stated fixture. 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.transportation · 3 passing test cases, 4 distinct argument descriptions
In the network (3), (2), (1), (2), (3), find the maximum flow from to .
Worked solution
The cut has capacity . Flow: 2, 1, 2: total 5. Max flow min cut .
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as discrete from "@ratmath/discrete";
const g = discrete.digraph([["s", "a", 3], ["s", "b", 2], ["a", "b", 1], ["a", "t", 2], ["b", "t", 3]]);
console.log(String(discrete.maxFlow(g, "s", "t").value));
Checked output
5
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Roughly 2–10 binary decisions or a 2×2 to 8×8 assignment; feasibility, integrality and optimality are separate questions.
For this problem type. Use about 2–8 agents on each side or 3–12 network vertices. Store costs, capacities and missing or forbidden edges explicitly.
Focal example. The code above passed its displayed check in 0.465 ms on Node.
Related workload in this unit.discrete.maximumMatching · vertices per side. Baseline test points across courses 1, 2, 5, 10. K_(n,n) has a diagonal perfect matching of size n.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 100 (102 ms, 125.5 MiB peak process RSS). The first sampled passing call above 100 ms used 100 (102 ms). The runs did not locate a ceiling for this family. Complete bipartite input has n² edges. Verifying a matching uses its vertices and edges. More general optimization objectives need their own check.
Measured times, memory and outcomes
vertices per side · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.869
75.2
2
Baseline
Passed
0.511
74.2
5
Baseline
Passed
0.783
76.1
10
Baseline
Passed
1.21
75
25
Stretch
Passed
4.06
78.9
50
Stretch
Passed
24.22
91.6
100
Stretch
Passed
102
125.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
discrete.digraph · 3 passing test cases, 3 distinct argument descriptions
A minimum-cost flow network has integer capacities and integer supplies with a feasible bounded optimum. Why can one seek an integral optimum?
Worked solution
The node–arc incidence matrix is totally unimodular. Integral right-hand sides give integral vertices of the feasible flow polyhedron, so a linear objective admits an integral optimal vertex.
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. Roughly 2–10 binary decisions or a 2×2 to 8×8 assignment; feasibility, integrality and optimality are separate questions.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 15 / 40 · Discrete optimization
Relaxation bound
Assisted@ratmath/core
Problem
An LP relaxation of an integer maximization model has value 18.6 and the objective is integer-valued. What upper bound follows?
Worked solution
Every integer feasible solution is feasible for the relaxation, so its objective is at most 18.
Using RatMath
Construct an Integer or Rational before applying its methods. Use fraction strings or integer inputs to preserve exact values.
JavaScript module
import { Rational } from "@ratmath/core";
console.log(String(new Rational("18.6").floor()));
Checked output
18
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. Roughly 2–10 binary decisions or a 2×2 to 8×8 assignment; feasibility, integrality and optimality are separate questions.
Focal example. The code above passed its displayed check in 0.071 ms on Node.
Related workload in this unit.core.Rational.add · denominator. Baseline test points across courses 1, 2, 3, 12, 100, 1,000. Cross-multiply 1/n + 1/(n+1) against (2n+1)/(n(n+1)).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000,007 (0.038 ms, 76.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact work depends on the bit lengths of both numerator and denominator. A long sum of relatively prime fractions can build a large common denominator.
Measured times, memory and outcomes
denominator · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.034
74.9
2
Baseline
Passed
0.036
75.6
3
Baseline
Passed
0.040
75.9
12
Baseline
Passed
0.039
75.2
100
Baseline
Passed
0.041
75
1,000
Baseline
Passed
0.035
75.8
1,000,003
Stretch
Passed
0.044
75
1,000,000,007
Stretch
Passed
0.038
76.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.Rational · 485 passing test cases, 447 distinct argument descriptions
Express “if project A is selected, project B must also be selected” using binary variables.
Worked solution
Impose x_A≤x_B. Only the assignment (1,0) violates the condition.
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. Roughly 2–10 binary decisions or a 2×2 to 8×8 assignment; feasibility, integrality and optimality are separate questions.
Scope of verification. This day asks for a hand argument, construction or interpretation. The worked instance gives the input. General claims need the reasoning shown above. A measured time, memory ceiling or finite input sweep would not verify that claim.
Day 17 / 40 · Smooth unconstrained optimization
Optimising a rectangle
Direct calculation@ratmath/analytic
Problem
A rectangle has perimeter 20. What is the largest area it can have?
Worked solution
With sides and , is largest at : area 25.
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 analytic from "@ratmath/analytic";
console.log(
analytic.extrema("x*(10 - x)", [0, 10]).exact().filter((e) => e.kind === "max").map((e) => [e.at, e.value])
);
Checked output
[[5, 25]]
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 real variables, simple polynomials and a few starting points; local stationary conditions need global checks.
Focal example. The code above passed its displayed check in 1.56 ms on Node.
Related workload in this unit.analytic.gradientDescent · iterations. Baseline test points across courses 1, 2, 4, 10. For f=x²+y², step 1/4 and start (1,1), each coordinate halves every iteration.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 300 (7.03 ms, 81.6 MiB peak process RSS). The runs did not locate a ceiling for this family. Starting point and step size affect convergence. A converged local iterate does not establish global optimality.
Measured times, memory and outcomes
iterations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.976
75.6
2
Baseline
Passed
0.942
75.8
4
Baseline
Passed
0.860
75.8
10
Baseline
Passed
1.07
75.7
30
Stretch
Passed
1.55
75.4
100
Stretch
Passed
2.90
77
300
Stretch
Passed
7.03
81.6
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.
analytic.extrema · 10 passing test cases, 11 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. One or two real variables, simple polynomials and a few starting points; local stationary conditions need global checks.
Focal example. The code above passed its displayed check in 0.679 ms on Node.
Related workload in this unit.analytic.gradientDescent · iterations. Baseline test points across courses 1, 2, 4, 10. For f=x²+y², step 1/4 and start (1,1), each coordinate halves every iteration.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 300 (7.03 ms, 81.6 MiB peak process RSS). The runs did not locate a ceiling for this family. Starting point and step size affect convergence. A converged local iterate does not establish global optimality.
Measured times, memory and outcomes
iterations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.976
75.6
2
Baseline
Passed
0.942
75.8
4
Baseline
Passed
0.860
75.8
10
Baseline
Passed
1.07
75.7
30
Stretch
Passed
1.55
75.4
100
Stretch
Passed
2.90
77
300
Stretch
Passed
7.03
81.6
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.
analytic.extrema · 10 passing test cases, 11 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. One or two real variables, simple polynomials and a few starting points; local stationary conditions need global checks.
Focal example. The code above passed its displayed check in 1.51 ms on Node.
Related workload in this unit.symbolic.sym.diff · degree. Baseline test points across courses 1, 2, 4, 8. Derivative of x^n at 2 is n·2^(n−1).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,024 (0.459 ms, 74.4 MiB peak process RSS). The runs did not locate a ceiling for this family. A monomial differentiates to one term. Products, repeated derivatives and expression expansion can make intermediate expressions much larger.
Measured times, memory and outcomes
degree · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.157
75.7
2
Baseline
Passed
0.192
75.7
4
Baseline
Passed
0.276
75.2
8
Baseline
Passed
0.642
75.5
16
Stretch
Passed
18.83
74.7
64
Stretch
Passed
0.406
75
256
Stretch
Passed
0.241
75.3
1,024
Stretch
Passed
0.459
74.4
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
analytic.field · 20 passing test cases, 22 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. One or two real variables, simple polynomials and a few starting points; local stationary conditions need global checks.
Focal example. The code above passed its displayed check in 10.03 ms on Node.
Related workload in this unit.symbolic.sym.diff · degree. Baseline test points across courses 1, 2, 4, 8. Derivative of x^n at 2 is n·2^(n−1).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,024 (0.459 ms, 74.4 MiB peak process RSS). The runs did not locate a ceiling for this family. A monomial differentiates to one term. Products, repeated derivatives and expression expansion can make intermediate expressions much larger.
Measured times, memory and outcomes
degree · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.157
75.7
2
Baseline
Passed
0.192
75.7
4
Baseline
Passed
0.276
75.2
8
Baseline
Passed
0.642
75.5
16
Stretch
Passed
18.83
74.7
64
Stretch
Passed
0.406
75
256
Stretch
Passed
0.241
75.3
1,024
Stretch
Passed
0.459
74.4
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
analytic.field · 20 passing test cases, 22 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. One or two real variables, simple polynomials and a few starting points; local stationary conditions need global checks.
Focal example. The code above passed its displayed check in 1.55 ms on Node.
Related workload in this unit.analytic.gradientDescent · iterations. Baseline test points across courses 1, 2, 4, 10. For f=x²+y², step 1/4 and start (1,1), each coordinate halves every iteration.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 300 (7.03 ms, 81.6 MiB peak process RSS). The runs did not locate a ceiling for this family. Starting point and step size affect convergence. A converged local iterate does not establish global optimality.
Measured times, memory and outcomes
iterations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.976
75.6
2
Baseline
Passed
0.942
75.8
4
Baseline
Passed
0.860
75.8
10
Baseline
Passed
1.07
75.7
30
Stretch
Passed
1.55
75.4
100
Stretch
Passed
2.90
77
300
Stretch
Passed
7.03
81.6
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.
analytic.extrema · 10 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 analytic from "@ratmath/analytic";
console.log(analytic.extrema("x^3 - 3x", [0, 2]).exact().map((e) => [e.kind, e.at, e.value]));
Checked output
[["min", 1, -2]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One or two real variables, simple polynomials and a few starting points; local stationary conditions need global checks.
Focal example. The code above passed its displayed check in 0.546 ms on Node.
Related workload in this unit.analytic.gradientDescent · iterations. Baseline test points across courses 1, 2, 4, 10. For f=x²+y², step 1/4 and start (1,1), each coordinate halves every iteration.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 300 (7.03 ms, 81.6 MiB peak process RSS). The runs did not locate a ceiling for this family. Starting point and step size affect convergence. A converged local iterate does not establish global optimality.
Measured times, memory and outcomes
iterations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.976
75.6
2
Baseline
Passed
0.942
75.8
4
Baseline
Passed
0.860
75.8
10
Baseline
Passed
1.07
75.7
30
Stretch
Passed
1.55
75.4
100
Stretch
Passed
2.90
77
300
Stretch
Passed
7.03
81.6
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.
analytic.extrema · 10 passing test cases, 11 distinct argument descriptions
No. Values on opposite sides of zero have opposite signs. The stationary point is an inflection.
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 real variables, simple polynomials and a few starting points; local stationary conditions need global 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 · Smooth unconstrained optimization
Coercivity
Worked by hand
Problem
Why does a continuous coercive function on ℝⁿ attain a global minimum?
Worked solution
Outside a sufficiently large ball its values exceed a chosen reference value. The extreme-value theorem gives a minimum on the closed ball.
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 real variables, simple polynomials and a few starting points; local stationary conditions need global 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 25 / 40 · Constrained optimization
Lagrange multipliers
Direct calculation@ratmath/analytic
Problem
Find the point of the line closest to the origin.
Worked solution
Minimise : , , so and , ; distance squared 5.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as analytic from "@ratmath/analytic";
const mid = (v) => (v.low.toNumber() + v.high.toNumber()) / 2;
const r = analytic.lagrange("x^2 + y^2", "x + 2*y - 5", ["x", "y"], { x: [-10, 10], y: [-10, 10] });
const c = r.candidates[0];
console.log(
[...Object.values(c.point).map(mid), mid(c.value), r.candidates.length] // x, y, value, how many candidates
);
Checked output
[1, 2, 5, 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. One or two active constraints and up to three continuous unknowns in hand calculations; check constraint qualifications.
Focal example. The code above passed its displayed check in 1.48 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.symbolic.sym.diff · degree. Baseline test points across courses 1, 2, 4, 8. Derivative of x^n at 2 is n·2^(n−1).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,024 (0.459 ms, 74.4 MiB peak process RSS). The runs did not locate a ceiling for this family. A monomial differentiates to one term. Products, repeated derivatives and expression expansion can make intermediate expressions much larger.
Measured times, memory and outcomes
degree · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.157
75.7
2
Baseline
Passed
0.192
75.7
4
Baseline
Passed
0.276
75.2
8
Baseline
Passed
0.642
75.5
16
Stretch
Passed
18.83
74.7
64
Stretch
Passed
0.406
75
256
Stretch
Passed
0.241
75.3
1,024
Stretch
Passed
0.459
74.4
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
analytic.lagrange · 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 analytic from "@ratmath/analytic";
const mid = (v) => (v.low.toNumber() + v.high.toNumber()) / 2;
const r = analytic.lagrange("x*y*z", "x + y + z - 3", ["x", "y", "z"], { x: ["1/2", 2], y: ["1/2", 2], z: ["1/2", 2] });
console.log(
[...Object.values(r.candidates[0].point).map(mid), mid(r.candidates[0].value), r.candidates.length] // x, y, z, value, how many candidates
);
Checked output
[1, 1, 1, 1, 1]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One or two active constraints and up to three continuous unknowns in hand calculations; check constraint qualifications.
Focal example. The code above passed its displayed check in 384 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.symbolic.sym.diff · degree. Baseline test points across courses 1, 2, 4, 8. Derivative of x^n at 2 is n·2^(n−1).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,024 (0.459 ms, 74.4 MiB peak process RSS). The runs did not locate a ceiling for this family. A monomial differentiates to one term. Products, repeated derivatives and expression expansion can make intermediate expressions much larger.
Measured times, memory and outcomes
degree · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.157
75.7
2
Baseline
Passed
0.192
75.7
4
Baseline
Passed
0.276
75.2
8
Baseline
Passed
0.642
75.5
16
Stretch
Passed
18.83
74.7
64
Stretch
Passed
0.406
75
256
Stretch
Passed
0.241
75.3
1,024
Stretch
Passed
0.459
74.4
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
analytic.lagrange · 1 passing test case, 2 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One or two active constraints and up to three continuous unknowns in hand calculations; check constraint qualifications.
For this problem type. Use 2×2 through 4×4 matrices for hand spectra, including repeated eigenvalues. An entry’s size alone gives little indication of root-isolation cost.
Focal example. The code above passed its displayed check in 0.697 ms on Node.
Same API, measured input family.linalg.eigenvalues.exact · matrix side. Baseline test points across courses 1, 2, 3, 4. An upper bidiagonal matrix has diagonal entries 1 through n as its full spectrum.
Practical limit. Largest passing sample 18 (18.30 ms, 87.1 MiB peak process RSS). The runs did not locate a ceiling for this family. The triangular example has rational eigenvalues. General characteristic polynomials, repeated roots and algebraic root isolation are harder.
Measured times, memory and outcomes
matrix side · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.92
75.5
2
Baseline
Passed
6.14
75.2
3
Baseline
Passed
3.11
75
4
Baseline
Passed
7.05
76.1
6
Stretch
Passed
4.26
75.4
10
Stretch
Passed
7.90
78.4
18
Stretch
Passed
18.30
87.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.
linalg.definiteness · 1 passing test case, 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. One or two active constraints and up to three continuous unknowns in hand calculations; check constraint qualifications.
Focal example. The code above passed its displayed check in 802 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.symbolic.sym.diff · degree. Baseline test points across courses 1, 2, 4, 8. Derivative of x^n at 2 is n·2^(n−1).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,024 (0.459 ms, 74.4 MiB peak process RSS). The runs did not locate a ceiling for this family. A monomial differentiates to one term. Products, repeated derivatives and expression expansion can make intermediate expressions much larger.
Measured times, memory and outcomes
degree · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.157
75.7
2
Baseline
Passed
0.192
75.7
4
Baseline
Passed
0.276
75.2
8
Baseline
Passed
0.642
75.5
16
Stretch
Passed
18.83
74.7
64
Stretch
Passed
0.406
75
256
Stretch
Passed
0.241
75.3
1,024
Stretch
Passed
0.459
74.4
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
analytic.lagrange · 1 passing test case, 2 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One or two active constraints and up to three continuous unknowns in hand calculations; check constraint qualifications.
Focal example. The code above passed its displayed check in 91.32 ms on Node.
Related workload in this unit.symbolic.sym.diff · degree. Baseline test points across courses 1, 2, 4, 8. Derivative of x^n at 2 is n·2^(n−1).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,024 (0.459 ms, 74.4 MiB peak process RSS). The runs did not locate a ceiling for this family. A monomial differentiates to one term. Products, repeated derivatives and expression expansion can make intermediate expressions much larger.
Measured times, memory and outcomes
degree · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.157
75.7
2
Baseline
Passed
0.192
75.7
4
Baseline
Passed
0.276
75.2
8
Baseline
Passed
0.642
75.5
16
Stretch
Passed
18.83
74.7
64
Stretch
Passed
0.406
75
256
Stretch
Passed
0.241
75.3
1,024
Stretch
Passed
0.459
74.4
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
analytic.field · 20 passing test cases, 22 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. One or two active constraints and up to three continuous unknowns in hand calculations; check constraint qualifications.
For this problem type. Use 2×2 through 4×4 matrices for hand spectra, including repeated eigenvalues. An entry’s size alone gives little indication of root-isolation cost.
Focal example. The code above passed its displayed check in 0.262 ms on Node.
Related workload in this unit.linalg.eigenvalues.exact · matrix side. Baseline test points across courses 1, 2, 3, 4. An upper bidiagonal matrix has diagonal entries 1 through n as its full spectrum.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 18 (18.30 ms, 87.1 MiB peak process RSS). The runs did not locate a ceiling for this family. The triangular example has rational eigenvalues. General characteristic polynomials, repeated roots and algebraic root isolation are harder.
Measured times, memory and outcomes
matrix side · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
1.92
75.5
2
Baseline
Passed
6.14
75.2
3
Baseline
Passed
3.11
75
4
Baseline
Passed
7.05
76.1
6
Stretch
Passed
4.26
75.4
10
Stretch
Passed
7.90
78.4
18
Stretch
Passed
18.30
87.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.
linalg.definiteness · 1 passing test case, 4 distinct argument descriptions
At an optimum with a valid KKT system, what multiplier corresponds to a strictly slack inequality?
Worked solution
Complementary slackness forces its multiplier to zero. A binding inequality may also have zero multiplier.
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 active constraints and up to three continuous unknowns in hand calculations; check constraint qualifications.
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 · Constrained optimization
Constraint qualification
Worked by hand
Problem
Minimize x subject to x²=0. Why do ordinary equality-multiplier equations miss the answer?
Worked solution
Only x=0 is feasible, but the constraint gradient vanishes there, so no multiplier can cancel the nonzero objective gradient.
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 active constraints and up to three continuous unknowns in hand calculations; check constraint qualifications.
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 · Methods and sensitivity
Least squares
Direct calculation@ratmath/linalg
Problem
Fit a line to by least squares.
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 linalg from "@ratmath/linalg";
console.log(
linalg.leastSquares([[1, 0], [1, 1], [1, 2], [1, 3]], [1, 3, 4, 4]).exact().x.toArray().flat()
);
Checked output
[3/2, 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. Small least-squares matrices or about 1–50 numerical iterations; inspect scaling, gradient norm and feasibility as well as objective change.
For this problem type. Hand fits use about 4–12 paired observations. A classroom dataset can have tens to hundreds of rows and one to five predictors. Include a nonconstant predictor.
Focal example. The code above passed its displayed check in 0.404 ms on Node.
Same API, measured input family.linalg.leastSquares.exact · observations. Baseline test points across courses 2, 3, 5, 20. For y=2+3x, recover both coefficients with zero residual.
Practical limit. Largest passing sample 2,000 (68.14 ms, 92.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Cost depends on both observations and independent columns. Collinearity can destroy uniqueness, and near-collinearity makes floating fits sensitive.
Measured times, memory and outcomes
observations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
1.88
75.3
3
Baseline
Passed
2.81
75.9
5
Baseline
Passed
2.05
74.7
20
Baseline
Passed
2.43
75.7
100
Stretch
Passed
4.00
75.9
500
Stretch
Passed
18.48
81.3
2,000
Stretch
Passed
68.14
92.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.
linalg.leastSquares · 1 passing test case, 2 distinct argument descriptions
Take one gradient-descent step of size 0.1 from on .
Worked solution
, so the step lands at .
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 analytic from "@ratmath/analytic";
console.log(analytic.gradientDescent("x^2 + 4*y^2", ["1", "1"], { step: "1/10", steps: 1 }).final);
Checked output
[4/5, 1/5]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small least-squares matrices or about 1–50 numerical iterations; inspect scaling, gradient norm and feasibility as well as objective change.
Focal example. The code above passed its displayed check in 0.639 ms on Node.
Same API, measured input family.analytic.gradientDescent · iterations. Baseline test points across courses 1, 2, 4, 10. For f=x²+y², step 1/4 and start (1,1), each coordinate halves every iteration.
Practical limit. Largest passing sample 300 (7.03 ms, 81.6 MiB peak process RSS). The runs did not locate a ceiling for this family. Starting point and step size affect convergence. A converged local iterate does not establish global optimality.
Measured times, memory and outcomes
iterations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.976
75.6
2
Baseline
Passed
0.942
75.8
4
Baseline
Passed
0.860
75.8
10
Baseline
Passed
1.07
75.7
30
Stretch
Passed
1.55
75.4
100
Stretch
Passed
2.90
77
300
Stretch
Passed
7.03
81.6
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.
analytic.gradientDescent · 4 passing test cases, 4 distinct argument descriptions
Take two Newton steps for minimising from . What is the exact minimiser?
Worked solution
, . , . The minimiser is .
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 analytic from "@ratmath/analytic";
const r = analytic.newton("2*x - 1/x", 1); // Newton's method on f'
console.log([r.iterations[1].x, r.iterations[2].x, r.root]);
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 least-squares matrices or about 1–50 numerical iterations; inspect scaling, gradient norm and feasibility as well as objective change.
For this problem type. Use one scalar function, one starting point or bracket and about 3–20 displayed iterations. Typical requested errors are 10⁻³ to 10⁻¹⁰.
Focal example. The code above passed its displayed check in 1.38 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.analytic.bisection · decimal tolerance exponent. Baseline test points across courses 2, 4, 6, 8. Both the returned root and its final bracket must contain or agree with √2 to the requested tolerance, allowing one double-precision ulp for the floating trace. Check enclosure endpoint squares.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 24 (7.66 ms, 79.5 MiB peak process RSS). The runs did not locate a ceiling for this family. The displayed iteration trace uses doubles; precision eventually stops improving. A bracket with several roots can select different roots under different starting bounds. Compare the returned enclosure with the trace.
Measured times, memory and outcomes
decimal tolerance exponent · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
4.24
74.7
4
Baseline
Passed
4.72
77.2
6
Baseline
Passed
4.12
77
8
Baseline
Passed
6.67
76.9
10
Stretch
Passed
4.27
77.4
12
Stretch
Passed
4.18
75.9
16
Stretch
Passed
4.90
76.4
24
Stretch
Passed
7.66
79.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.
analytic.newton · 4 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 linalg from "@ratmath/linalg";
console.log(String(linalg.cond([["1", "1"], ["1", "1.0001"]], "inf").exact()));
Checked output
400040001/10000
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 least-squares matrices or about 1–50 numerical iterations; inspect scaling, gradient norm and feasibility as well as objective change.
Focal example. The code above passed its displayed check in 0.527 ms on Node.
Related workload in this unit.linalg.rref.exact · matrix side. Baseline test points across courses 1, 2, 4, 8. A lower triangular square matrix with diagonal 1 is invertible and reduces to the identity.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 128 (119 ms, 92.8 MiB peak process RSS). The first sampled passing call above 100 ms used 128 (119 ms). The runs did not locate a ceiling for this family. Exact elimination preserves pivots. Input dimensions, rank and the size of intermediate fractions affect memory and time.
Measured times, memory and outcomes
matrix side · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.937
76.1
2
Baseline
Passed
0.800
75.3
4
Baseline
Passed
1.05
75.4
8
Baseline
Passed
2.45
74.4
16
Stretch
Passed
3.07
75.6
32
Stretch
Passed
8.82
78.7
64
Stretch
Passed
19.67
89.3
128
Stretch
Passed
119
92.8
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.
linalg.cond · 1 passing test case, 4 distinct argument descriptions
: , , . The correct digits roughly double each step.
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 analytic from "@ratmath/analytic";
console.log(analytic.newton("x^2 - 2", "1").iterations.slice(1, 4).map((i) => i.x));
Checked output
[1.5, 1.4166666666666667, 1.4142156862745099]
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 least-squares matrices or about 1–50 numerical iterations; inspect scaling, gradient norm and feasibility as well as objective change.
For this problem type. Use one scalar function, one starting point or bracket and about 3–20 displayed iterations. Typical requested errors are 10⁻³ to 10⁻¹⁰.
Focal example. The code above passed its displayed check in 1.27 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.analytic.bisection · decimal tolerance exponent. Baseline test points across courses 2, 4, 6, 8. Both the returned root and its final bracket must contain or agree with √2 to the requested tolerance, allowing one double-precision ulp for the floating trace. Check enclosure endpoint squares.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 24 (7.66 ms, 79.5 MiB peak process RSS). The runs did not locate a ceiling for this family. The displayed iteration trace uses doubles; precision eventually stops improving. A bracket with several roots can select different roots under different starting bounds. Compare the returned enclosure with the trace.
Measured times, memory and outcomes
decimal tolerance exponent · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
4.24
74.7
4
Baseline
Passed
4.72
77.2
6
Baseline
Passed
4.12
77
8
Baseline
Passed
6.67
76.9
10
Stretch
Passed
4.27
77.4
12
Stretch
Passed
4.18
75.9
16
Stretch
Passed
4.90
76.4
24
Stretch
Passed
7.66
79.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.
analytic.newton · 4 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 linalg from "@ratmath/linalg";
console.log(
String(linalg.leastSquares([[1, 0], [1, 1], [1, 2], [1, 3]], [[1], [3], [4], [4]]).exact().x)
);
Checked output
[3/2]
[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. Small least-squares matrices or about 1–50 numerical iterations; inspect scaling, gradient norm and feasibility as well as objective change.
For this problem type. Hand fits use about 4–12 paired observations. A classroom dataset can have tens to hundreds of rows and one to five predictors. Include a nonconstant predictor.
Focal example. The code above passed its displayed check in 0.287 ms on Node.
Same API, measured input family.linalg.leastSquares.exact · observations. Baseline test points across courses 2, 3, 5, 20. For y=2+3x, recover both coefficients with zero residual.
Practical limit. Largest passing sample 2,000 (68.14 ms, 92.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Cost depends on both observations and independent columns. Collinearity can destroy uniqueness, and near-collinearity makes floating fits sensitive.
Measured times, memory and outcomes
observations · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
1.88
75.3
3
Baseline
Passed
2.81
75.9
5
Baseline
Passed
2.05
74.7
20
Baseline
Passed
2.43
75.7
100
Stretch
Passed
4.00
75.9
500
Stretch
Passed
18.48
81.3
2,000
Stretch
Passed
68.14
92.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.
linalg.leastSquares · 1 passing test case, 2 distinct argument descriptions
Apply two gradient steps to f(x)=x² from x=8 with step size 1/4.
Worked solution
Each step multiplies x by 1−2(1/4)=1/2. Two steps reach 2.
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { R } from "@ratmath/core";
console.log(String(R`8*(1-2/4)^2`));
Checked output
2
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small least-squares matrices or about 1–50 numerical iterations; inspect scaling, gradient norm and feasibility as well as objective change.
Focal example. The code above passed its displayed check in 0.131 ms on Node.
Same arithmetic expression. Replaced its first numeral 8 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.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
Why can a small parameter update alone be a misleading stopping rule?
Worked solution
A tiny step size can produce small updates far from stationarity. Check the gradient or projected gradient, feasibility and objective change as appropriate.
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 least-squares matrices or about 1–50 numerical iterations; inspect scaling, gradient norm and feasibility as well as objective change.
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.