Pick a polynomial and a root r, then step through the table. Each column repeats the same two moves: multiply the last row entry by r and add it under the next coefficient, then add that column down.
<p class="hint">The polynomial is <b>p(x) = x³ − 6x² + 11x − 6</b> (roots 1, 2 and 3). Pick a root r, then press Step to bring down, multiply and add across the row — one column at a time.</p>
<div class="controls">
<label for="root-select">Divide by (x - r):</label>
<select id="root-select">
<option value="1">r = 1</option>
<option value="2">r = 2</option>
<option value="3">r = 3</option>
<option value="4">r = 4</option>
<option value="-1">r = -1</option>
</select>
<button id="step" type="button">Step</button>
<button id="auto" type="button">Auto-run</button>
<button id="reset" type="button" class="ghost">Reset</button>
</div>
<div id="table" class="table"></div>
<div class="status" id="status">Bring down the first coefficient, then press Step.</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 .7rem; line-height: 1.45; }
.controls { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; }
.controls label { font-size: .85rem; font-weight: 600; color: #1d3557; }
select { font: 600 14px system-ui, sans-serif; padding: .35rem .5rem; border-radius: 6px; border: 1px solid #adb1b8; }
.table { display: grid; grid-template-columns: repeat(5, 62px); gap: 4px; margin: .5rem 0; font: 700 16px ui-monospace, monospace; }
.cell { height: 42px; display: flex; align-items: center; justify-content: center; border-radius: 6px; }
.cell.coeff { background: #e8eef3; color: #1d3557; border: 1px solid #cdd9e3; }
.cell.mult { background: #fff3cd; color: #8a6d1d; border: 1px dashed #e0b93d; }
.cell.sum { background: #c9ccd1; color: #222; border: 1px solid #adb1b8; }
.cell.sum.active { background: #1d3557; color: #fff; }
.cell.sum.remainder { background: #0a7d33; color: #fff; }
.cell.empty { visibility: hidden; }
.status { font-size: 1rem; font-weight: 600; margin: .5rem 0; min-height: 1.4em; }
.status.ok { color: #0a7d33; }
.status.info { color: #1d3557; }
.btns { display: flex; gap: .5rem; }
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; }
const i18nFmt = (s, v) => s.replace(/%(\w+)%/g, (_, k) => String(v[k] ?? ''));
// Fixed polynomial: coefficients of x^3 - 6x^2 + 11x - 6, highest degree first.
const COEFFS = [1, -6, 11, -6]; // coefficients 1, -6, 11, -6
let r = 1;
let col = 0; // next column to fill
let running = null;
const row = [];
function polyLabel(){
// builds the human-readable polynomial label for the console
return 'p(x) = x' + '³' + ' − 6x' + '²' + ' + 11x − 6';
}
function reset(){
row.length = 0;
row.push(COEFFS[0]);
col = 1;
clearInterval(running); running = null;
render();
setStatus('Bring down the first coefficient, then press Step.', 'info');
}
function step(){
if (col >= COEFFS.length) return false;
const brought = COEFFS[col] + row[col-1]*r; // multiply the last row value by r, add the next coefficient
row.push(brought);
col++;
render();
if (col === COEFFS.length){
setStatus(i18nFmt('Done! The remainder is %pr% — and that equals p(%r%), computed for free.', { r: r, pr: row[row.length-1] }), 'ok');
return false;
}
setStatus(i18nFmt('Multiplied by r and added into column %col%.', { col: col }), 'info');
return true;
}
function render(){
const t = document.getElementById('table'); t.innerHTML = '';
const n = COEFFS.length;
// top row = coefficients, middle row = multiply-by-r products, bottom row = running sums
for (let i = 0; i < n; i++){
const d = document.createElement('div');
d.className = 'cell coeff';
d.textContent = COEFFS[i];
t.appendChild(d);
}
const rLabel = document.createElement('div');
rLabel.className = 'cell empty';
t.appendChild(rLabel);
for (let i = 0; i < n; i++){
const d = document.createElement('div');
if (i === 0 || i >= row.length){ d.className = 'cell empty'; }
else { d.className = 'cell mult'; d.textContent = '+' + (row[i-1]*r); }
t.appendChild(d);
}
const mLabel = document.createElement('div');
mLabel.className = 'cell empty';
t.appendChild(mLabel);
for (let i = 0; i < n; i++){
const d = document.createElement('div');
if (i >= row.length){ d.className = 'cell empty'; }
else {
const isLast = (i === n-1) && (row.length === n);
d.className = 'cell sum' + (isLast ? ' remainder' : (i === row.length-1 ? ' active' : ''));
d.textContent = row[i];
}
t.appendChild(d);
}
}
function setStatus(t, cls){ const s = document.getElementById('status'); s.textContent = t; s.className = 'status ' + cls; }
document.getElementById('root-select').addEventListener('change', (e) => {
r = Number(e.target.value);
reset();
});
document.getElementById('step').addEventListener('click', step);
document.getElementById('auto').addEventListener('click', () => {
if (running) return;
running = setInterval(() => { if (!step()) { clearInterval(running); running = null; } }, 650);
});
document.getElementById('reset').addEventListener('click', reset);
console.log(polyLabel(), '(open the console to see the label)'); // log the polynomial once at start
reset();
<p class="hint">The polynomial is <b>p(x) = x³ − 6x² + 11x − 6</b> (roots 1, 2 and 3). Pick a root r, then press Step to bring down, multiply and add across the row — one column at a time.</p>
<div class="controls">
<label for="root-select">Divide by (x - r):</label>
<select id="root-select">
<option value="1">r = 1</option>
<option value="2">r = 2</option>
<option value="3">r = 3</option>
<option value="4">r = 4</option>
<option value="-1">r = -1</option>
</select>
<button id="step" type="button">Step</button>
<button id="auto" type="button">Auto-run</button>
<button id="reset" type="button" class="ghost">Reset</button>
</div>
<div id="table" class="table"></div>
<div class="status" id="status">Bring down the first coefficient, then press Step.</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 .7rem; line-height: 1.45; }
.controls { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; }
.controls label { font-size: .85rem; font-weight: 600; color: #1d3557; }
select { font: 600 14px system-ui, sans-serif; padding: .35rem .5rem; border-radius: 6px; border: 1px solid #adb1b8; }
.table { display: grid; grid-template-columns: repeat(5, 62px); gap: 4px; margin: .5rem 0; font: 700 16px ui-monospace, monospace; }
.cell { height: 42px; display: flex; align-items: center; justify-content: center; border-radius: 6px; }
.cell.coeff { background: #e8eef3; color: #1d3557; border: 1px solid #cdd9e3; }
.cell.mult { background: #fff3cd; color: #8a6d1d; border: 1px dashed #e0b93d; }
.cell.sum { background: #c9ccd1; color: #222; border: 1px solid #adb1b8; }
.cell.sum.active { background: #1d3557; color: #fff; }
.cell.sum.remainder { background: #0a7d33; color: #fff; }
.cell.empty { visibility: hidden; }
.status { font-size: 1rem; font-weight: 600; margin: .5rem 0; min-height: 1.4em; }
.status.ok { color: #0a7d33; }
.status.info { color: #1d3557; }
.btns { display: flex; gap: .5rem; }
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; }
const i18nFmt = (s, v) => s.replace(/%(\w+)%/g, (_, k) => String(v[k] ?? ''));
// Fixed polynomial: coefficients of x^3 - 6x^2 + 11x - 6, highest degree first.
const COEFFS = [1, -6, 11, -6]; // coefficients 1, -6, 11, -6
let r = 1;
let col = 0; // next column to fill
let running = null;
const row = [];
function polyLabel(){
// builds the human-readable polynomial label for the console
return 'p(x) = x' + '³' + ' − 6x' + '²' + ' + 11x − 6';
}
function reset(){
row.length = 0;
row.push(COEFFS[0]);
col = 1;
clearInterval(running); running = null;
render();
setStatus('Bring down the first coefficient, then press Step.', 'info');
}
function step(){
if (col >= COEFFS.length) return false;
const brought = COEFFS[col] + row[col-1]*r; // multiply the last row value by r, add the next coefficient
row.push(brought);
col++;
render();
if (col === COEFFS.length){
setStatus(i18nFmt('Done! The remainder is %pr% — and that equals p(%r%), computed for free.', { r: r, pr: row[row.length-1] }), 'ok');
return false;
}
setStatus(i18nFmt('Multiplied by r and added into column %col%.', { col: col }), 'info');
return true;
}
function render(){
const t = document.getElementById('table'); t.innerHTML = '';
const n = COEFFS.length;
// top row = coefficients, middle row = multiply-by-r products, bottom row = running sums
for (let i = 0; i < n; i++){
const d = document.createElement('div');
d.className = 'cell coeff';
d.textContent = COEFFS[i];
t.appendChild(d);
}
const rLabel = document.createElement('div');
rLabel.className = 'cell empty';
t.appendChild(rLabel);
for (let i = 0; i < n; i++){
const d = document.createElement('div');
if (i === 0 || i >= row.length){ d.className = 'cell empty'; }
else { d.className = 'cell mult'; d.textContent = '+' + (row[i-1]*r); }
t.appendChild(d);
}
const mLabel = document.createElement('div');
mLabel.className = 'cell empty';
t.appendChild(mLabel);
for (let i = 0; i < n; i++){
const d = document.createElement('div');
if (i >= row.length){ d.className = 'cell empty'; }
else {
const isLast = (i === n-1) && (row.length === n);
d.className = 'cell sum' + (isLast ? ' remainder' : (i === row.length-1 ? ' active' : ''));
d.textContent = row[i];
}
t.appendChild(d);
}
}
function setStatus(t, cls){ const s = document.getElementById('status'); s.textContent = t; s.className = 'status ' + cls; }
document.getElementById('root-select').addEventListener('change', (e) => {
r = Number(e.target.value);
reset();
});
document.getElementById('step').addEventListener('click', step);
document.getElementById('auto').addEventListener('click', () => {
if (running) return;
running = setInterval(() => { if (!step()) { clearInterval(running); running = null; } }, 650);
});
document.getElementById('reset').addEventListener('click', reset);
console.log(polyLabel(), '(open the console to see the label)'); // log the polynomial once at start
reset();
Watch what happens to the very last cell. It's the remainder of the division — and it always matches p(r) computed the ordinary way, plugging r straight into the polynomial. Try a root where the remainder lands on 0: that means (x−r) divides the polynomial exactly, and r is one of its roots.
Comments
Loading comments...