HomeAlgorithms & AIMiller–Rabin Witness Density & Convergence (2D)

Miller–Rabin Witness Density & Convergence (2D)

Interactive 2D companion to the 3D Miller-Rabin spiral: instead of animating one random round, this simulator brute-force computes the exact witness fraction for every odd number in a range, plots it as a density scan against the theorem's 3/4 guarantee, contrasts a Carmichael number's near-zero Fermat witness rate with Miller-Rabin catching it every time, and runs a live Monte Carlo convergence test measuring the real false-positive rate against the theoretical 4^-k bound.

Algorithms & AI2DAdvanced60 FPS📱 Mobile-adapted⇄ 3D version
2d-cryptographic-mathematics ↗ Open standalone

This is the 2D companion to the 3D Miller-Rabin primality-test simulator, and it deliberately computes a different, more exhaustive view of the same algorithm rather than animating a single random round. For every odd number across a chosen range it brute-force checks every candidate base a ∈ [2, n−2] and computes the exact fraction that are true witnesses to compositeness — turning the textbook guarantee that at least three quarters of all bases expose a composite number into a real, measured curve plotted against that 0.75 threshold. Loading the classic Carmichael number 561 shows the contrast this scan is built to reveal: restricted to bases coprime to n, the weaker Fermat test's witness fraction collapses to essentially zero — the entire reason Carmichael numbers exist — while Miller-Rabin's witness fraction over the same n stays comfortably above 0.75, because its modular squaring chain checks for nontrivial square roots of 1 that Fermat's test cannot see. A second panel then runs a live Monte Carlo experiment: sampling real composite numbers from the scanned range, running k independent randomized rounds thousands of times, and plotting the measured false-positive rate directly against the theoretical 4−k ceiling that the same test relies on when it selects large primes for RSA keys.

⚙ Under the hood

2D companion to the 3D Miller-Rabin spiral: brute-force computes the exact witness fraction for every odd number in a range, plots it against the theorem's 3/4 guarantee, contrasts a Carmichael number's near-zero Fermat witness rate with Miller-Rabin catching it every time, and runs a live Monte Carlo test measuring the real false-positive rate against the theoretical 4^-k bound.

cryptographynumber-theoryprimality-testmodular-arithmeticalgorithmsRSAmonte-carlostatistics

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)