35 of 40 focal problems use RatMath for a calculation or a substantive step.
Direct calculation
32 · 80%
Assisted
3 · 7.5%
Worked by hand
5 · 12.5%
Using the packages
Exact integers and modular routines support calculations and witness checks. Success on a list of primes cannot establish a statement quantified over every prime.
Calculator interface
Keep the modulus attached to every residue. Offer extended-Euclid steps, probable-prime versus proven-prime labels and a separate pane to replay certificates.
Each of the 40 focal problems has equal weight. Direct means the displayed package calculation answers the computational question after the inputs are set up. Assisted means it contributes a step and the worked solution supplies essential reasoning, interpretation or selection. Worked by hand means the guide relies on a construction, argument or judgment for that task. The helpful share combines direct and assisted days. Courses and instructors assign different mixes of problems. The percentages describe this syllabus.
Classroom inputs and practical limits
35 of 40 days include a checked executable example. On 10 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 · Divisibility and congruence. Integer operands from units to thousands in hand examples, with several congruences and small moduli.
Unit benchmark · numtheory.gcd, operand bits. Largest passing sample 32,768 (0.183 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 9–16 · Primes and arithmetic functions. Integers often up to 10⁴ for hand factorization and larger known-factor examples in computational work.
Unit benchmark · numtheory.factor, known semiprime. Largest passing sample 1,000,036,000,099 (5.12 ms, 77 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 17–24 · Quadratic and multiplicative residues. Small primes or odd moduli, usually below a few hundred in hand examples; specify whether inverses and square roots exist.
Unit benchmark · numtheory.modPow, exponent bits. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 25–32 · Primality and representation. Small primes, pseudoprimes or deliberately chosen products; difficulty depends strongly on the least factor.
Unit benchmark · numtheory.factor, known semiprime. Largest passing sample 1,000,036,000,099 (5.12 ms, 77 MiB peak process RSS). The runs did not locate a ceiling for this family.
Days 33–40 · Diophantine methods. Two to four integer coefficients in a linear equation, continued fractions of modest period or small quadratic discriminants.
Unit benchmark · numtheory.gcd, operand bits. Largest passing sample 32,768 (0.183 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family.
, , , . So the gcd is 18, and back-substituting gives .
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 numtheory from "@ratmath/numtheory";
console.log(numtheory.egcd(252, 198));
Checked output
{ g: 18n, x: 4n, y: -5n }
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Integer operands from units to thousands in hand examples, with several congruences and small moduli.
Focal example. The code above passed its displayed check in 0.063 ms on Node.
Related workload in this unit.numtheory.gcd · operand bits. Baseline test points across courses 4, 8, 16, 32. Consecutive integers m,m+1 are coprime, so gcd(7m,7(m+1))=7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 32,768 (0.183 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Euclidean reduction depends on operand size and their quotient sequence. Consecutive Fibonacci numbers need more steps than many inputs of the same bit length.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
4
Baseline
Passed
0.171
74.8
8
Baseline
Passed
0.132
74.7
16
Baseline
Passed
0.129
74.8
32
Baseline
Passed
0.131
76.2
256
Stretch
Passed
0.124
74.5
4,096
Stretch
Passed
0.165
74.9
32,768
Stretch
Passed
0.183
75.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.egcd · 1 passing test case, 3 distinct argument descriptions
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.solveLinear(17, 3, 29).solutions);
Checked output
[7n]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Integer operands from units to thousands in hand examples, with several congruences and small moduli.
Focal example. The code above passed its displayed check in 0.189 ms on Node.
Related workload in this unit.numtheory.gcd · operand bits. Baseline test points across courses 4, 8, 16, 32. Consecutive integers m,m+1 are coprime, so gcd(7m,7(m+1))=7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 32,768 (0.183 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Euclidean reduction depends on operand size and their quotient sequence. Consecutive Fibonacci numbers need more steps than many inputs of the same bit length.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
4
Baseline
Passed
0.171
74.8
8
Baseline
Passed
0.132
74.7
16
Baseline
Passed
0.129
74.8
32
Baseline
Passed
0.131
76.2
256
Stretch
Passed
0.124
74.5
4,096
Stretch
Passed
0.165
74.9
32,768
Stretch
Passed
0.183
75.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.solveLinear · 1 passing test case, 6 distinct argument descriptions
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.crt([2, 3, 2], [3, 5, 7]));
Checked output
{ x: 23n, modulus: 105n }
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Integer operands from units to thousands in hand examples, with several congruences and small moduli.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.067 ms on Node.
Related workload in this unit.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.crt · 2 passing test cases, 12 distinct argument descriptions
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.modPow(7n, 222n, 11n));
Checked output
5n
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Integer operands from units to thousands in hand examples, with several congruences and small moduli.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.128 ms on Node.
Same API, measured input family.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.modPow · 4 passing test cases, 22 distinct argument descriptions
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.modInverse(17n, 43n));
Checked output
38n
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Integer operands from units to thousands in hand examples, with several congruences and small moduli.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.144 ms on Node.
Related workload in this unit.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.modInverse · 1 passing test case, 6 distinct argument descriptions
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.crt([2, 3, 2], [3, 5, 7]));
Checked output
{ x: 23n, modulus: 105n }
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Integer operands from units to thousands in hand examples, with several congruences and small moduli.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.193 ms on Node.
Related workload in this unit.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.crt · 2 passing test cases, 12 distinct argument descriptions
A solution exists exactly when gcd(a,m) divides b. Divide by that gcd to obtain an invertible coefficient modulo the reduced modulus.
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. Integer operands from units to thousands in hand examples, with several congruences and small moduli.
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 · Divisibility and congruence
Noncoprime moduli
Assisted@ratmath/numtheory
Problem
Can x≡1 mod 4 and x≡2 mod 6 hold simultaneously?
Worked solution
A shared solution would have to be both odd and even. The residues disagree modulo gcd(4,6)=2.
Using RatMath
Use the result for the computational step. The worked solution explains the remaining mathematical inference.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.gcd(4,6));
Checked output
2n
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. Integer operands from units to thousands in hand examples, with several congruences and small moduli.
Focal example. The code above passed its displayed check in 0.086 ms on Node.
Same API, measured input family.numtheory.gcd · operand bits. Baseline test points across courses 4, 8, 16, 32. Consecutive integers m,m+1 are coprime, so gcd(7m,7(m+1))=7.
Practical limit. Largest passing sample 32,768 (0.183 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Euclidean reduction depends on operand size and their quotient sequence. Consecutive Fibonacci numbers need more steps than many inputs of the same bit length.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
4
Baseline
Passed
0.171
74.8
8
Baseline
Passed
0.132
74.7
16
Baseline
Passed
0.129
74.8
32
Baseline
Passed
0.131
76.2
256
Stretch
Passed
0.124
74.5
4,096
Stretch
Passed
0.165
74.9
32,768
Stretch
Passed
0.183
75.3
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.gcd · 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 numtheory from "@ratmath/numtheory";
console.log(numtheory.totient(360));
Checked output
96n
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. Integers often up to 10⁴ for hand factorization and larger known-factor examples in computational work.
For this problem type. Typical hand examples are positive integers up to thousands. For computation, distinguish a known-factor input or prime-count endpoint from a hard semiprime.
Focal example. The code above passed its displayed check in 0.124 ms on Node.
Related workload in this unit.numtheory.factor · known semiprime. Baseline test points across courses 15, 77, 899, 10,403. Recover both planted prime factors, including exponent one.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,036,000,099 (5.12 ms, 77 MiB peak process RSS). The runs did not locate a ceiling for this family. Equal-length integers can have very different factoring times. These planted semiprimes give sample timings, with no general bound for the next integer.
Measured times, memory and outcomes
known semiprime · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
15
Baseline
Passed
0.331
76
77
Baseline
Passed
0.309
76.3
899
Baseline
Passed
0.298
74.9
10,403
Baseline
Passed
0.327
75.7
1,022,117
Stretch
Passed
0.397
75.8
100,160,063
Stretch
Passed
0.922
75.4
1,000,036,000,099
Stretch
Passed
5.12
77
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.totient · 1 passing test case, 6 distinct argument descriptions
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.modPow(3, 100, 7));
Checked output
4n
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. Integers often up to 10⁴ for hand factorization and larger known-factor examples in computational work.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.047 ms on Node.
Same API, measured input family.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.modPow · 4 passing test cases, 22 distinct argument descriptions
Divisors 1, 2, 4, 7, 14, 28: , , so 28 is perfect.
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 numtheory from "@ratmath/numtheory";
console.log([numtheory.sigma(28), numtheory.tau(28), numtheory.isPerfect(28)]);
Checked output
[56n, 6n, 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. Integers often up to 10⁴ for hand factorization and larger known-factor examples in computational work.
For this problem type. Typical hand examples are positive integers up to thousands. For computation, distinguish a known-factor input or prime-count endpoint from a hard semiprime.
Focal example. The code above passed its displayed check in 0.209 ms on Node.
Related workload in this unit.numtheory.factor · known semiprime. Baseline test points across courses 15, 77, 899, 10,403. Recover both planted prime factors, including exponent one.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,036,000,099 (5.12 ms, 77 MiB peak process RSS). The runs did not locate a ceiling for this family. Equal-length integers can have very different factoring times. These planted semiprimes give sample timings, with no general bound for the next integer.
Measured times, memory and outcomes
known semiprime · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
15
Baseline
Passed
0.331
76
77
Baseline
Passed
0.309
76.3
899
Baseline
Passed
0.298
74.9
10,403
Baseline
Passed
0.327
75.7
1,022,117
Stretch
Passed
0.397
75.8
100,160,063
Stretch
Passed
0.922
75.4
1,000,036,000,099
Stretch
Passed
5.12
77
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.sigma · 1 passing test case, 6 distinct argument descriptions
has three distinct primes: . has a square factor: .
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 numtheory from "@ratmath/numtheory";
console.log([numtheory.mobius(30), numtheory.mobius(12)]);
Checked output
[-1n, 0n]
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. Integers often up to 10⁴ for hand factorization and larger known-factor examples in computational work.
For this problem type. Typical hand examples are positive integers up to thousands. For computation, distinguish a known-factor input or prime-count endpoint from a hard semiprime.
Focal example. The code above passed its displayed check in 0.100 ms on Node.
Related workload in this unit.numtheory.factor · known semiprime. Baseline test points across courses 15, 77, 899, 10,403. Recover both planted prime factors, including exponent one.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,036,000,099 (5.12 ms, 77 MiB peak process RSS). The runs did not locate a ceiling for this family. Equal-length integers can have very different factoring times. These planted semiprimes give sample timings, with no general bound for the next integer.
Measured times, memory and outcomes
known semiprime · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
15
Baseline
Passed
0.331
76
77
Baseline
Passed
0.309
76.3
899
Baseline
Passed
0.298
74.9
10,403
Baseline
Passed
0.327
75.7
1,022,117
Stretch
Passed
0.397
75.8
100,160,063
Stretch
Passed
0.922
75.4
1,000,036,000,099
Stretch
Passed
5.12
77
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.mobius · 1 passing test case, 6 distinct argument descriptions
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.factorialValuation(100, 2));
Checked output
97
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. Integers often up to 10⁴ for hand factorization and larger known-factor examples in computational work.
For this problem type. Typical hand examples are positive integers up to thousands. For computation, distinguish a known-factor input or prime-count endpoint from a hard semiprime.
Focal example. The code above passed its displayed check in 0.133 ms on Node.
Related workload in this unit.numtheory.factor · known semiprime. Baseline test points across courses 15, 77, 899, 10,403. Recover both planted prime factors, including exponent one.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,036,000,099 (5.12 ms, 77 MiB peak process RSS). The runs did not locate a ceiling for this family. Equal-length integers can have very different factoring times. These planted semiprimes give sample timings, with no general bound for the next integer.
Measured times, memory and outcomes
known semiprime · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
15
Baseline
Passed
0.331
76
77
Baseline
Passed
0.309
76.3
899
Baseline
Passed
0.298
74.9
10,403
Baseline
Passed
0.327
75.7
1,022,117
Stretch
Passed
0.397
75.8
100,160,063
Stretch
Passed
0.922
75.4
1,000,036,000,099
Stretch
Passed
5.12
77
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.factorialValuation · 3 passing test cases, 13 distinct argument descriptions
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.primePi(1000));
Checked output
168n
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. Integers often up to 10⁴ for hand factorization and larger known-factor examples in computational work.
For this problem type. Typical hand examples are positive integers up to thousands. For computation, distinguish a known-factor input or prime-count endpoint from a hard semiprime.
Focal example. The code above passed its displayed check in 0.135 ms on Node.
Same API, measured input family.numtheory.primePi · upper endpoint. Baseline test points across courses 10, 100, 1,000, 10,000. Compare with known π(10^k) values 4,25,168,1229,9592,78498,664579.
Practical limit. Largest passing sample 10,000,000 (20.56 ms, 81 MiB peak process RSS). The runs did not locate a ceiling for this family. Sieving trades storage for time as the endpoint grows. Counting primes and listing or factoring large integers are different workloads.
Measured times, memory and outcomes
upper endpoint · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
10
Baseline
Passed
0.185
75.3
100
Baseline
Passed
0.163
75.4
1,000
Baseline
Passed
0.235
74.5
10,000
Baseline
Passed
0.678
75.6
100,000
Stretch
Passed
2.63
75.4
1,000,000
Stretch
Passed
4.67
76.1
10,000,000
Stretch
Passed
20.56
81
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.primePi · 3 passing test cases, 17 distinct argument descriptions
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Integers often up to 10⁴ for hand factorization and larger known-factor examples in computational work.
For this problem type. Typical hand examples are positive integers up to thousands. For computation, distinguish a known-factor input or prime-count endpoint from a hard semiprime.
Focal example. The code above passed its displayed check in 0.374 ms on Node.
Related workload in this unit.numtheory.factor · known semiprime. Baseline test points across courses 15, 77, 899, 10,403. Recover both planted prime factors, including exponent one.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,036,000,099 (5.12 ms, 77 MiB peak process RSS). The runs did not locate a ceiling for this family. Equal-length integers can have very different factoring times. These planted semiprimes give sample timings, with no general bound for the next integer.
Measured times, memory and outcomes
known semiprime · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
15
Baseline
Passed
0.331
76
77
Baseline
Passed
0.309
76.3
899
Baseline
Passed
0.298
74.9
10,403
Baseline
Passed
0.327
75.7
1,022,117
Stretch
Passed
0.397
75.8
100,160,063
Stretch
Passed
0.922
75.4
1,000,036,000,099
Stretch
Passed
5.12
77
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.isPrime · 4 passing test cases, 14 distinct argument descriptions
Why does adding one to a product of finitely many primes rule out a complete finite prime list?
Worked solution
Every listed prime leaves remainder one. Any prime divisor of the new integer is outside the list, even when the new integer is composite.
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. Integers often up to 10⁴ for hand factorization and larger known-factor examples in computational work.
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 · Quadratic and multiplicative residues
Legendre symbol
Direct calculation@ratmath/numtheory
Problem
Evaluate .
Worked solution
By reciprocity . (Indeed .)
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 numtheory from "@ratmath/numtheory";
console.log(numtheory.legendre(5, 11));
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. Small primes or odd moduli, usually below a few hundred in hand examples; specify whether inverses and square roots exist.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.110 ms on Node.
Related workload in this unit.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.legendre · 1 passing test case, 6 distinct argument descriptions
Day 18 / 40 · Quadratic and multiplicative residues
Jacobi symbol
Direct calculation@ratmath/numtheory
Problem
Evaluate the Jacobi symbol . Is 2 a square mod 15?
Worked solution
, but 2 is not a square mod 3, so it is not a square mod 15: the Jacobi symbol 1 does not imply a square.
Using RatMath
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log([numtheory.jacobi(2, 15), numtheory.sqrtsMod(2, 15)]);
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. Small primes or odd moduli, usually below a few hundred in hand examples; specify whether inverses and square roots exist.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.337 ms on Node.
Related workload in this unit.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.jacobi · 1 passing test case, 6 distinct argument descriptions
Day 19 / 40 · Quadratic and multiplicative residues
Square roots mod p
Direct calculation@ratmath/numtheory
Problem
Solve .
Worked solution
, so , that is 6 and 7.
Using RatMath
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.sqrtsMod(10, 13));
Checked output
[6n, 7n]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes or odd moduli, usually below a few hundred in hand examples; specify whether inverses and square roots exist.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.131 ms on Node.
Related workload in this unit.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.sqrtsMod · 1 passing test case, 6 distinct argument descriptions
Day 20 / 40 · Quadratic and multiplicative residues
Order of an element
Direct calculation@ratmath/numtheory
Problem
Find the multiplicative order of 2 modulo 11.
Worked solution
The order divides 10. , , so the order is 10.
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 numtheory from "@ratmath/numtheory";
console.log(numtheory.multiplicativeOrder(2, 11));
Checked output
10n
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes or odd moduli, usually below a few hundred in hand examples; specify whether inverses and square roots exist.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.198 ms on Node.
Same API, measured input family.numtheory.multiplicativeOrder · prime modulus. Baseline test points across courses 3, 5, 7, 11, 23. Compute the order by multiplying 2 repeatedly modulo p until the first return to 1.
Practical limit. Largest passing sample 10,007 (0.475 ms, 74.3 MiB peak process RSS). The runs did not locate a ceiling for this family. The least positive exponent requires a unit modulo the modulus. Modular factoring and order structure affect running time.
Measured times, memory and outcomes
prime modulus · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
0.281
75.7
5
Baseline
Passed
0.413
76.2
7
Baseline
Passed
0.300
74.5
11
Baseline
Passed
0.352
74.9
23
Baseline
Passed
0.338
75.6
101
Stretch
Passed
0.384
75.7
1,009
Stretch
Passed
0.512
75.9
10,007
Stretch
Passed
0.475
74.3
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Day 21 / 40 · Quadratic and multiplicative residues
Primitive roots
Direct calculation@ratmath/numtheory
Problem
Find the least primitive root modulo 13.
Worked solution
, , so : 2 has order 12 and is a primitive root.
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 numtheory from "@ratmath/numtheory";
console.log(numtheory.primitiveRoot(13));
Checked output
2n
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes or odd moduli, usually below a few hundred in hand examples; specify whether inverses and square roots exist.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.164 ms on Node.
Same API, measured input family.numtheory.primitiveRoot · prime modulus. Baseline test points across courses 3, 5, 7, 11, 23. Powers of a primitive root must visit every nonzero residue modulo p.
Practical limit. Largest passing sample 10,007 (0.286 ms, 75.6 MiB peak process RSS). The runs did not locate a ceiling for this family. Primitive roots exist for prime moduli here. Composite moduli need existence checks. Generating and retaining every power is linear in the group order.
Measured times, memory and outcomes
prime modulus · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
3
Baseline
Passed
0.244
75.7
5
Baseline
Passed
0.247
75.4
7
Baseline
Passed
0.373
75.4
11
Baseline
Passed
0.335
74.6
23
Baseline
Passed
0.406
74.9
101
Stretch
Passed
0.302
75.7
1,009
Stretch
Passed
0.283
73.9
10,007
Stretch
Passed
0.286
75.6
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Day 22 / 40 · Quadratic and multiplicative residues
Groups of units
Direct calculation@ratmath/structures
Problem
Describe the group of units .
Worked solution
, of order 8, not cyclic.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as structures from "@ratmath/structures";
console.log(structures.Zn(15).unitGroup().text);
Checked output
C2 × C4
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes or odd moduli, usually below a few hundred in hand examples; specify whether inverses and square roots exist.
Focal example. The code above passed its displayed check in 0.297 ms on Node.
Related workload in this unit.structures.Zn.units · modulus. Baseline test points across courses 2, 6, 12, 30. Enumerate the residues independently and select those coprime to n by Euclid's algorithm.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (22.59 ms, 87 MiB peak process RSS). The runs did not locate a ceiling for this family. Enumerating units or ideals scales with the size of the residue ring. A large modulus encoded in a few digits can still imply a large list.
Measured times, memory and outcomes
modulus · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.373
74.3
6
Baseline
Passed
0.611
75.5
12
Baseline
Passed
0.473
75.1
30
Baseline
Passed
0.541
75
120
Stretch
Passed
1.29
74.5
1,000
Stretch
Passed
6.59
76.5
10,000
Stretch
Passed
22.59
87
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
structures.Zn · 3 passing test cases, 4 distinct argument descriptions
Day 23 / 40 · Quadratic and multiplicative residues
Squares modulo eight
Direct calculation@ratmath/numtheory
Problem
Which residues can an odd square have modulo 8?
Worked solution
Write an odd number as 2k+1. Its square is 4k(k+1)+1, and one of k,k+1 is even. The only residue is 1.
Using RatMath
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log([1,3,5,7].map(x=>numtheory.modPow(x,2,8)));
Checked output
[1n, 1n, 1n, 1n]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes or odd moduli, usually below a few hundred in hand examples; specify whether inverses and square roots exist.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.071 ms on Node.
Same API, measured input family.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.modPow · 4 passing test cases, 22 distinct argument descriptions
Day 24 / 40 · Quadratic and multiplicative residues
Order divisibility
Worked by hand
Problem
In a group of order 12, can an element have order 5?
Worked solution
Lagrange's theorem forces the element order to divide 12. Five does not.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Small primes or odd moduli, usually below a few hundred in hand examples; specify whether inverses and square roots exist.
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 · Primality and representation
Fermat numbers
Direct calculation@ratmath/numtheory
Problem
Factor .
Worked solution
Euler: (both prime).
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 numtheory from "@ratmath/numtheory";
console.log(numtheory.formatFactors(numtheory.factor(2n ** 32n + 1n)));
Checked output
641 · 6700417
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes, pseudoprimes or deliberately chosen products; difficulty depends strongly on the least factor.
For this problem type. Typical hand examples are positive integers up to thousands. For computation, distinguish a known-factor input or prime-count endpoint from a hard semiprime.
Focal example. The code above passed its displayed check in 0.114 ms on Node.
Same API, measured input family.numtheory.factor · known semiprime. Baseline test points across courses 15, 77, 899, 10,403. Recover both planted prime factors, including exponent one.
Practical limit. Largest passing sample 1,000,036,000,099 (5.12 ms, 77 MiB peak process RSS). The runs did not locate a ceiling for this family. Equal-length integers can have very different factoring times. These planted semiprimes give sample timings, with no general bound for the next integer.
Measured times, memory and outcomes
known semiprime · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
15
Baseline
Passed
0.331
76
77
Baseline
Passed
0.309
76.3
899
Baseline
Passed
0.298
74.9
10,403
Baseline
Passed
0.327
75.7
1,022,117
Stretch
Passed
0.397
75.8
100,160,063
Stretch
Passed
0.922
75.4
1,000,036,000,099
Stretch
Passed
5.12
77
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.formatFactors · 2 passing test cases, 2 distinct argument descriptions
Show 561 is composite but for every coprime to 561.
Worked solution
, and all divide 560 (Korselt), so the Carmichael function divides 560.
Using RatMath
Use the meaning of the Carmichael exponent on units. Divisibility of 560 by that exponent supplies the step applying to every coprime base.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(
[numtheory.formatFactors(numtheory.factor(561)), numtheory.carmichael(561), 560 % Number(numtheory.carmichael(561))]
);
Checked output
["3 · 11 · 17", 80n, 0]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes, pseudoprimes or deliberately chosen products; difficulty depends strongly on the least factor.
For this problem type. Typical hand examples are positive integers up to thousands. For computation, distinguish a known-factor input or prime-count endpoint from a hard semiprime.
Focal example. The code above passed its displayed check in 0.166 ms on Node.
Same API, measured input family.numtheory.factor · known semiprime. Baseline test points across courses 15, 77, 899, 10,403. Recover both planted prime factors, including exponent one.
Practical limit. Largest passing sample 1,000,036,000,099 (5.12 ms, 77 MiB peak process RSS). The runs did not locate a ceiling for this family. Equal-length integers can have very different factoring times. These planted semiprimes give sample timings, with no general bound for the next integer.
Measured times, memory and outcomes
known semiprime · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
15
Baseline
Passed
0.331
76
77
Baseline
Passed
0.309
76.3
899
Baseline
Passed
0.298
74.9
10,403
Baseline
Passed
0.327
75.7
1,022,117
Stretch
Passed
0.397
75.8
100,160,063
Stretch
Passed
0.922
75.4
1,000,036,000,099
Stretch
Passed
5.12
77
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.formatFactors · 2 passing test cases, 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 numtheory from "@ratmath/numtheory";
console.log(numtheory.twoSquaresAll(65));
Checked output
[[8n, 1n], [7n, 4n]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes, pseudoprimes or deliberately chosen products; difficulty depends strongly on the least factor.
Focal example. The code above passed its displayed check in 0.413 ms on Node.
Related workload in this unit.numtheory.factor · known semiprime. Baseline test points across courses 15, 77, 899, 10,403. Recover both planted prime factors, including exponent one.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 1,000,036,000,099 (5.12 ms, 77 MiB peak process RSS). The runs did not locate a ceiling for this family. Equal-length integers can have very different factoring times. These planted semiprimes give sample timings, with no general bound for the next integer.
Measured times, memory and outcomes
known semiprime · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
15
Baseline
Passed
0.331
76
77
Baseline
Passed
0.309
76.3
899
Baseline
Passed
0.298
74.9
10,403
Baseline
Passed
0.327
75.7
1,022,117
Stretch
Passed
0.397
75.8
100,160,063
Stretch
Passed
0.922
75.4
1,000,036,000,099
Stretch
Passed
5.12
77
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.twoSquaresAll · 1 passing test case, 6 distinct argument descriptions
: a reducible cubic has a rational root, and are not roots; irreducible. : reducible (previous exercise). : Eisenstein at 3; irreducible.
Using RatMath
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as structures from "@ratmath/structures";
const R = structures.ring(["x"]);
console.log(
["x^3 - 2", "x^4 + 4", "x^4 + 6*x + 3"].map((f) => structures.isIrreducible(R.poly(f)))
);
Checked output
[true, false, 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. Small primes, pseudoprimes or deliberately chosen products; difficulty depends strongly on the least factor.
For this problem type. Use low-degree defining polynomials, often degree 2–5, and one or two generators. State the base field and multiplicity or irreducibility assumptions.
Focal example. The code above passed its displayed check in 1.48 ms on Node.
Related workload in this unit.structures.Zn.units · modulus. Baseline test points across courses 2, 6, 12, 30. Enumerate the residues independently and select those coprime to n by Euclid's algorithm.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (22.59 ms, 87 MiB peak process RSS). The runs did not locate a ceiling for this family. Enumerating units or ideals scales with the size of the residue ring. A large modulus encoded in a few digits can still imply a large list.
Measured times, memory and outcomes
modulus · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.373
74.3
6
Baseline
Passed
0.611
75.5
12
Baseline
Passed
0.473
75.1
30
Baseline
Passed
0.541
75
120
Stretch
Passed
1.29
74.5
1,000
Stretch
Passed
6.59
76.5
10,000
Stretch
Passed
22.59
87
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
structures.ring · 27 passing test cases, 30 distinct argument descriptions
Put the arithmetic inside the R tag so RatMath parses the literals. Keep fractions as ratios throughout the calculation and attach the units from the problem to the result.
JavaScript module
import { BaseSystem, R } from "@ratmath/core";
console.log(R`2026`.toBase(BaseSystem.fromBase(2)));
Checked output
11111101010
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes, pseudoprimes or deliberately chosen products; difficulty depends strongly on the least factor.
Focal example. The code above passed its displayed check in 0.280 ms on Node.
Related workload in this unit.core.R · whole-number operand. Baseline test points across courses 0, 1, 10, 20, 100, 1,000, 1,000,000. (n+7)(n−3) by independent BigInt arithmetic.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 9,007,199,254,740,991 (1.67 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact integer arithmetic grows with operand bit length. Enter large integers as decimal strings or BigInts before any JavaScript Number conversion.
Measured times, memory and outcomes
whole-number operand · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
1.75
75
1
Baseline
Passed
1.70
75.7
10
Baseline
Passed
1.78
75.1
20
Baseline
Passed
1.88
75.4
100
Baseline
Passed
1.55
75.4
1,000
Baseline
Passed
1.36
75.3
1,000,000
Baseline
Passed
1.39
74.8
1,000,000,000
Stretch
Passed
1.69
76.3
9,007,199,254,740,991
Stretch
Passed
1.67
75.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.BaseSystem · 15 passing test cases, 16 distinct argument descriptions
Factor 1001 by spotting a small divisor and finish the factorization.
Worked solution
1001=7×143=7×11×13. Check the three prime factors multiply back.
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`7*11*13`));
Checked output
1001
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes, pseudoprimes or deliberately chosen products; difficulty depends strongly on the least factor.
Focal example. The code above passed its displayed check in 0.194 ms on Node.
Same arithmetic expression. Replaced its first numeral 7 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.R · whole-number operand. Baseline test points across courses 0, 1, 10, 20, 100, 1,000, 1,000,000. (n+7)(n−3) by independent BigInt arithmetic.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 9,007,199,254,740,991 (1.67 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact integer arithmetic grows with operand bit length. Enter large integers as decimal strings or BigInts before any JavaScript Number conversion.
Measured times, memory and outcomes
whole-number operand · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
1.75
75
1
Baseline
Passed
1.70
75.7
10
Baseline
Passed
1.78
75.1
20
Baseline
Passed
1.88
75.4
100
Baseline
Passed
1.55
75.4
1,000
Baseline
Passed
1.36
75.3
1,000,000
Baseline
Passed
1.39
74.8
1,000,000,000
Stretch
Passed
1.69
76.3
9,007,199,254,740,991
Stretch
Passed
1.67
75.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
The only square residues are 0 and 1. Pairwise sums give 0, 1 or 2.
Using RatMath
Enter whole numbers and keep the modulus with each residue. Check a proposed residue by substitution into the original congruence.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log([0,1,2,3].map(x=>numtheory.modPow(x,2,4)));
Checked output
[0n, 1n, 0n, 1n]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes, pseudoprimes or deliberately chosen products; difficulty depends strongly on the least factor.
For this problem type. Use small moduli, often 2–200, and one to four congruences or trial residues. Verify coprimality or primality when required.
Focal example. The code above passed its displayed check in 0.076 ms on Node.
Same API, measured input family.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. Other inputs to this API can take different paths. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.modPow · 4 passing test cases, 22 distinct argument descriptions
The valuations 2 and 3 add. The highest power is 3⁵.
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`3^5`));
Checked output
243
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Small primes, pseudoprimes or deliberately chosen products; difficulty depends strongly on the least factor.
Focal example. The code above passed its displayed check in 0.065 ms on Node.
Same arithmetic expression. Replaced its first numeral 3 with 0, 1, 2, 7, 12, 100, 1000, -3, 1/2. All 9 defined variants agreed exactly with Python’s rational arithmetic. This varies the arithmetic operation while holding the rest of the expression fixed.
Related workload in this unit.core.Rational.multiply · operand bits. Baseline test points across courses 8, 32, 64, 256. Cross-multiply the unreduced integer products; operands have unlike denominators.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 131,072 (1.53 ms, 75.5 MiB peak process RSS). The runs did not locate a ceiling for this family. Intermediate products can have twice the bit length of their factors. Repeated squaring can exhaust the engine’s BigInt allocation limit in a small number of steps.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
8
Baseline
Passed
0.317
74.6
32
Baseline
Passed
0.035
75.5
64
Baseline
Passed
0.045
75.1
256
Baseline
Passed
0.106
74
1,024
Stretch
Passed
0.035
75.3
8,192
Stretch
Passed
0.075
75.8
32,768
Stretch
Passed
0.245
75
131,072
Stretch
Passed
1.53
75.5
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.R · 2 passing test cases, 10 distinct argument descriptions
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as numtheory from "@ratmath/numtheory";
console.log(numtheory.nonNegativeSolutions(3, 5, 47).solutions);
Checked output
[[4n, 7n], [9n, 4n], [14n, 1n]]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to four integer coefficients in a linear equation, continued fractions of modest period or small quadratic discriminants.
Focal example. The code above passed its displayed check in 0.467 ms on Node.
Related workload in this unit.numtheory.gcd · operand bits. Baseline test points across courses 4, 8, 16, 32. Consecutive integers m,m+1 are coprime, so gcd(7m,7(m+1))=7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 32,768 (0.183 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Euclidean reduction depends on operand size and their quotient sequence. Consecutive Fibonacci numbers need more steps than many inputs of the same bit length.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
4
Baseline
Passed
0.171
74.8
8
Baseline
Passed
0.132
74.7
16
Baseline
Passed
0.129
74.8
32
Baseline
Passed
0.131
76.2
256
Stretch
Passed
0.124
74.5
4,096
Stretch
Passed
0.165
74.9
32,768
Stretch
Passed
0.183
75.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.nonNegativeSolutions · 1 passing test case, 1 distinct argument description
Chicken nuggets come in boxes of 6, 9 and 20. What is the largest number that cannot be bought exactly?
Worked solution
44 = 24 + 20, 45 = 5·9, 46 = 6 + 40, 47 = 27 + 20, 48 = 8·6, 49 = 9 + 40 are all possible, and any later number adds 6 to one of these. 43 is not possible (43, 23 and 3 are not sums of 6s and 9s). Answer: 43.
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 numtheory from "@ratmath/numtheory";
console.log(numtheory.frobenius([6, 9, 20]));
Checked output
43n
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to four integer coefficients in a linear equation, continued fractions of modest period or small quadratic discriminants.
Focal example. The code above passed its displayed check in 0.215 ms on Node.
Related workload in this unit.numtheory.gcd · operand bits. Baseline test points across courses 4, 8, 16, 32. Consecutive integers m,m+1 are coprime, so gcd(7m,7(m+1))=7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 32,768 (0.183 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Euclidean reduction depends on operand size and their quotient sequence. Consecutive Fibonacci numbers need more steps than many inputs of the same bit length.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
4
Baseline
Passed
0.171
74.8
8
Baseline
Passed
0.132
74.7
16
Baseline
Passed
0.129
74.8
32
Baseline
Passed
0.131
76.2
256
Stretch
Passed
0.124
74.5
4,096
Stretch
Passed
0.165
74.9
32,768
Stretch
Passed
0.183
75.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.frobenius · 1 passing test case, 5 distinct argument descriptions
Implementation limit. With more than two coprime positive denominations, the residue-search branch caps the smallest coin at one million. Two denominations use the closed formula. Source at the tested revision
Day 35 / 40 · Diophantine methods
Continued fractions and Pell's equation
Direct calculation@ratmath/numtheory
Problem
Find the continued fraction of , and the smallest positive solution of .
Worked solution
. For : , convergent : , 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 numtheory from "@ratmath/numtheory";
const cf = numtheory.periodicContinuedFraction(numtheory.fromQuadratic(0, 1, 13, 1));
const p = numtheory.pell(7);
console.log([cf.preperiod, cf.period, p.x, p.y]);
Checked output
[[3n], [1n, 1n, 1n, 1n, 6n], 8n, 3n]
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to four integer coefficients in a linear equation, continued fractions of modest period or small quadratic discriminants.
Focal example. The code above passed its displayed check in 1.29 ms on Node.
Related workload in this unit.numtheory.modPow · exponent bits. Baseline test points across courses 2, 4, 8, 16. Reduce the exponent independently modulo the order 3 of 2 mod 7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 8,192 (2.51 ms, 81.1 MiB peak process RSS). The runs did not locate a ceiling for this family. Modular reduction keeps residues bounded. Cost depends on modulus size and exponent bit length. Negative exponents require an inverse.
Measured times, memory and outcomes
exponent bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.083
75.3
4
Baseline
Passed
0.081
75.5
8
Baseline
Passed
0.129
74.3
16
Baseline
Passed
0.085
74.9
64
Stretch
Passed
0.088
74.5
1,024
Stretch
Passed
0.204
75.4
8,192
Stretch
Passed
2.51
81.1
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.periodicContinuedFraction · 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 numtheory from "@ratmath/numtheory";
console.log(numtheory.egcd(252n, 198n));
Checked output
{ g: 18n, x: 4n, y: -5n }
Run this example locally
Use the integrated RatMath workspace with the subject packages linked. Save this example as lesson.mjs in its root and run node lesson.mjs. The guide formats library objects as mathematical values. Your console may also print their fields or JavaScript type suffixes.
Typical inputs for this unit. Two to four integer coefficients in a linear equation, continued fractions of modest period or small quadratic discriminants.
Focal example. The code above passed its displayed check in 0.113 ms on Node.
Related workload in this unit.numtheory.gcd · operand bits. Baseline test points across courses 4, 8, 16, 32. Consecutive integers m,m+1 are coprime, so gcd(7m,7(m+1))=7.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 32,768 (0.183 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Euclidean reduction depends on operand size and their quotient sequence. Consecutive Fibonacci numbers need more steps than many inputs of the same bit length.
Measured times, memory and outcomes
operand bits · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
4
Baseline
Passed
0.171
74.8
8
Baseline
Passed
0.132
74.7
16
Baseline
Passed
0.129
74.8
32
Baseline
Passed
0.131
76.2
256
Stretch
Passed
0.124
74.5
4,096
Stretch
Passed
0.165
74.9
32,768
Stretch
Passed
0.183
75.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
numtheory.egcd · 1 passing test case, 3 distinct argument descriptions
Use the data and parameter order shown below. Compare the returned value with the intermediate quantities in the worked solution.
JavaScript module
import * as structures from "@ratmath/structures";
const f = structures.gaussianIntegers().factor(5);
console.log([String(f.unit), f.factors.map((x) => `${x.prime}^${x.exponent}`)]);
Checked output
["1", ["2 − i^1", "2 + i^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. Two to four integer coefficients in a linear equation, continued fractions of modest period or small quadratic discriminants.
Focal example. The code above passed its displayed check in 1.53 ms on Node.
Related workload in this unit.structures.Zn.units · modulus. Baseline test points across courses 2, 6, 12, 30. Enumerate the residues independently and select those coprime to n by Euclid's algorithm.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 10,000 (22.59 ms, 87 MiB peak process RSS). The runs did not locate a ceiling for this family. Enumerating units or ideals scales with the size of the residue ring. A large modulus encoded in a few digits can still imply a large list.
Measured times, memory and outcomes
modulus · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
2
Baseline
Passed
0.373
74.3
6
Baseline
Passed
0.611
75.5
12
Baseline
Passed
0.473
75.1
30
Baseline
Passed
0.541
75
120
Stretch
Passed
1.29
74.5
1,000
Stretch
Passed
6.59
76.5
10,000
Stretch
Passed
22.59
87
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
structures.gaussianIntegers · 3 passing test cases, 1 distinct argument description
Why does x²=2y² have no positive integer solutions?
Worked solution
A solution forces x even and then y even. Dividing both by two produces a solution with a smaller positive y, contradicting minimality.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Two to four integer coefficients in a linear equation, continued fractions of modest period or small quadratic discriminants.
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 39 / 40 · Diophantine methods
A primitive triple
Direct calculation@ratmath/core
Problem
Use m=3,n=2 in Euclid's formula. Which Pythagorean triple results?
Worked solution
The legs are m²−n² and 2mn. The hypotenuse is m²+n², giving (5,12,13).
Using RatMath
Construct an Integer or Rational before applying its methods. Use fraction strings or integer inputs to preserve exact values.
JavaScript module
import { Integer } from "@ratmath/core";
console.log([new Integer(3**2-2**2),new Integer(2*3*2),new Integer(3**2+2**2)]);
Checked output
[5, 12, 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. Two to four integer coefficients in a linear equation, continued fractions of modest period or small quadratic discriminants.
Focal example. The code above passed its displayed check in 0.070 ms on Node.
Related workload in this unit.core.R · whole-number operand. Baseline test points across courses 0, 1, 10, 20, 100, 1,000, 1,000,000. (n+7)(n−3) by independent BigInt arithmetic.
Practical limit. The cutoff for this lesson’s own code is unmeasured. Largest passing sample 9,007,199,254,740,991 (1.67 ms, 75.3 MiB peak process RSS). The runs did not locate a ceiling for this family. Exact integer arithmetic grows with operand bit length. Enter large integers as decimal strings or BigInts before any JavaScript Number conversion.
Measured times, memory and outcomes
whole-number operand · one run per input
Input
Sample
Result
Call (ms)
Peak RSS (MiB)
0
Baseline
Passed
1.75
75
1
Baseline
Passed
1.70
75.7
10
Baseline
Passed
1.78
75.1
20
Baseline
Passed
1.88
75.4
100
Baseline
Passed
1.55
75.4
1,000
Baseline
Passed
1.36
75.3
1,000,000
Baseline
Passed
1.39
74.8
1,000,000,000
Stretch
Passed
1.69
76.3
9,007,199,254,740,991
Stretch
Passed
1.67
75.3
Each row measures the stated fixture. This workload uses a different operation or expression from the focal example. Its thresholds apply only to the named fixture. Course intervals are estimates. Finite samples leave intermediate inputs and other problem families unverified.
Additional inputs from package tests
These arguments were observed in passing test cases. The linked assertions show what the tests actually checked. Structured inputs are abbreviated.
core.Integer · 170 passing test cases, 60 distinct argument descriptions
Why is there exactly one representative in {0,…,m−1} for each integer modulo positive m?
Worked solution
Division with remainder supplies one. Two representatives in that interval differing by a multiple of m must coincide.
Working without a calculator
Use the argument or construction in the worked solution. This lesson assigns the reasoning to the student.
Input range and limits
Typical inputs for this unit. Two to four integer coefficients in a linear equation, continued fractions of modest period or small quadratic discriminants.
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.