36 of 40 focal problems use RatMath for a calculation or a substantive step.
Direct calculation
33 · 82.5%
Assisted
3 · 7.5%
Worked by hand
4 · 10%
Using the packages
Preview values are convenient for exploring an algorithm; exact references help separate discretization from roundoff. The pinned bisection routine can report another root when an initial bracket contains several. Isolate the target before trusting its error column.
Calculator interface
Expose working precision, iteration history, residual, step size and a proven bound separately. Make absolute and relative error explicit and let students compare two mesh sizes.
Each of the 40 focal problems has equal weight. Direct means the displayed package calculation answers the computational question after the inputs are set up. Assisted means it contributes a step and the worked solution supplies essential reasoning, interpretation or selection. Worked by hand means the guide relies on a construction, argument or judgment for that task. The helpful share combines direct and assisted days. Courses and instructors assign different mixes of problems. The percentages describe this syllabus.
Classroom inputs and practical limits
36 of 40 days include a checked executable example. On 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 · Arithmetic and conditioning. Binary64 examples at ordinary and extreme scales; 2×2 to 10×10 matrices illustrate condition numbers.
Unit benchmark · core.Rational.multiply, operand bits. Largest passing sample 131,072 (1.53 ms, 75.5 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 9–16 · Nonlinear equations. One bracket or one or two starting points, tolerances about 10⁻²–10⁻¹⁰ and a finite iteration budget.
Unit benchmark · analytic.bisection, decimal tolerance exponent. Largest passing sample 24 (7.66 ms, 79.5 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 17–24 · Approximation. About 2–20 nodes for explicit polynomial interpolation or low-degree least-squares fits; clustered nodes change conditioning.
Unit benchmark · analytic.interpolate, distinct nodes. Largest passing sample 64 (17.06 ms, 89.7 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 25–32 · Quadrature. A few to a few hundred panels, a low-degree polynomial or smooth test function, and a specified error criterion.
Unit benchmark · analytic.quadratureRule, Simpson panels. Largest passing sample 2,048 (120 ms, 90.9 MiB peak process RSS). The first sampled passing call above 100 ms used 2,048 (120 ms). The runs did not locate a ceiling for this family.
Days 33–40 · ODEs and linear systems. Typically tens to hundreds of time steps or small exact linear systems; stability depends on step size times spectral scale.
Unit benchmark · analytic.odeMethod, Euler steps. Largest passing sample 1,000 (292 ms, 90.4 MiB peak process RSS). The first sampled passing call above 100 ms used 300 (117 ms). The runs did not locate a ceiling for this family.
Accuracy notes (1)
Fixed · Bisection identifies the root selected by its trace. For (x−1)(x−6)(x−9) on [0,10], the certificate now returns the root 1 inside the last displayed bracket. A sign-changing interval can still contain several roots.
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. Binary64 examples at ordinary and extreme scales; 2×2 to 10×10 matrices illustrate condition numbers.
Focal example. The code above passed its displayed check in 0.355 ms on Node.
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.
analytic.floatParts · 1 passing test case, 1 distinct argument description
Evaluate at in double precision. What goes wrong, and what is the true value?
Worked solution
rounds to , so the computed difference is 0, with every digit lost. Rewriting as gives the true value.
Using RatMath
Rationalize the difference to explain cancellation. The comparison reports the floating result beside the high-precision value.
JavaScript module
import * as analytic from "@ratmath/analytic";
const r = analytic.roundoff("sqrt(x + 1) - sqrt(x)", { x: 1e16 });
console.log([r.float, r.exact, r.digitsLost]);
Checked output
[0, 0.00000000499999999999:0.000000005, 16]
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. Binary64 examples at ordinary and extreme scales; 2×2 to 10×10 matrices illustrate condition numbers.
Focal example. The code above passed its displayed check in 0.676 ms on Node.
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.
analytic.roundoff · 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 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. Binary64 examples at ordinary and extreme scales; 2×2 to 10×10 matrices illustrate condition numbers.
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
Enter the matrix one row at a time, preserving the order of the unknowns. Use the result with the original matrix to check the required relation.
JavaScript module
import * as linalg from "@ratmath/linalg";
console.log(String(linalg.det([[2, -1, 0], [1, 3, 4], [0, 5, -2]]).exact()));
Checked output
-54
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. Binary64 examples at ordinary and extreme scales; 2×2 to 10×10 matrices illustrate condition numbers.
For this problem type. Hand calculations usually use 2–5 rows and columns with small integer or rational entries. Include deficient rank as a separate case.
Focal example. The code above passed its displayed check in 0.117 ms on Node.
Same API, measured input family.linalg.det.exact · square matrix side. Baseline test points across courses 1, 2, 3, 5, 10. Dense matrix I+J has eigenvalues 1 (n−1 times) and n+1.
Practical limit. Largest passing sample 200 (383 ms, 131.8 MiB peak process RSS). The first sampled passing call above 100 ms used 200 (383 ms). The runs did not locate a ceiling for this family. Even with small dimensions, large integer minors increase the cost of exact elimination. The dense structured fixture has small entries.
Measured times, memory and outcomes
square matrix side · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.731
76.1
2
Baseline
Passed
0.810
74.8
3
Baseline
Passed
0.876
75.2
5
Baseline
Passed
1.32
75.4
10
Baseline
Passed
1.58
76.1
25
Stretch
Passed
7.10
77.5
50
Stretch
Passed
21.28
81.7
100
Stretch
Passed
67.11
90.3
200
Stretch
Passed
383
131.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.
linalg.det · 19 passing test cases, 22 distinct argument descriptions
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as symbolic from "@ratmath/symbolic";
console.log(String(symbolic.taylor("sqrt(x)", "x", 4, 1)));
Checked output
2 + 1/4*(x - 4) + …
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Binary64 examples at ordinary and extreme scales; 2×2 to 10×10 matrices illustrate condition numbers.
For this problem type. Typical hand calculations keep 2–10 nonzero terms. Specify the expansion center and distance of the evaluation point from it.
Focal example. The code above passed its displayed check in 0.658 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.
symbolic.taylor · 2 passing test cases, 7 distinct argument descriptions
Approximate 1/3 by 0.33. Find the absolute relative error.
Worked solution
Divide the absolute difference by the absolute exact value to obtain one percent.
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`(1/3-0.33)/(1/3)`));
Checked output
1/100
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. Binary64 examples at ordinary and extreme scales; 2×2 to 10×10 matrices illustrate condition numbers.
Focal example. The code above passed its displayed check in 0.377 ms on Node.
Same arithmetic expression. Replaced its first numeral 1 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.add · denominator. Baseline test points across courses 1, 2, 3, 12, 100, 1,000. Cross-multiply 1/n + 1/(n+1) against (2n+1)/(n(n+1)).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000,007 (0.038 ms, 76.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact work depends on the bit lengths of both numerator and denominator. A long sum of relatively prime fractions can build a large common denominator.
Measured times, memory and outcomes
denominator · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.034
74.9
2
Baseline
Passed
0.036
75.6
3
Baseline
Passed
0.040
75.9
12
Baseline
Passed
0.039
75.2
100
Baseline
Passed
0.041
75
1,000
Baseline
Passed
0.035
75.8
1,000,003
Stretch
Passed
0.044
75
1,000,000,007
Stretch
Passed
0.038
76.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
Rewrite √(1+x)−1 for small positive x to avoid subtraction of nearly equal numbers.
Worked solution
Multiply by the conjugate to get x/(√(1+x)+1). The formulas agree on the common domain.
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. Binary64 examples at ordinary and extreme scales; 2×2 to 10×10 matrices illustrate condition numbers.
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 · Arithmetic and conditioning
Residual and conditioning
Direct calculation@ratmath/core
Problem
For 10⁻⁸x=1, how much forward error corresponds to an absolute residual of 10⁻⁸?
Worked solution
Divide by the magnitude of the coefficient. A small absolute residual can mean a forward error of one.
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`(1/10^8)/(1/10^8)`));
Checked output
1
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Binary64 examples at ordinary and extreme scales; 2×2 to 10×10 matrices illustrate condition numbers.
Focal example. The code above passed its displayed check in 0.120 ms on Node.
Same arithmetic expression. Replaced its first numeral 1 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
Bisection on over : how many steps until the guaranteed error is below ?
Worked solution
needs (): 19 halvings, i.e. 20 midpoints counting the first, with bound .
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 b = analytic.bisection("x^2 - 2", ["1", "2"], { tol: "1e-6" });
console.log([b.iterations.length, b.iterations.at(-1).bound]);
Checked output
[20, 9.5367431640625e-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. One bracket or one or two starting points, tolerances about 10⁻²–10⁻¹⁰ and a finite iteration budget.
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.21 ms on Node.
Same API, measured input family.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. 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. 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.bisection · 3 passing test cases, 3 distinct argument descriptions
Fixed · Bisection identifies the root selected by its trace. For (x−1)(x−6)(x−9) on [0,10], the certificate now returns the root 1 inside the last displayed bracket. A sign-changing interval can still contain several roots.
Day 10 / 40 · Nonlinear equations
Newton's method
Direct calculation@ratmath/analytic
Problem
Apply Newton's method to from . Give .
Worked solution
: , , . 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. One bracket or one or two starting points, tolerances about 10⁻²–10⁻¹⁰ and a finite iteration budget.
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 analytic from "@ratmath/analytic";
console.log(analytic.secant("x^2 - 2", "1", "2").iterations.slice(2, 4).map((i) => i.x));
Checked output
[1.3333333333333335, 1.4000000000000001]
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 bracket or one or two starting points, tolerances about 10⁻²–10⁻¹⁰ and a finite iteration budget.
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.21 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.secant · 2 passing test cases, 2 distinct argument descriptions
For , by what factor does the error shrink each step near the fixed point?
Worked solution
: linear convergence with that ratio.
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.fixedPoint("cos(x)", "1").multiplier);
Checked output
-0.6736120291832148153[5:4]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One bracket or one or two starting points, tolerances about 10⁻²–10⁻¹⁰ and a finite iteration budget.
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 4.36 ms on Node.
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.fixedPoint · 2 passing test cases, 2 distinct argument descriptions
Direct calculation@ratmath/analytic · @ratmath/core
Problem
Apply Newton's method to from . Give as fractions.
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 analytic from "@ratmath/analytic";
import { exact } from "@ratmath/core";
console.log(
analytic.newton("x^2 - 2", "1", { exact: true, steps: 3 }).iterations.slice(1).map((r) => r.x)
);
Checked output
[3/2, 17/12, 577/408]
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 bracket or one or two starting points, tolerances about 10⁻²–10⁻¹⁰ and a finite iteration budget.
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 3.90 ms on Node.
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
Show is a contraction on and find its fixed point.
Worked solution
maps into and . The fixed point (the Dottie number) is .
Using RatMath
Verify that cosine maps [0,1] into itself and bound its derivative by sin(1)<1 before applying the contraction theorem.
JavaScript module
import * as analytic from "@ratmath/analytic";
import { Rational } from "@ratmath/core";
// the two hypotheses, each from a certified range over [0, 1], then the fixed point
const slope = analytic.fn("sin(x)").range(["0", "1"]).exact(); // g′ = −sin x
const image = analytic.fn("cos(x)").range(["0", "1"]).exact();
const one = new Rational(1n);
// |g′| < 1 on [0, 1]; g ≥ 0 there, and cos ≤ 1 everywhere, so g maps [0, 1] into itself
console.log(
[slope.high.lessThan(one) && slope.low.greaterThan(one.negate()), image.low.greaterThan(new Rational(0n)), analytic.fixedPoint("cos(x)", "1").root]
);
Checked output
[true, true, 0.7390851332151606416[5:6]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. One bracket or one or two starting points, tolerances about 10⁻²–10⁻¹⁰ and a finite iteration budget.
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 168 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.
analytic.fn · 51 passing test cases, 88 distinct argument descriptions
After ten halvings of [1,2], what is the width of the retained bracket?
Worked solution
Each bisection halves the preceding width. The midpoint error is at most half of the final width if that bracket contains the intended root.
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`1/2^10`));
Checked output
1/1024
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 bracket or one or two starting points, tolerances about 10⁻²–10⁻¹⁰ and a finite iteration budget.
Focal example. The code above passed its displayed check in 0.098 ms on Node.
Same arithmetic expression. Replaced its first numeral 1 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
For f(x)=(x−1)², derive the recurrence of the error under Newton's method.
Worked solution
For x≠1 the correction is (x−1)/2. The next error is half the old error, giving linear convergence.
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 bracket or one or two starting points, tolerances about 10⁻²–10⁻¹⁰ and a finite iteration budget.
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 · Approximation
Interpolation
Direct calculation@ratmath/analytic
Problem
Find the polynomial through , , and evaluate it at 3.
Worked solution
Divided differences: 1; 2, 4; 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 analytic from "@ratmath/analytic";
const p = analytic.interpolate([[0, 1], [1, 3], [2, 7]]);
console.log([String(p.polynomial), p.at(3)]);
Checked output
["x^2 + x + 1", 13]
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–20 nodes for explicit polynomial interpolation or low-degree least-squares fits; clustered nodes change conditioning.
For this problem type. Use roughly 3–10 distinct nodes. On the line, compare both a nodal value and a value between nodes.
Focal example. The code above passed its displayed check in 0.507 ms on Node.
Same API, measured input family.analytic.interpolate · distinct nodes. Baseline test points across courses 2, 3, 5, 8. For nodes sampled on y=2x+1 the interpolant reproduces that line at the off-grid point n+1.
Practical limit. Largest passing sample 64 (17.06 ms, 89.7 MiB peak process RSS). The runs did not locate a ceiling for this family. Interpolation needs distinct nodes. More equispaced nodes can worsen oscillation between them even when the nodal values match exactly.
Measured times, memory and outcomes
distinct nodes · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.869
75.6
3
Baseline
Passed
0.795
75.3
5
Baseline
Passed
0.952
75.4
8
Baseline
Passed
1.28
75.2
16
Stretch
Passed
2.23
76.2
32
Stretch
Passed
5.35
77.9
64
Stretch
Passed
17.06
89.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.
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.interpolate · 2 passing test cases, 4 distinct argument descriptions
Find the natural cubic spline through , , and its value at .
Worked solution
With : , . On : , so .
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(String(analytic.spline([[0, 0], [1, 1], [2, 0]]).at("1/2")));
Checked output
11/16
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–20 nodes for explicit polynomial interpolation or low-degree least-squares fits; clustered nodes change conditioning.
For this problem type. Use roughly 3–10 distinct nodes. On the line, compare both a nodal value and a value between nodes.
Focal example. The code above passed its displayed check in 0.353 ms on Node.
Same API, measured input family.analytic.spline · equally spaced knots. Baseline test points across courses 2, 3, 5, 10. Natural cubic interpolation reproduces affine data at the midpoint between the first two knots.
Practical limit. Largest passing sample 200 (1,588 ms, 186.4 MiB peak process RSS). Library refusal at 2. The first sampled passing call above one second used 200 (1,588 ms). A natural cubic spline prescribes endpoint second derivatives. Check the knot ordering and boundary conditions before extrapolating.
Measured times, memory and outcomes
equally spaced knots · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Library refusal · AnalyticError: a spline needs at least three points
0.433
75.6
3
Baseline
Passed
1.10
76.1
5
Baseline
Passed
0.892
76.2
10
Baseline
Passed
2.11
75.8
20
Stretch
Passed
5.66
78.3
50
Stretch
Passed
69.53
92.4
100
Stretch
Passed
226
122.1
200
Stretch
Passed
1,588
186.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.
analytic.spline · 1 passing test case, 1 distinct argument description
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.chebyshevNodes(-1, 1, 3));
Checked output
[-56755/65536, 0, 14189/16384]
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–20 nodes for explicit polynomial interpolation or low-degree least-squares fits; clustered nodes change conditioning.
For this problem type. Use roughly 3–10 distinct nodes. On the line, compare both a nodal value and a value between nodes.
Focal example. The code above passed its displayed check in 0.856 ms on Node.
Related workload in this unit.analytic.interpolate · distinct nodes. Baseline test points across courses 2, 3, 5, 8. For nodes sampled on y=2x+1 the interpolant reproduces that line at the off-grid point n+1.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 64 (17.06 ms, 89.7 MiB peak process RSS). The runs did not locate a ceiling for this family. Interpolation needs distinct nodes. More equispaced nodes can worsen oscillation between them even when the nodal values match exactly.
Measured times, memory and outcomes
distinct nodes · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.869
75.6
3
Baseline
Passed
0.795
75.3
5
Baseline
Passed
0.952
75.4
8
Baseline
Passed
1.28
75.2
16
Stretch
Passed
2.23
76.2
32
Stretch
Passed
5.35
77.9
64
Stretch
Passed
17.06
89.7
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
analytic.chebyshevNodes · 1 passing test case, 1 distinct argument description
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(String(analytic.leastSquares([[0, 1], [1, 3], [2, 4], [3, 4]], 1).polynomial));
Checked output
x + 3/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. About 2–20 nodes for explicit polynomial interpolation or low-degree least-squares fits; clustered nodes change conditioning.
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.314 ms on Node.
Related workload in this unit.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. The cutoff for this lesson’s own code is unmeasured. 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. 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.leastSquares · 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. About 2–20 nodes for explicit polynomial interpolation or low-degree least-squares fits; clustered nodes change conditioning.
Focal example. The code above passed its displayed check in 0.284 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.analytic.quadratureRule · Simpson panels. Baseline test points across courses 1, 2, 4, 10. Simpson's rule integrates x³ on [0,1] exactly, giving 1/4 at every panel count.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 2,048 (120 ms, 90.9 MiB peak process RSS). The first sampled passing call above 100 ms used 2,048 (120 ms). The runs did not locate a ceiling for this family. A cubic integrates exactly under Simpson’s rule. Other integrands need an error estimate, smoothness conditions and checks near singular endpoints.
Measured times, memory and outcomes
Simpson panels · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
4.67
75.8
2
Baseline
Passed
5.06
75.8
4
Baseline
Passed
5.80
75.6
10
Baseline
Passed
10.20
76.9
32
Stretch
Passed
8.77
77.8
128
Stretch
Passed
19.65
87.5
512
Stretch
Passed
37.54
90.1
2,048
Stretch
Passed
120
90.9
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.richardson · 1 passing test case, 1 distinct argument description
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. About 2–20 nodes for explicit polynomial interpolation or low-degree least-squares fits; clustered nodes change conditioning.
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
What degree-one polynomial interpolates f(0)=1 and f(2)=5?
Worked solution
Its slope is (5−1)/2=2 and the intercept is 1, so p(x)=1+2x.
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { R } from "@ratmath/core";
console.log(String(R`(5-1)/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. About 2–20 nodes for explicit polynomial interpolation or low-degree least-squares fits; clustered nodes change conditioning.
Focal example. The code above passed its displayed check in 0.087 ms on Node.
Same arithmetic expression. Replaced its first numeral 5 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.add · denominator. Baseline test points across courses 1, 2, 3, 12, 100, 1,000. Cross-multiply 1/n + 1/(n+1) against (2n+1)/(n(n+1)).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000,007 (0.038 ms, 76.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact work depends on the bit lengths of both numerator and denominator. A long sum of relatively prime fractions can build a large common denominator.
Measured times, memory and outcomes
denominator · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.034
74.9
2
Baseline
Passed
0.036
75.6
3
Baseline
Passed
0.040
75.9
12
Baseline
Passed
0.039
75.2
100
Baseline
Passed
0.041
75
1,000
Baseline
Passed
0.035
75.8
1,000,003
Stretch
Passed
0.044
75
1,000,000,007
Stretch
Passed
0.038
76.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
Why can increasing the degree on equally spaced nodes worsen the sup-norm interpolation error?
Worked solution
High-degree basis functions can amplify oscillations near the ends. Compare the error there with a Chebyshev-node or piecewise approximation.
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–20 nodes for explicit polynomial interpolation or low-degree least-squares fits; clustered nodes change conditioning.
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 · Quadrature
Trapezoid rule
Direct calculation@ratmath/analytic
Problem
Approximate by the trapezoid rule with 4 panels.
Worked solution
(exact ).
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.quadratureRule("x^2", ["0", "1"], { rule: "trapezoid", n: 4 }).value);
Checked output
11/32
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. A few to a few hundred panels, a low-degree polynomial or smooth test function, and a specified error criterion.
Focal example. The code above passed its displayed check in 0.556 ms on Node.
Same API, measured input family.analytic.quadratureRule · Simpson panels. Baseline test points across courses 1, 2, 4, 10. Simpson's rule integrates x³ on [0,1] exactly, giving 1/4 at every panel count.
Practical limit. Largest passing sample 2,048 (120 ms, 90.9 MiB peak process RSS). The first sampled passing call above 100 ms used 2,048 (120 ms). The runs did not locate a ceiling for this family. A cubic integrates exactly under Simpson’s rule. Other integrands need an error estimate, smoothness conditions and checks near singular endpoints.
Measured times, memory and outcomes
Simpson panels · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
4.67
75.8
2
Baseline
Passed
5.06
75.8
4
Baseline
Passed
5.80
75.6
10
Baseline
Passed
10.20
76.9
32
Stretch
Passed
8.77
77.8
128
Stretch
Passed
19.65
87.5
512
Stretch
Passed
37.54
90.1
2,048
Stretch
Passed
120
90.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.
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.quadratureRule · 1 passing test case, 3 distinct argument descriptions
Apply Simpson's rule with one panel (three points) to .
Worked solution
(exact ).
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.quadratureRule("x^4", ["0", "1"], { rule: "simpson", n: 1 }).value);
Checked output
5/24
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. A few to a few hundred panels, a low-degree polynomial or smooth test function, and a specified error criterion.
Focal example. The code above passed its displayed check in 0.375 ms on Node.
Same API, measured input family.analytic.quadratureRule · Simpson panels. Baseline test points across courses 1, 2, 4, 10. Simpson's rule integrates x³ on [0,1] exactly, giving 1/4 at every panel count.
Practical limit. Largest passing sample 2,048 (120 ms, 90.9 MiB peak process RSS). The first sampled passing call above 100 ms used 2,048 (120 ms). The runs did not locate a ceiling for this family. A cubic integrates exactly under Simpson’s rule. Other integrands need an error estimate, smoothness conditions and checks near singular endpoints.
Measured times, memory and outcomes
Simpson panels · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
4.67
75.8
2
Baseline
Passed
5.06
75.8
4
Baseline
Passed
5.80
75.6
10
Baseline
Passed
10.20
76.9
32
Stretch
Passed
8.77
77.8
128
Stretch
Passed
19.65
87.5
512
Stretch
Passed
37.54
90.1
2,048
Stretch
Passed
120
90.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.
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.quadratureRule · 1 passing test case, 3 distinct argument descriptions
Nodes , weights 1: (exact ; the rule is exact only up to degree 3).
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as analytic from "@ratmath/analytic";
console.log(analytic.gaussRule("x^4", ["-1", "1"], 2).value);
Checked output
0.2222222222222222222[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. A few to a few hundred panels, a low-degree polynomial or smooth test function, and a specified error criterion.
Focal example. The code above passed its displayed check in 3.34 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.analytic.quadratureRule · Simpson panels. Baseline test points across courses 1, 2, 4, 10. Simpson's rule integrates x³ on [0,1] exactly, giving 1/4 at every panel count.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 2,048 (120 ms, 90.9 MiB peak process RSS). The first sampled passing call above 100 ms used 2,048 (120 ms). The runs did not locate a ceiling for this family. A cubic integrates exactly under Simpson’s rule. Other integrands need an error estimate, smoothness conditions and checks near singular endpoints.
Measured times, memory and outcomes
Simpson panels · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
4.67
75.8
2
Baseline
Passed
5.06
75.8
4
Baseline
Passed
5.80
75.6
10
Baseline
Passed
10.20
76.9
32
Stretch
Passed
8.77
77.8
128
Stretch
Passed
19.65
87.5
512
Stretch
Passed
37.54
90.1
2,048
Stretch
Passed
120
90.9
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.gaussRule · 1 passing test case, 1 distinct argument description
Direct calculation@ratmath/symbolic · @ratmath/core
Problem
Use Simpson's rule with to estimate . Compare with the exact value.
Worked solution
; exact .
Using RatMath
Pass the integrand and variable separately. Finite bounds request a definite integral. For an antiderivative, differentiate the proposed expression on its domain.
JavaScript module
import * as symbolic from "@ratmath/symbolic";
import { R } from "@ratmath/core";
const f = (x) => R`1/(1 + ${x}^2)`, h = R`1/4`;
const S = h.divide(R`3`).multiply(f(0).add(R`4`.multiply(f(h))).add(R`2`.multiply(f(R`1/2`))).add(R`4`.multiply(f(R`3/4`))).add(f(1)));
console.log([S, symbolic.integrate("1/(1 + x^2)", "x", { from: 0, to: 1 }).value]);
Checked output
[8011/10200, pi/4]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. A few to a few hundred panels, a low-degree polynomial or smooth test function, and a specified error criterion.
For this problem type. Use a low-degree or elementary integrand and one to three integration variables, with one interval per dimension or a few piecewise bounds.
Focal example. The code above passed its displayed check in 10.09 ms on Node.
Same API, measured input family.symbolic.integrate · degree. Baseline test points across courses 0, 1, 2, 5, 10. The integral of x^n over [0,1] is 1/(n+1).
Practical limit. Largest passing sample 500 (195 ms, 88.7 MiB peak process RSS). The first sampled passing call above 100 ms used 500 (195 ms). The runs did not locate a ceiling for this family. Polynomial primitives are a favorable case. Singular endpoints, non-elementary primitives and unevaluated integrals need separate treatment.
Measured times, memory and outcomes
degree · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
5.98
75.7
1
Baseline
Passed
8.66
75.9
2
Baseline
Passed
7.14
75.7
5
Baseline
Passed
9.22
75.5
10
Baseline
Passed
8.48
75.8
30
Stretch
Passed
56.11
88.9
100
Stretch
Passed
78.06
88.4
500
Stretch
Passed
195
88.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.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
symbolic.integrate · 11 passing test cases, 47 distinct argument descriptions
Bound the error of the degree-4 Taylor polynomial of about 0 on , and compare with the true error.
Worked solution
Lagrange: . The true maximum error, at , 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 T = analytic.taylorRemainder("exp(x)", { order: 4, on: ["0", "1"] });
console.log([T.bound, T.actual]);
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. A few to a few hundred panels, a low-degree polynomial or smooth test function, and a specified error criterion.
For this problem type. Typical hand calculations keep 2–10 nonzero terms. Specify the expansion center and distance of the evaluation point from it.
Focal example. The code above passed its displayed check in 346 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Related workload in this unit.analytic.quadratureRule · Simpson panels. Baseline test points across courses 1, 2, 4, 10. Simpson's rule integrates x³ on [0,1] exactly, giving 1/4 at every panel count.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 2,048 (120 ms, 90.9 MiB peak process RSS). The first sampled passing call above 100 ms used 2,048 (120 ms). The runs did not locate a ceiling for this family. A cubic integrates exactly under Simpson’s rule. Other integrands need an error estimate, smoothness conditions and checks near singular endpoints.
Measured times, memory and outcomes
Simpson panels · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
4.67
75.8
2
Baseline
Passed
5.06
75.8
4
Baseline
Passed
5.80
75.6
10
Baseline
Passed
10.20
76.9
32
Stretch
Passed
8.77
77.8
128
Stretch
Passed
19.65
87.5
512
Stretch
Passed
37.54
90.1
2,048
Stretch
Passed
120
90.9
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.taylorRemainder · 1 passing test case, 1 distinct argument description
Compute the lower and upper sums of on with four equal pieces.
Worked solution
is increasing: , .
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 d = analytic.darboux("x^2", { interval: [0, 1], n: 4 });
console.log([d.lower, d.upper, d.exact]);
Checked output
[7/32, 15/32, 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. A few to a few hundred panels, a low-degree polynomial or smooth test function, and a specified error criterion.
Focal example. The code above passed its displayed check in 1.14 ms on Node.
Related workload in this unit.symbolic.integrate · degree. Baseline test points across courses 0, 1, 2, 5, 10. The integral of x^n over [0,1] is 1/(n+1).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 500 (195 ms, 88.7 MiB peak process RSS). The first sampled passing call above 100 ms used 500 (195 ms). The runs did not locate a ceiling for this family. Polynomial primitives are a favorable case. Singular endpoints, non-elementary primitives and unevaluated integrals need separate treatment.
Measured times, memory and outcomes
degree · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
5.98
75.7
1
Baseline
Passed
8.66
75.9
2
Baseline
Passed
7.14
75.7
5
Baseline
Passed
9.22
75.5
10
Baseline
Passed
8.48
75.8
30
Stretch
Passed
56.11
88.9
100
Stretch
Passed
78.06
88.4
500
Stretch
Passed
195
88.7
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
analytic.darboux · 6 passing test cases, 6 distinct argument descriptions
An O(h²) rule returns 1.40 at h and 1.25 at h/2. Estimate the extrapolated limit.
Worked solution
Cancelling the leading quadratic term gives (4·1.25−1.40)/3 = 1.20.
Using RatMath
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { R } from "@ratmath/core";
console.log(String(R`(4*1.25-1.40)/3`));
Checked output
6/5
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. A few to a few hundred panels, a low-degree polynomial or smooth test function, and a specified error criterion.
Focal example. The code above passed its displayed check in 0.123 ms on Node.
Same arithmetic expression. Replaced its first numeral 4 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.add · denominator. Baseline test points across courses 1, 2, 3, 12, 100, 1,000. Cross-multiply 1/n + 1/(n+1) against (2n+1)/(n(n+1)).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000,007 (0.038 ms, 76.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact work depends on the bit lengths of both numerator and denominator. A long sum of relatively prime fractions can build a large common denominator.
Measured times, memory and outcomes
denominator · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.034
74.9
2
Baseline
Passed
0.036
75.6
3
Baseline
Passed
0.040
75.9
12
Baseline
Passed
0.039
75.2
100
Baseline
Passed
0.041
75
1,000
Baseline
Passed
0.035
75.8
1,000,003
Stretch
Passed
0.044
75
1,000,000,007
Stretch
Passed
0.038
76.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
The trapezoid errors on mesh widths h and h/2 are approximately 0.08 and 0.02. What order does their ratio suggest?
Worked solution
The error decreased by a factor of four when the width halved. An hᵖ law therefore suggests p=2. Two measurements alone do not prove the asymptotic order.
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`0.08/0.02`));
Checked output
4
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. A few to a few hundred panels, a low-degree polynomial or smooth test function, and a specified error criterion.
Focal example. The code above passed its displayed check in 0.070 ms on Node.
Same arithmetic expression. Replaced its first numeral 0.08 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.add · denominator. Baseline test points across courses 1, 2, 3, 12, 100, 1,000. Cross-multiply 1/n + 1/(n+1) against (2n+1)/(n(n+1)).
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,000,007 (0.038 ms, 76.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact work depends on the bit lengths of both numerator and denominator. A long sum of relatively prime fractions can build a large common denominator.
Measured times, memory and outcomes
denominator · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.034
74.9
2
Baseline
Passed
0.036
75.6
3
Baseline
Passed
0.040
75.9
12
Baseline
Passed
0.039
75.2
100
Baseline
Passed
0.041
75
1,000
Baseline
Passed
0.035
75.8
1,000,003
Stretch
Passed
0.044
75
1,000,000,007
Stretch
Passed
0.038
76.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
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.odeMethod("y", { y0: 1, until: "0.5", steps: 5 }).steps.at(-1).y);
Checked output
1.61051
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. Typically tens to hundreds of time steps or small exact linear systems; stability depends on step size times spectral scale.
For this problem type. Use a scalar ODE or a two-state system with a short time interval. Hand traces use a few steps and classroom comparisons commonly use 10–100.
Focal example. The code above passed its displayed check in 6.11 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Same API, measured input family.analytic.odeMethod · Euler steps. Baseline test points across courses 1, 4, 10, 50. For y′=y and h=1/n, check the floating Euler iterate against exp(n log1p(1/n)) within 10⁻¹¹. Method error relative to e is separate.
Practical limit. Largest passing sample 1,000 (292 ms, 90.4 MiB peak process RSS). The first sampled passing call above 100 ms used 300 (117 ms). The runs did not locate a ceiling for this family. Smaller steps reduce Euler truncation error for a suitably stable problem. The teaching trace uses doubles. Stiff equations can require vastly smaller steps.
Measured times, memory and outcomes
Euler steps · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
51.00
90.3
4
Baseline
Passed
34.01
89.8
10
Baseline
Passed
36.24
89.6
50
Baseline
Passed
61.43
89.9
100
Stretch
Passed
66.45
90.3
300
Stretch
Passed
117
89.3
1,000
Stretch
Passed
292
90.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.
analytic.odeMethod · 1 passing test case, 1 distinct argument description
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.odeMethod("y", { y0: 1, until: "0.1", steps: 1, method: "rk4" }).steps.at(-1).y
);
Checked output
1.1051708333333332
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. Typically tens to hundreds of time steps or small exact linear systems; stability depends on step size times spectral scale.
For this problem type. Use a scalar ODE or a two-state system with a short time interval. Hand traces use a few steps and classroom comparisons commonly use 10–100.
Focal example. The code above passed its displayed check in 2.77 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
Same API, measured input family.analytic.odeMethod · Euler steps. Baseline test points across courses 1, 4, 10, 50. For y′=y and h=1/n, check the floating Euler iterate against exp(n log1p(1/n)) within 10⁻¹¹. Method error relative to e is separate.
Practical limit. Largest passing sample 1,000 (292 ms, 90.4 MiB peak process RSS). The first sampled passing call above 100 ms used 300 (117 ms). The runs did not locate a ceiling for this family. Smaller steps reduce Euler truncation error for a suitably stable problem. The teaching trace uses doubles. Stiff equations can require vastly smaller steps.
Measured times, memory and outcomes
Euler steps · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
51.00
90.3
4
Baseline
Passed
34.01
89.8
10
Baseline
Passed
36.24
89.6
50
Baseline
Passed
61.43
89.9
100
Stretch
Passed
66.45
90.3
300
Stretch
Passed
117
89.3
1,000
Stretch
Passed
292
90.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.
analytic.odeMethod · 1 passing test case, 1 distinct argument description
For , what is the largest step for which Euler's method does not grow?
Worked solution
Each step multiplies by ; needs . The stability interval for 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 s = analytic.stability("euler");
console.log([s.interval, s.largestStep(-10)]);
Checked output
[[-2, 0], 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. Typically tens to hundreds of time steps or small exact linear systems; stability depends on step size times spectral scale.
Focal example. The code above passed its displayed check in 0.323 ms on Node.
Related workload in this unit.analytic.odeMethod · Euler steps. Baseline test points across courses 1, 4, 10, 50. For y′=y and h=1/n, check the floating Euler iterate against exp(n log1p(1/n)) within 10⁻¹¹. Method error relative to e is separate.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000 (292 ms, 90.4 MiB peak process RSS). The first sampled passing call above 100 ms used 300 (117 ms). The runs did not locate a ceiling for this family. Smaller steps reduce Euler truncation error for a suitably stable problem. The teaching trace uses doubles. Stiff equations can require vastly smaller steps.
Measured times, memory and outcomes
Euler steps · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
51.00
90.3
4
Baseline
Passed
34.01
89.8
10
Baseline
Passed
36.24
89.6
50
Baseline
Passed
61.43
89.9
100
Stretch
Passed
66.45
90.3
300
Stretch
Passed
117
89.3
1,000
Stretch
Passed
292
90.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.stability · 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 linalg from "@ratmath/linalg";
const F = linalg.lu([[2, 1], [4, 3]]).exact();
console.log([F.L, F.U].map(String));
Checked output
["[1, 0]\n[2, 1]", "[2, 1]\n[0, 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. Typically tens to hundreds of time steps or small exact linear systems; stability depends on step size times spectral scale.
For this problem type. Hand calculations usually use 2–5 rows and columns with small integer or rational entries. Include deficient rank as a separate case.
Focal example. The code above passed its displayed check in 0.428 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.lu · 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. Typically tens to hundreds of time steps or small exact linear systems; stability depends on step size times spectral scale.
Focal example. The code above passed its displayed check in 7.49 ms on Node. Both enclosure endpoints also met the lesson’s stated numerical tolerance.
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.methods.jacobi · 3 passing test cases, 8 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.odeMethod("y", { method: "euler", y0: 1, until: 1, steps: 4 }).steps.at(-1).y
);
Checked output
2.44140625
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. Typically tens to hundreds of time steps or small exact linear systems; stability depends on step size times spectral scale.
For this problem type. Use a scalar ODE or a two-state system with a short time interval. Hand traces use a few steps and classroom comparisons commonly use 10–100.
Focal example. The code above passed its displayed check in 20.19 ms on Node.
Same API, measured input family.analytic.odeMethod · Euler steps. Baseline test points across courses 1, 4, 10, 50. For y′=y and h=1/n, check the floating Euler iterate against exp(n log1p(1/n)) within 10⁻¹¹. Method error relative to e is separate.
Practical limit. Largest passing sample 1,000 (292 ms, 90.4 MiB peak process RSS). The first sampled passing call above 100 ms used 300 (117 ms). The runs did not locate a ceiling for this family. Smaller steps reduce Euler truncation error for a suitably stable problem. The teaching trace uses doubles. Stiff equations can require vastly smaller steps.
Measured times, memory and outcomes
Euler steps · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
51.00
90.3
4
Baseline
Passed
34.01
89.8
10
Baseline
Passed
36.24
89.6
50
Baseline
Passed
61.43
89.9
100
Stretch
Passed
66.45
90.3
300
Stretch
Passed
117
89.3
1,000
Stretch
Passed
292
90.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.
analytic.odeMethod · 1 passing test case, 1 distinct argument description
For y′=−4y, find the positive h for which the Euler amplification has magnitude strictly below 1.
Worked solution
Solve |1−4h|<1. This gives 0<h<1/2. At equality the numerical solution oscillates without decay.
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. Typically tens to hundreds of time steps or small exact linear systems; stability depends on step size times spectral scale.
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 · ODEs and linear systems
Pivoting
Direct calculation@ratmath/linalg
Problem
Does zero in the first diagonal entry of [[0,1],[1,0]] imply singularity?
Worked solution
The determinant is −1. Swap the rows before elimination.
Using RatMath
Enter the matrix one row at a time, preserving the order of the unknowns. Use the result with the original matrix to check the required relation.
JavaScript module
import * as linalg from "@ratmath/linalg";
console.log(String(linalg.det([[0,1],[1,0]]).exact()));
Checked output
-1
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Typically tens to hundreds of time steps or small exact linear systems; stability depends on step size times spectral scale.
For this problem type. Hand calculations usually use 2–5 rows and columns with small integer or rational entries. Include deficient rank as a separate case.
Focal example. The code above passed its displayed check in 0.261 ms on Node.
Same API, measured input family.linalg.det.exact · square matrix side. Baseline test points across courses 1, 2, 3, 5, 10. Dense matrix I+J has eigenvalues 1 (n−1 times) and n+1.
Practical limit. Largest passing sample 200 (383 ms, 131.8 MiB peak process RSS). The first sampled passing call above 100 ms used 200 (383 ms). The runs did not locate a ceiling for this family. Even with small dimensions, large integer minors increase the cost of exact elimination. The dense structured fixture has small entries.
Measured times, memory and outcomes
square matrix side · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
1
Baseline
Passed
0.731
76.1
2
Baseline
Passed
0.810
74.8
3
Baseline
Passed
0.876
75.2
5
Baseline
Passed
1.32
75.4
10
Baseline
Passed
1.58
76.1
25
Stretch
Passed
7.10
77.5
50
Stretch
Passed
21.28
81.7
100
Stretch
Passed
67.11
90.3
200
Stretch
Passed
383
131.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.
linalg.det · 19 passing test cases, 22 distinct argument descriptions