Pick any even number greater than 2. The demo searches every prime p and checks whether n − p is also prime — listing all the pairs at once.
<p class="hint">Pick any even number greater than 2. The demo searches for a pair of primes <b>p + q = n</b> — and counts <b>every</b> such pair. Goldbach's conjecture says a pair <i>always</i> exists. Nobody has ever found a counterexample, yet nobody has proved it can't happen.</p>
<div class="row">
<button id="dec" type="button" class="ghost">−2</button>
<div class="num" id="num">100</div>
<button id="inc" type="button" class="ghost">+2</button>
</div>
<div class="btns">
<button id="find" type="button">Find prime pairs</button>
<button id="rand" type="button" class="ghost">Random even n</button>
</div>
<div class="status" id="status">Press "Find prime pairs".</div>
<ul class="pairs" id="pairs"></ul>
<div class="comet-wrap">
<div class="comet-title">Goldbach comet — number of prime pairs for each even n</div>
<canvas id="comet" width="520" height="200"></canvas>
</div>
* { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; color: #222; margin: 0; }
.hint { font-size: .9rem; color: #444; margin: 0 0 .8rem; line-height: 1.45; }
.row { display: flex; align-items: center; gap: .8rem; margin: .3rem 0; }
.num { font: 800 30px ui-monospace, monospace; color: #1d3557; min-width: 110px; text-align: center; }
.btns { display: flex; gap: .5rem; flex-wrap: wrap; margin: .5rem 0; }
button { font: 600 14px system-ui, sans-serif; padding: .45rem .9rem; border: 1px solid #1d3557;
background: #1d3557; color: #fff; border-radius: 8px; cursor: pointer; }
button.ghost { background: #fff; color: #1d3557; }
button:disabled { opacity: .5; cursor: default; }
.status { font-size: 1rem; font-weight: 600; margin: .5rem 0; min-height: 1.4em; }
.status.ok { color: #0a7d33; }
.status.bad { color: #c92f3c; }
.pairs { display: flex; flex-wrap: wrap; gap: .4rem; list-style: none; padding: 0; margin: .4rem 0 1rem; }
.pairs li { background: #e8eef3; color: #1d3557; border: 1px solid #cdd9e3; border-radius: 6px;
padding: .25rem .55rem; font: 600 13px ui-monospace, monospace; }
.comet-wrap { margin-top: .6rem; }
.comet-title { font-size: .78rem; color: #667; margin-bottom: .3rem; }
canvas { width: 100%; max-width: 520px; height: auto; background: #f6f8fa; border: 1px solid #dde3ea; border-radius: 8px; }
const fmt = (s, v) => s.replace(/%(\w+)%/g, (_, k) => String(v[k] ?? ''));
// Goldbach's conjecture (Christian Goldbach, 1742): every even integer n > 2 can be written as the sum of two primes. Still OPEN — verified by computer for every even n up to 4 x 10^18, but never proved. This demo, for a given even n, lists every prime pair p + q = n (p <= q) and plots how the *number* of such pairs grows — the famous "Goldbach comet".
const MAXN = 100000;
// Sieve of Eratosthenes up to MAXN.
const isPrime = new Uint8Array(MAXN + 1).fill(1);
isPrime[0] = isPrime[1] = 0;
for (let i = 2; i * i <= MAXN; i++) if (isPrime[i])
for (let j = i * i; j <= MAXN; j += i) isPrime[j] = 0;
// All prime pairs p + q = n with 2 <= p <= q.
function goldbachPairs(n){
const out = [];
for (let p = 2; p <= n / 2; p++)
if (isPrime[p] && isPrime[n - p]) out.push([p, n - p]);
return out;
}
let n = 100;
const $ = id => document.getElementById(id);
function setNum(v){ n = Math.max(4, Math.min(MAXN, v)); if (n % 2) n++; $('num').textContent = n; }
function setStatus(t, cls){ const s = $('status'); s.textContent = t; s.className = 'status ' + (cls||''); }
function find(){
const pairs = goldbachPairs(n);
const ul = $('pairs'); ul.innerHTML = '';
const show = pairs.slice(0, 24);
show.forEach(([p, q]) => { const li = document.createElement('li'); li.textContent = p + ' + ' + q; ul.appendChild(li); });
if (pairs.length > show.length){ const li = document.createElement('li'); li.textContent = fmt('+%v% more', { v: pairs.length - show.length }); ul.appendChild(li); }
if (pairs.length > 0){
setStatus(fmt('✓ %n% = sum of two primes in %length%%v%', { n: n, length: pairs.length, v: pairs.length===1?' way. As Goldbach predicted.':' ways. As Goldbach predicted.' }), 'ok');
console.log(fmt('%n%: %length% representations, e.g. %v%+%v2%', { n: n, length: pairs.length, v: pairs[0][0], v2: pairs[0][1] }));
} else {
setStatus('No pair found — this would be a counterexample!', 'bad');
}
drawComet();
}
function drawComet(){
const cv = $('comet'), ctx = cv.getContext('2d');
const W = cv.width, H = cv.height, pad = 24;
ctx.clearRect(0, 0, W, H);
// Window of even numbers centred near n.
const lo = 4, hi = Math.min(MAXN, Math.max(300, n + 100));
let maxCount = 1;
const pts = [];
for (let m = lo; m <= hi; m += 2){ const c = goldbachPairs(m).length; if (c > maxCount) maxCount = c; pts.push([m, c]); }
// axes
ctx.strokeStyle = '#c3ccd6'; ctx.lineWidth = 1;
ctx.beginPath(); ctx.moveTo(pad, H - pad); ctx.lineTo(W - 6, H - pad); ctx.moveTo(pad, 6); ctx.lineTo(pad, H - pad); ctx.stroke();
const x = m => pad + (m - lo) / (hi - lo) * (W - pad - 8);
const y = c => (H - pad) - c / maxCount * (H - pad - 8);
ctx.fillStyle = '#1d3557';
for (const [m, c] of pts){ ctx.beginPath(); ctx.arc(x(m), y(c), 1.4, 0, 7); ctx.fill(); }
// highlight current n
const cn = goldbachPairs(n).length;
ctx.fillStyle = '#e63946'; ctx.beginPath(); ctx.arc(x(n), y(cn), 4, 0, 7); ctx.fill();
ctx.fillStyle = '#667'; ctx.font = '11px system-ui';
ctx.fillText('pairs', pad + 4, 12); ctx.fillText('n', W - 16, H - pad + 14);
}
$('inc').addEventListener('click', () => { setNum(n + 2); });
$('dec').addEventListener('click', () => { setNum(n - 2); });
$('find').addEventListener('click', find);
$('rand').addEventListener('click', () => { setNum(6 + 2 * Math.floor(Math.random() * 300)); find(); });
setNum(100); drawComet();
<p class="hint">Pick any even number greater than 2. The demo searches for a pair of primes <b>p + q = n</b> — and counts <b>every</b> such pair. Goldbach's conjecture says a pair <i>always</i> exists. Nobody has ever found a counterexample, yet nobody has proved it can't happen.</p>
<div class="row">
<button id="dec" type="button" class="ghost">−2</button>
<div class="num" id="num">100</div>
<button id="inc" type="button" class="ghost">+2</button>
</div>
<div class="btns">
<button id="find" type="button">Find prime pairs</button>
<button id="rand" type="button" class="ghost">Random even n</button>
</div>
<div class="status" id="status">Press "Find prime pairs".</div>
<ul class="pairs" id="pairs"></ul>
<div class="comet-wrap">
<div class="comet-title">Goldbach comet — number of prime pairs for each even n</div>
<canvas id="comet" width="520" height="200"></canvas>
</div>
* { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; color: #222; margin: 0; }
.hint { font-size: .9rem; color: #444; margin: 0 0 .8rem; line-height: 1.45; }
.row { display: flex; align-items: center; gap: .8rem; margin: .3rem 0; }
.num { font: 800 30px ui-monospace, monospace; color: #1d3557; min-width: 110px; text-align: center; }
.btns { display: flex; gap: .5rem; flex-wrap: wrap; margin: .5rem 0; }
button { font: 600 14px system-ui, sans-serif; padding: .45rem .9rem; border: 1px solid #1d3557;
background: #1d3557; color: #fff; border-radius: 8px; cursor: pointer; }
button.ghost { background: #fff; color: #1d3557; }
button:disabled { opacity: .5; cursor: default; }
.status { font-size: 1rem; font-weight: 600; margin: .5rem 0; min-height: 1.4em; }
.status.ok { color: #0a7d33; }
.status.bad { color: #c92f3c; }
.pairs { display: flex; flex-wrap: wrap; gap: .4rem; list-style: none; padding: 0; margin: .4rem 0 1rem; }
.pairs li { background: #e8eef3; color: #1d3557; border: 1px solid #cdd9e3; border-radius: 6px;
padding: .25rem .55rem; font: 600 13px ui-monospace, monospace; }
.comet-wrap { margin-top: .6rem; }
.comet-title { font-size: .78rem; color: #667; margin-bottom: .3rem; }
canvas { width: 100%; max-width: 520px; height: auto; background: #f6f8fa; border: 1px solid #dde3ea; border-radius: 8px; }
const fmt = (s, v) => s.replace(/%(\w+)%/g, (_, k) => String(v[k] ?? ''));
// Goldbach's conjecture (Christian Goldbach, 1742): every even integer n > 2 can be written as the sum of two primes. Still OPEN — verified by computer for every even n up to 4 x 10^18, but never proved. This demo, for a given even n, lists every prime pair p + q = n (p <= q) and plots how the *number* of such pairs grows — the famous "Goldbach comet".
const MAXN = 100000;
// Sieve of Eratosthenes up to MAXN.
const isPrime = new Uint8Array(MAXN + 1).fill(1);
isPrime[0] = isPrime[1] = 0;
for (let i = 2; i * i <= MAXN; i++) if (isPrime[i])
for (let j = i * i; j <= MAXN; j += i) isPrime[j] = 0;
// All prime pairs p + q = n with 2 <= p <= q.
function goldbachPairs(n){
const out = [];
for (let p = 2; p <= n / 2; p++)
if (isPrime[p] && isPrime[n - p]) out.push([p, n - p]);
return out;
}
let n = 100;
const $ = id => document.getElementById(id);
function setNum(v){ n = Math.max(4, Math.min(MAXN, v)); if (n % 2) n++; $('num').textContent = n; }
function setStatus(t, cls){ const s = $('status'); s.textContent = t; s.className = 'status ' + (cls||''); }
function find(){
const pairs = goldbachPairs(n);
const ul = $('pairs'); ul.innerHTML = '';
const show = pairs.slice(0, 24);
show.forEach(([p, q]) => { const li = document.createElement('li'); li.textContent = p + ' + ' + q; ul.appendChild(li); });
if (pairs.length > show.length){ const li = document.createElement('li'); li.textContent = fmt('+%v% more', { v: pairs.length - show.length }); ul.appendChild(li); }
if (pairs.length > 0){
setStatus(fmt('✓ %n% = sum of two primes in %length%%v%', { n: n, length: pairs.length, v: pairs.length===1?' way. As Goldbach predicted.':' ways. As Goldbach predicted.' }), 'ok');
console.log(fmt('%n%: %length% representations, e.g. %v%+%v2%', { n: n, length: pairs.length, v: pairs[0][0], v2: pairs[0][1] }));
} else {
setStatus('No pair found — this would be a counterexample!', 'bad');
}
drawComet();
}
function drawComet(){
const cv = $('comet'), ctx = cv.getContext('2d');
const W = cv.width, H = cv.height, pad = 24;
ctx.clearRect(0, 0, W, H);
// Window of even numbers centred near n.
const lo = 4, hi = Math.min(MAXN, Math.max(300, n + 100));
let maxCount = 1;
const pts = [];
for (let m = lo; m <= hi; m += 2){ const c = goldbachPairs(m).length; if (c > maxCount) maxCount = c; pts.push([m, c]); }
// axes
ctx.strokeStyle = '#c3ccd6'; ctx.lineWidth = 1;
ctx.beginPath(); ctx.moveTo(pad, H - pad); ctx.lineTo(W - 6, H - pad); ctx.moveTo(pad, 6); ctx.lineTo(pad, H - pad); ctx.stroke();
const x = m => pad + (m - lo) / (hi - lo) * (W - pad - 8);
const y = c => (H - pad) - c / maxCount * (H - pad - 8);
ctx.fillStyle = '#1d3557';
for (const [m, c] of pts){ ctx.beginPath(); ctx.arc(x(m), y(c), 1.4, 0, 7); ctx.fill(); }
// highlight current n
const cn = goldbachPairs(n).length;
ctx.fillStyle = '#e63946'; ctx.beginPath(); ctx.arc(x(n), y(cn), 4, 0, 7); ctx.fill();
ctx.fillStyle = '#667'; ctx.font = '11px system-ui';
ctx.fillText('pairs', pad + 4, 12); ctx.fillText('n', W - 16, H - pad + 14);
}
$('inc').addEventListener('click', () => { setNum(n + 2); });
$('dec').addEventListener('click', () => { setNum(n - 2); });
$('find').addEventListener('click', find);
$('rand').addEventListener('click', () => { setNum(6 + 2 * Math.floor(Math.random() * 300)); find(); });
setNum(100); drawComet();
Two things stand out. First, you will always find at least one pair, no matter which even number you try. Second, the number of pairs tends to climb as the numbers grow — the scattered cloud below is the famous Goldbach comet. Verifying any single number is quick; proving the pattern never breaks, for the infinitely many numbers we can never test, is the part nobody has managed.
Comments
Loading comments...