An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
feat(linear-algebra): chapters 32-34 and cost.js finish Unit 4
yzr5927824a0ab3
diff --git a/site/linear-algebra/ch32/audio/en/dmat.mp3 b/site/linear-algebra/ch32/audio/en/dmat.mp3new file mode 100644index 0000000..22aa0cdBinary files /dev/null and b/site/linear-algebra/ch32/audio/en/dmat.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/ex2.mp3 b/site/linear-algebra/ch32/audio/en/ex2.mp3new file mode 100644index 0000000..2fac64dBinary files /dev/null and b/site/linear-algebra/ch32/audio/en/ex2.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/ex3.mp3 b/site/linear-algebra/ch32/audio/en/ex3.mp3new file mode 100644index 0000000..553916eBinary files /dev/null and b/site/linear-algebra/ch32/audio/en/ex3.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/final1.mp3 b/site/linear-algebra/ch32/audio/en/final1.mp3new file mode 100644index 0000000..73670d8Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/final1.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/final2.mp3 b/site/linear-algebra/ch32/audio/en/final2.mp3new file mode 100644index 0000000..4a41c78Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/final2.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/final3.mp3 b/site/linear-algebra/ch32/audio/en/final3.mp3new file mode 100644index 0000000..c47fa18Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/final3.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/final4.mp3 b/site/linear-algebra/ch32/audio/en/final4.mp3new file mode 100644index 0000000..7cb5773Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/final4.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/finish.mp3 b/site/linear-algebra/ch32/audio/en/finish.mp3new file mode 100644index 0000000..7257dbfBinary files /dev/null and b/site/linear-algebra/ch32/audio/en/finish.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/intro.mp3 b/site/linear-algebra/ch32/audio/en/intro.mp3new file mode 100644index 0000000..90e23a5Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/intro.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/ldu.mp3 b/site/linear-algebra/ch32/audio/en/ldu.mp3new file mode 100644index 0000000..6cbfaf6Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/ldu.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/play.mp3 b/site/linear-algebra/ch32/audio/en/play.mp3new file mode 100644index 0000000..7c18028Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/play.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/pull.mp3 b/site/linear-algebra/ch32/audio/en/pull.mp3new file mode 100644index 0000000..9f59a7cBinary files /dev/null and b/site/linear-algebra/ch32/audio/en/pull.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/q1.mp3 b/site/linear-algebra/ch32/audio/en/q1.mp3new file mode 100644index 0000000..be3a650Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/q1.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/q2.mp3 b/site/linear-algebra/ch32/audio/en/q2.mp3new file mode 100644index 0000000..fd5b337Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/q2.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/q3.mp3 b/site/linear-algebra/ch32/audio/en/q3.mp3new file mode 100644index 0000000..29782d9Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/q3.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/recall.mp3 b/site/linear-algebra/ch32/audio/en/recall.mp3new file mode 100644index 0000000..e637b63Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/recall.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/timings.js b/site/linear-algebra/ch32/audio/en/timings.jsnew file mode 100644index 0000000..fd4fe83--- /dev/null+++ b/site/linear-algebra/ch32/audio/en/timings.js@@ -0,0 +1,658 @@+window.TIMINGS = {+ "intro": {+ "dur": 14.64,+ "marks": {+ "sub": 3.425,+ "move": 9.362+ },+ "cues": [+ [+ 0.104,+ "Chapter thirty-two."+ ],+ [+ 1.576,+ "A equals L D U."+ ],+ [+ 3.425,+ "After elimination, the pivots sit on the diagonal of U, while L has ones on its diagonal."+ ],+ [+ 9.362,+ "Pull the pivots out into a matrix of their own, and L and U look alike."+ ]+ ]+ },+ "recall": {+ "dur": 52.464,+ "marks": {+ "A": 5.195,+ "L": 9.18,+ "U": 14.036,+ "mult": 19.857,+ "diag": 21.849,+ "ones": 24.44,+ "piv": 25.69,+ "lop": 28.581,+ "sys": 32.383,+ "elim": 43.529+ },+ "cues": [+ [+ 0.104,+ "Chapter thirty factored the matrix two, one, eight, seven."+ ],+ [+ 5.195,+ "Elimination takes four times row one away from row two."+ ],+ [+ 9.18,+ "L keeps that multiplier, four, below a diagonal of ones."+ ],+ [+ 14.036,+ "U is what elimination leaves: two, one, and zero, three."+ ],+ [+ 19.857,+ "And L times U gives back A."+ ],+ [+ 21.849,+ "Now compare the two diagonals."+ ],+ [+ 24.44,+ "L has one and one."+ ],+ [+ 25.69,+ "U has the pivots, two and three."+ ],+ [+ 28.581,+ "The factors are lopsided: every pivot sits in U."+ ],+ [+ 32.383,+ "Here is A in a system: two x plus y equals three, and eight x plus seven y equals fifteen, as in chapter thirty."+ ],+ [+ 41.745,+ "The lines meet at one, one."+ ],+ [+ 43.529,+ "Elimination gives U's system: two x plus y equals three, and three y equals three."+ ],+ [+ 50.247,+ "The coral line turns flat."+ ]+ ]+ },+ "pull": {+ "dur": 44.688,+ "marks": {+ "r1": 1.797,+ "div1": 5.469,+ "same1": 11.576,+ "chk1": 20.456,+ "r2": 26.471,+ "div2": 29.844,+ "same2": 33.125,+ "new": 36.914,+ "keep": 40.26+ },+ "cues": [+ [+ 0.104,+ "Let's take the pivots out of U."+ ],+ [+ 1.797,+ "Row one is two, one, and three on the right."+ ],+ [+ 5.469,+ "Divide the whole row by its pivot, two: one, one half, and three halves."+ ],+ [+ 11.576,+ "Watch the blue line: it did not move."+ ],+ [+ 14.102,+ "Dividing every number of an equation by two changes the numbers, but not the points that fit it."+ ],+ [+ 20.456,+ "The point one, one still fits: one, plus one half of one, is three halves."+ ],+ [+ 26.471,+ "Row two is zero, three, three."+ ],+ [+ 29.844,+ "Divide by its pivot, three: zero, one, one."+ ],+ [+ 33.125,+ "Again the line stays: y equals one either way."+ ],+ [+ 36.914,+ "The new table has ones down its diagonal, just like L."+ ],+ [+ 40.26,+ "But the pivots, two and three, are gone from it."+ ],+ [+ 43.177,+ "We have to keep them somewhere."+ ]+ ]+ },+ "dmat": {+ "dur": 50.184,+ "marks": {+ "r1": 3.021,+ "r2": 4.518,+ "mat": 6.211,+ "row2": 15.052,+ "D": 19.701,+ "go1": 26.966,+ "still": 35.195,+ "go2": 36.797,+ "back": 41.341,+ "name": 44.245+ },+ "cues": [+ [+ 0.091,+ "To get U back, multiply the rows again: row one by two, and row two by three."+ ],+ [+ 6.211,+ "That's a matrix on the left, as in chapter twenty-one."+ ],+ [+ 9.635,+ "Its first row is two, zero: two of row one, none of row two."+ ],+ [+ 15.052,+ "Its second row is zero, three: three of row two."+ ],+ [+ 19.701,+ "Numbers on the diagonal and zeros everywhere else: a diagonal matrix."+ ],+ [+ 25.625,+ "We call it D."+ ],+ [+ 26.966,+ "Watch D grow from the identity."+ ],+ [+ 29.518,+ "Its first number goes from one to two, and row one of the answer doubles: two, one, three."+ ],+ [+ 35.195,+ "The line does not move."+ ],+ [+ 36.797,+ "Its second number goes to three: zero, three, three."+ ],+ [+ 41.341,+ "D times the table with ones gives U again."+ ],+ [+ 44.245,+ "From now on, U means the matrix with ones on its diagonal, and the pivots live in D."+ ]+ ]+ },+ "ldu": {+ "dur": 54.552,+ "marks": {+ "eq": 1.458,+ "ldu": 6.458,+ "three": 9.388,+ "check": 18.75,+ "du": 21.12,+ "du1": 23.398,+ "du2": 26.133,+ "lu": 29.362,+ "lr1": 31.432,+ "lr2": 36.12,+ "a": 44.297,+ "pic": 46.797+ },+ "cues": [+ [+ 0.104,+ "Put it all together."+ ],+ [+ 1.458,+ "A equals L times the old U, and the old U equals D times the new U."+ ],+ [+ 6.458,+ "So A equals L times D times U."+ ],+ [+ 9.388,+ "L is one, zero, four, one."+ ],+ [+ 12.161,+ "D is two, zero, zero, three."+ ],+ [+ 15.495,+ "U is one, one half, zero, one."+ ],+ [+ 18.75,+ "Let's check, multiplying from the right."+ ],+ [+ 21.12,+ "D times U scales the rows of U: row one times two is two, one."+ ],+ [+ 26.133,+ "Row two times three is zero, three."+ ],+ [+ 29.362,+ "Then L mixes those rows."+ ],+ [+ 31.432,+ "Row one of L is one, zero: row one stays two, one."+ ],+ [+ 36.12,+ "Row two of L is four, one: four times two, one is eight, four."+ ],+ [+ 40.964,+ "Add zero, three: eight, seven."+ ],+ [+ 44.297,+ "Two, one, eight, seven."+ ],+ [+ 45.925,+ "That's A."+ ],+ [+ 46.797,+ "And in the picture, L turns the flat coral line back up to eight x plus seven y equals fifteen."+ ]+ ]+ },+ "q1": {+ "dur": 2.856,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.133,+ "Pull the pivots out of this U."+ ]+ ]+ },+ "ex2": {+ "dur": 60.432,+ "marks": {+ "A": 1.797,+ "l": 5.365,+ "step": 9.036,+ "LU": 16.823,+ "piv": 24.883,+ "div1": 26.901,+ "div2": 30.026,+ "ldu": 34.987,+ "look": 43.06,+ "mirror": 45.573+ },+ "cues": [+ [+ 0.104,+ "Another one, from the start."+ ],+ [+ 1.797,+ "A is three, six, and six, sixteen."+ ],+ [+ 5.365,+ "The multiplier is six divided by three: two."+ ],+ [+ 9.036,+ "Row two minus two times row one leaves zero, four, and minus four on the right."+ ],+ [+ 14.688,+ "The coral line lies flat."+ ],+ [+ 16.823,+ "So L is one, zero, two, one, and the old U is three, six, zero, four."+ ],+ [+ 24.883,+ "The pivots are three and four."+ ],+ [+ 26.901,+ "Divide row one by three: one, two."+ ],+ [+ 30.026,+ "Divide row two by four: zero, one."+ ],+ [+ 33.62,+ "The lines stay."+ ],+ [+ 34.987,+ "A equals L D U: L with its two, D with three and four, and U with ones and a two."+ ],+ [+ 43.06,+ "Now look at L and U side by side."+ ],+ [+ 45.573,+ "L's two sits below the diagonal, and U's two sits above it, in the mirror spot."+ ],+ [+ 51.042,+ "That happens because A itself is the same across its diagonal: six above, six below."+ ],+ [+ 57.617,+ "Matrices like that are chapter thirty-six."+ ]+ ]+ },+ "ex3": {+ "dur": 53.28,+ "marks": {+ "A": 2.513,+ "U": 6.693,+ "piv": 15.43,+ "r1": 18.099,+ "r2": 22.409,+ "r3": 28.542,+ "still": 34.089,+ "D": 35.599,+ "go": 38.333,+ "L": 43.372,+ "ldu": 48.034+ },+ "cues": [+ [+ 0.156,+ "Three by three works the same way."+ ],+ [+ 2.513,+ "This is the lecture's system from chapters eighteen and twenty-one."+ ],+ [+ 6.693,+ "Elimination left U: one, two, one; zero, two, minus two; zero, zero, five."+ ],+ [+ 15.43,+ "Its pivots are one, two and five."+ ],+ [+ 18.099,+ "Row one's pivot is one: dividing by one changes nothing."+ ],+ [+ 22.409,+ "Row two divided by two: zero, one, minus one, and three on the right."+ ],+ [+ 28.542,+ "Row three divided by five: zero, zero, one, and minus two."+ ],+ [+ 34.089,+ "Not one plane moved."+ ],+ [+ 35.599,+ "D holds the pivots: one, two, five."+ ],+ [+ 38.333,+ "Grow D from the identity, and the table with ones turns back into the old U."+ ],+ [+ 43.372,+ "L holds the multipliers: three, zero and two."+ ],+ [+ 48.034,+ "A equals L D U, and both L and U have ones down the diagonal."+ ]+ ]+ },+ "zero": {+ "dur": 16.848,+ "marks": {+ "div": 1.172,+ "ch20": 5.3,+ "swap": 8.529,+ "next": 12.474+ },+ "cues": [+ [+ 0.104,+ "One warning."+ ],+ [+ 1.172,+ "To divide a row by its pivot, the pivot must not be zero."+ ],+ [+ 5.3,+ "Chapter twenty met a zero in the pivot spot."+ ],+ [+ 8.529,+ "A row exchange fixed it, or there was no pivot at all."+ ],+ [+ 12.474,+ "Chapter thirty-four puts the row exchange into the factors."+ ]+ ]+ },+ "q2": {+ "dur": 7.632,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Your turn."+ ],+ [+ 1.081,+ "Change the two numbers on the diagonal of D until D times U is the amber U from elimination."+ ]+ ]+ },+ "q3": {+ "dur": 2.592,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Quick check."+ ],+ [+ 1.185,+ "Find the pivots for D."+ ]+ ]+ },+ "wrap": {+ "dur": 31.248,+ "marks": {+ "w1": 1.081,+ "w2": 8.516,+ "w3": 15.977,+ "w4": 22.982,+ "end": 29.336+ },+ "cues": [+ [+ 0.091,+ "Let's sum up."+ ],+ [+ 1.081,+ "Divide each row of U by its pivot: the new U has ones down its diagonal, and no line or plane moves."+ ],+ [+ 8.516,+ "The pivots go into D, a diagonal matrix."+ ],+ [+ 11.927,+ "D times a matrix multiplies each row by its pivot."+ ],+ [+ 15.977,+ "A equals L D U: L and U both have ones on the diagonal, and D holds the pivots."+ ],+ [+ 22.982,+ "To check a factoring, multiply from the right: D scales the rows, then L mixes them."+ ],+ [+ 29.336,+ "Now try the chapter practice."+ ]+ ]+ },+ "final1": {+ "dur": 2.856,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Chapter practice."+ ],+ [+ 1.51,+ "Pull the pivots out of U."+ ]+ ]+ },+ "final2": {+ "dur": 4.416,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Set two."+ ],+ [+ 1.068,+ "Multiply L, D and U back together."+ ]+ ]+ },+ "final3": {+ "dur": 5.544,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Set three."+ ],+ [+ 1.224,+ "Factor A all the way: L, D and U."+ ]+ ]+ },+ "final4": {+ "dur": 5.712,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Last set."+ ],+ [+ 1.224,+ "Change D with your own hands until D times U is the target."+ ]+ ]+ },+ "play": {+ "dur": 12.264,+ "marks": {+ "go": 3.906+ },+ "cues": [+ [+ 0.104,+ "Playground."+ ],+ [+ 1.068,+ "Nothing here is marked right or wrong."+ ],+ [+ 3.906,+ "Change any number of D, or of the table, drag a line, and watch which changes move the picture and which do not."+ ]+ ]+ },+ "finish": {+ "dur": 10.608,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Well done."+ ],+ [+ 1.107,+ "That's the end of chapter thirty-two, A equals L D U."+ ],+ [+ 5.286,+ "Next: chapter thirty-three, where we count how much work elimination takes."+ ]+ ]+ }+};diff --git a/site/linear-algebra/ch32/audio/en/wrap.mp3 b/site/linear-algebra/ch32/audio/en/wrap.mp3new file mode 100644index 0000000..d3f2985Binary files /dev/null and b/site/linear-algebra/ch32/audio/en/wrap.mp3 differdiff --git a/site/linear-algebra/ch32/audio/en/zero.mp3 b/site/linear-algebra/ch32/audio/en/zero.mp3new file mode 100644index 0000000..abc21cbBinary files /dev/null and b/site/linear-algebra/ch32/audio/en/zero.mp3 differdiff --git a/site/linear-algebra/ch32/index.html b/site/linear-algebra/ch32/index.htmlnew file mode 100644index 0000000..737298f--- /dev/null+++ b/site/linear-algebra/ch32/index.html@@ -0,0 +1,439 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>A = LDU</title>+<link rel="stylesheet" href="../lib/engine.css">+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->+</head>+<body>+<script src="../lib/engine.js"></script>+<script src="../lib/math.js"></script>+<script src="../lib/linsys.js"></script>+<script src="../lib/space3.js"></script>+<script src="../lib/elim.js"></script>+<script src="../lib/emat.js"></script>+<script src="../lib/play.js"></script>+<script src="audio/en/timings.js"></script>+<script>+'use strict';+const CHAPTER = { number: 32, title: 'A = LDU', minutes: 8, language: 'en', next: '../ch33/' };++/* ---------- chapter drawing helpers (chapter 21's, with fractions) ---------- */+const DENS = [1, 2, 3, 4, 5];+const LECA = [[2, 1], [8, 7]], LECB = [3, 15]; // the lecture's 2 × 2 (OCW 18.06, lecture 4), chapter 30's b, x = (1, 1)+const UOLD = [[2, 1], [0, 3]], COLD = [3, 3]; // U with the pivots, its right side+const UNEW = [[1, 1 / 2], [0, 1]], CNEW = [3 / 2, 1]; // each row divided by its pivot+const L2 = [[1, 0], [4, 1]], D2 = [[2, 0], [0, 3]];+const LEC3 = { A: [[1, 2, 1], [3, 8, 1], [0, 4, 1]], b: [2, 12, 2] }; // chapters 18 and 21+const U3OLD = { A: [[1, 2, 1], [0, 2, -2], [0, 0, 5]], b: [2, 6, -10] };+const AT2 = [70, 290], AT3 = [64, 262];+const CARD2 = { x: 40, y: 600, w: 760, cls: 'side' }, CARD3 = { x: 40, y: 640, w: 820, cls: 'side' };+const say = (p, parts, x, y, t0, { size = 40, fill = COL.chalk, anchor = 'start' } = {}) => { const e = M(p, [].concat(parts), { x, y, size, fill, anchor, o: 0 }); show(e, t0); return e; };+const text = (p, str, x, y, t0, { size = 30, fill = COL.chalk, anchor = 'start', weight = 500 } = {}) => { const e = T(p, str, { x, y, size, fill, anchor, weight, o: 0 }); show(e, t0); return e; };+const thick = (sys, i, t0) => { tw(sys.lines[i].l, { 'a_stroke-width': 10 }, t0, .35); tw(sys.lines[i].l, { 'a_stroke-width': 5 }, t0 + .9, .6); };+// a number as math parts: whole, a fraction in lowest terms, or one decimal+const fp = v => {+ const r = Math.round(v);+ if (Math.abs(v - r) < 1e-9) return [num(r)];+ for (let d = 2; d <= 12; d++) { const k = Math.round(v * d); if (Math.abs(v * d - k) < 1e-9) return k < 0 ? ['−', F(-k, d)] : [F(k, d)]; }+ return [num(Math.round(v * 10) / 10)];+};+// A small matrix in brackets with its name to the left ("L ="); t0 null: at once (inside a question).+const mat = (p, rows, x, y, t0, { size = 32, cw = 52, rh = 46, name = '', fill = () => COL.chalk, under = '' } = {}) => {+ const g = G(p, { o: t0 === null ? 1 : 0 }), n = rows.length, w = rows[0].length * cw, top = y - size * .95, bot = y + (n - 1) * rh + size * .4;+ const hl = mk('rect', { x: x - 8, y: top - 6, width: w + 16, height: bot - top + 12, rx: 12, fill: COL.chalk, 'fill-opacity': .13 }, g);+ put(hl, { o: 0 });+ path(g, `M${x + 12} ${top}H${x}V${bot}H${x + 12}M${x + w - 12} ${top}H${x + w}V${bot}H${x + w - 12}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });+ rows.forEach((r, i) => r.forEach((v, j) => M(g, fp(v), { x: x + cw * (j + .5), y: y + i * rh, size, fill: fill(i, j), anchor: 'middle' })));+ if (name) M(g, [].concat(name), { x: x - 14, y: y + (n - 1) * rh / 2 + size * .3, size: size * 1.05, fill: COL.chalk, anchor: 'end' });+ if (under) T(g, under, { x: x + w / 2, y: bot + size * .95, size: 22, fill: COL.dim, weight: 600, anchor: 'middle' });+ if (t0 !== null) show(g, t0, .5);+ const cx = j => x + cw * (j + .5), ry = i => y + i * rh;+ const ring = (i, j, at, { color = COL.chalk, dash = false } = {}) => {+ const rg = G(p, { x: cx(j), y: ry(i) - size * .32, o: 0 });+ mk('ellipse', { rx: cw * .46, ry: size * .66, fill: 'none', stroke: color, 'stroke-width': 3.5, ...(dash ? { 'stroke-dasharray': '7 6' } : {}) }, rg);+ show(rg, at, .35);+ return rg;+ };+ const glow = (at, len = 1.4) => { tw(hl, { o: 1 }, at, .25); tw(hl, { o: 0 }, at + len, .6); };+ return { g, cx, ry, w, x, top, bot, ring, glow };+};+// A row of matrices "name = M₁ M₂ …" from x; items: [rows, { name, under, fill }]; returns the mats.+const chain = (p, items, x, y, t0, { size = 30, cw = 50, rh = 44, gap = 26, step = 0 } = {}) => {+ let cx0 = x;+ return items.map(([rows, o = {}], k) => {+ if (o.name) cx0 += mathW([].concat(o.name), size * 1.05) + 14;+ const mm_ = mat(p, rows, cx0, y, o.at ?? t0 + k * step, { size, cw, rh, ...o });+ cx0 += mm_.w + gap;+ return mm_;+ });+};+// 2D: the plane on the right, three tables on the left (E · [A | b] = [EA | Eb]).+const two = (p, { A, b }, caption, { t0 = .1, E = null, name = 'D', names = ['U', '', 'DU', ''] } = {}) => {+ const sys = linsys(p, { A, b, eq: [90, 200], mat: null, sol: false, plane: { cx: 1215, u: 50 }, t0 });+ sys.E.style.display = 'none';+ if (caption) say(p, [caption], 70, 175, t0 + .1, { size: 28, fill: COL.dim });+ const em = emat(p, sys, { A, b, E, at: AT2, size: 38, cw: 64, ecw: 56, rh: 62, gap: 66, t0, dens: DENS, name, names });+ return { sys, em };+};+const three = (p, { A, b }, caption, { t0 = .1, E = null, view = { yaw: -30, pitch: 22 }, name = 'D', names = ['U', '', 'DU', ''] } = {}) => {+ const sys = lin3(p, { A, b, eq: [90, 190], mat: null, sol: false, space: { cx: 1262, size: 520, ...view }, t0 });+ sys.E.style.display = 'none';+ if (caption) say(p, [caption], 64, 160, t0 + .1, { size: 26, fill: COL.dim });+ const em = emat(p, sys, { A, b, E, at: AT3, size: 32, cw: 52, ecw: 44, rh: 54, gap: 64, t0, dens: DENS, name, names });+ return { sys, em, V: sys.space };+};+// The plane alone with an elimination table beside it (chapter 16's layout, the plane further right).+const table = (p, { A, b }, caption, { t0 = .1 } = {}) => {+ const sys = linsys(p, { A, b, eq: [90, 200], mat: null, sol: false, plane: { cx: 1215, u: 50 }, t0 });+ sys.E.style.display = 'none';+ if (caption) say(p, [caption], 70, 175, t0 + .1, { size: 28, fill: COL.dim });+ const el = elim(p, sys, { at: [150, 320], size: 44, cw: 92, rh: 68, t0, dens: DENS });+ return { sys, el };+};+const bare = A => {+ const v = {}, fs = [];+ A.forEach((r, i) => { r.forEach((x, j) => { v[`a${i}${j}`] = x; }); v[`b${i}`] = 0; });+ return { v, set(to) { Object.assign(v, to); fs.forEach(f => f(v)); }, onChange: f => fs.push(f), solve: () => ({}), live() {}, to() {} };+};+const pin = (sys, x, y, t0) => { const g = G(sys.stage, { x: sys.P.PX(x), y: sys.P.PY(y), o: 0 }); mk('circle', { r: 20, fill: 'none', stroke: COL.chalk, 'stroke-width': 3.5, 'stroke-dasharray': '6 5' }, g); show(g, t0, .4); return g; };+// "row 1 ÷ 2" beside row i of an elim table+const divLab = (p, el, i, k, at) => { const g = G(p, { o: 0 }); M(g, [`row ${i + 1} ÷ `, ...fp(k)], { x: el.cx(2) + 110, y: el.ry(i) - 4, size: 34, fill: COL.chalk, anchor: 'start' }); show(g, at, .4); return g; };+const keysOf = ({ A, b }, E = null) => {+ const o = {}, n = A.length;+ A.forEach((r, i) => { r.forEach((x, j) => { o[`a${i}${j}`] = x; o[`e${i}${j}`] = E ? E[i][j] : +(i === j); }); o[`b${i}`] = b[i]; });+ return o;+};+const near = (a, b) => Math.abs(a - b) < 1e-9;+const sameU = (pr, U) => U.every((r, i) => r.every((x, j) => near(pr[`a${i}${j}`], x)));++/* ---------- practice data (every answer worked twice: by dividing, and by multiplying back) ---------- */+const SPLITQ = [+ { parts: ['U = (2, 6), (0, 5): D has ', { box: '2' }, ' and ', { box: '5' }, '; row 1 of the new U = (1, ', { box: '3' }, ')'], why: 'Pivots 2 and 5. Row 1 ÷ 2 = (1, 3).', hint: 'The pivots are on U’s diagonal. Then divide row 1 by its pivot.' },+ { parts: ['U = (4, −2), (0, 3): D has ', { box: '4' }, ' and ', { box: '3' }, '; row 1 of the new U = (1, ', { box: '-1/2' }, ')'], why: 'Row 1 ÷ 4 = (1, −2/4) = (1, −½).', hint: '−2 ÷ 4 is a fraction.' },+ { parts: ['U = (−1, 3), (0, 2): D has ', { box: '-1' }, ' and ', { box: '2' }, '; row 1 of the new U = (1, ', { box: '-3' }, ')'], why: 'A pivot can be negative: row 1 ÷ (−1) = (1, −3).', hint: 'Dividing by −1 changes every sign.' },+ { parts: ['U = (3, 3, 6), (0, 2, 4), (0, 0, 7): D has ', { box: '3' }, ', ', { box: '2' }, ', ', { box: '7' }, '; row 2 of the new U = (0, 1, ', { box: '2' }, ')'], why: 'Pivots 3, 2, 7. Row 2 ÷ 2 = (0, 1, 2).', hint: 'Three pivots, down the diagonal.' },+ { parts: ['U = (5, 0), (0, 2): the new U = (1, ', { box: '0' }, '), (0, ', { box: '1' }, ')'], why: 'U was already diagonal: U = D, and the new U is I.', hint: 'Row 1 ÷ 5, row 2 ÷ 2.' },+];+const MULTQ = [+ { parts: ['L = (1, 0), (2, 1); D = diag(3, 1); U = (1, 2), (0, 1): A = (3, 6), (', { box: '6' }, ', ', { box: '13' }, ')'], why: 'DU = (3, 6), (0, 1). Row 2 of A = 2 × (3, 6) + (0, 1) = (6, 13).', hint: 'First D scales the rows of U, then row 2 of L says: 2 of row 1, plus row 2.' },+ { parts: ['L = (1, 0), (−1, 1); D = diag(2, 4); U = (1, 3), (0, 1): A = (', { box: '2' }, ', ', { box: '6' }, '), (', { box: '-2' }, ', ', { box: '-2' }, ')'], why: 'DU = (2, 6), (0, 4). Row 2 = −(2, 6) + (0, 4) = (−2, −2).', hint: 'DU first: row 1 × 2, row 2 × 4.' },+ { parts: ['L = (1, 0), (3, 1); D = diag(1, −2); U = (1, −1), (0, 1): row 2 of A = (', { box: '3' }, ', ', { box: '-5' }, ')'], why: 'DU = (1, −1), (0, −2). Row 2 = 3 × (1, −1) + (0, −2) = (3, −5).', hint: 'Row 2 of DU is (0, −2).' },+ { parts: ['L = (1,0,0), (2,1,0), (0,1,1); D = diag(1, 1, 3); U = (1,1,1), (0,1,2), (0,0,1): row 3 of A = (', { box: '0' }, ', ', { box: '1' }, ', ', { box: '5' }, ')'], why: 'DU = (1, 1, 1), (0, 1, 2), (0, 0, 3). Row 3 = row 2 + row 3 of DU = (0, 1, 5).', hint: 'Row 3 of L is (0, 1, 1): row 2 plus row 3 of DU.' },+];+const FACTQ = [+ { parts: ['A = (2, 4), (6, 7): ℓ = ', { box: '3' }, '; D has ', { box: '2' }, ' and ', { box: '-5' }, '; U = (1, ', { box: '2' }, '), (0, 1)'], why: 'ℓ = 6 ÷ 2 = 3; 7 − 3 × 4 = −5. Row 1 ÷ 2 = (1, 2).', hint: 'Eliminate first: row 2 − 3 × row 1.' },+ { parts: ['A = (1, 3), (2, 8): ℓ = ', { box: '2' }, '; D has ', { box: '1' }, ' and ', { box: '2' }, '; U = (1, ', { box: '3' }, '), (0, 1)'], why: 'Row 2 − 2 × row 1 = (0, 2). Pivots 1 and 2.', hint: '8 − 2 × 3 is the second pivot.' },+ { parts: ['A = (4, 8), (2, 5): ℓ = ', { box: '1/2' }, '; D has ', { box: '4' }, ' and ', { box: '1' }, '; U = (1, ', { box: '2' }, '), (0, 1)'], why: 'ℓ = 2 ÷ 4 = ½; 5 − ½ × 8 = 1. Row 1 ÷ 4 = (1, 2).', hint: 'The multiplier is a fraction this time.' },+ { parts: ['A = (3, −3), (−6, 10): ℓ = ', { box: '-2' }, '; D has ', { box: '3' }, ' and ', { box: '4' }, '; U = (1, ', { box: '-1' }, '), (0, 1)'], why: 'ℓ = −6 ÷ 3 = −2; 10 − (−2)(−3) = 4. Row 1 ÷ 3 = (1, −1).', hint: 'ℓ is negative; careful with −ℓ × −3.' },+ { parts: ['A = (2, 1), (8, 7): D has ', { box: '2' }, ' and ', { box: '3' }, '; U = (1, ', { box: '1/2' }, '), (0, 1)'], why: 'The lecture’s A: pivots 2 and 3, row 1 ÷ 2 = (1, ½).', hint: 'This is the matrix of the chapter.' },+];+// Hands-on in 3D: D's diagonal, until D times U is the target.+const HANDS = [+ { sys: { A: [[1, 2, 1], [0, 1, -1], [0, 0, 1]], b: [2, 3, -2] }, target: [[1, 2, 1], [0, 2, -2], [0, 0, 5]], ans: { e00: 1, e11: 2, e22: 5 },+ why: 'D = 1, 2, 5: the lecture’s pivots. Row 2 × 2 = (0, 2, −2), row 3 × 5 = (0, 0, 5).' },+ { sys: { A: [[1, 1, 1], [0, 1, 2], [0, 0, 1]], b: [3, 3, 1] }, target: [[2, 2, 2], [0, -1, -2], [0, 0, 3]], ans: { e00: 2, e11: -1, e22: 3 },+ why: 'D = 2, −1, 3. A negative pivot flips the signs of its row.' },+ { sys: { A: [[1, -1, 2], [0, 1, 1], [0, 0, 1]], b: [2, 2, 1] }, target: [[3, -3, 6], [0, 4, 4], [0, 0, -2]], ans: { e00: 3, e11: 4, e22: -2 },+ why: 'D = 3, 4, −2: row 1 × 3, row 2 × 4, row 3 × (−2).' },+];+const dHint = target => (v, pr) => {+ const bad = [0, 1, 2].find(i => !near(pr[`a${i}${i}`], target[i][i]));+ return bad === undefined ? 'Only the diagonal of D should change.' : `Row ${bad + 1} of the answer starts its pivot at ${num(Math.round(pr[`a${bad}${bad}`] * 10) / 10)}; the target has ${num(target[bad][bad])}. What times 1 gives that?`;+};++/* ---------- beats ---------- */+const BEATS = [+ ['intro', 'A = LDU', (m, D) => {+ const g = G(scene, { o: 0, y: 24 });+ T(g, 'Unit 4, Chapter 32', { x: 800, y: 250, size: 28, fill: COL.dim, anchor: 'middle' });+ T(g, 'A = LDU', { x: 800, y: 360, size: 88, weight: 600, anchor: 'middle' });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);+ const r = text(scene, 'pull the pivots out of U into a diagonal matrix D', 800, 460, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });+ const lg = G(scene, { o: 0 }); show(lg, m('sub') + 1, .5);+ say(lg, ['U ='], 562, 664, 0, { size: 40, anchor: 'end' });+ const u0 = mat(lg, UOLD, 580, 625, 0, { size: 38, cw: 62, rh: 54 });+ const r1 = u0.ring(0, 0, m('sub') + 2.5), r2 = u0.ring(1, 1, m('sub') + 2.9);+ hide(u0.g, m('move') + .3, .5); hide(r1, m('move') + .3, .4); hide(r2, m('move') + .3, .4);+ const dm = mat(lg, D2, 580, 625, m('move') + .3, { size: 38, cw: 62, rh: 54, under: 'D' });+ dm.ring(0, 0, m('move') + .3); dm.ring(1, 1, m('move') + .3);+ mat(lg, UNEW, 740, 625, m('move') + 1.1, { size: 38, cw: 72, rh: 54, under: 'U' });+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);+ }],++ ['recall', 'A = LU, again', (m) => {+ const p = panel(0);+ text(p, 'A = LU, again', 60, 110, .2, { size: 40, weight: 600 });+ const [A, L, U] = chain(p, [[LECA, { name: 'A =' }], [L2, { under: 'L', at: m('L') }], [UOLD, { under: 'U', at: m('U') }]], 110, 260, .4, { size: 36, cw: 58, rh: 52, gap: 30 });+ text(p, 'row 2 − 4 × row 1', 110, 410, m('A'), { size: 28, fill: COL.dim, weight: 600 });+ L.ring(1, 0, m('L') + .4, { dash: true });+ A.glow(m('mult') + .2);+ const o1 = L.ring(0, 0, m('ones')), o2 = L.ring(1, 1, m('ones') + .3);+ const p1 = U.ring(0, 0, m('piv')), p2 = U.ring(1, 1, m('piv') + .3);+ text(p, 'L: ones on the diagonal. U: the pivots.', 110, 470, m('lop'), { size: 30, weight: 600 });+ const sys = linsys(p, { A: LECA, b: LECB, eq: [90, 200], mat: null, sol: false, plane: { cx: 1215, u: 50 }, t0: m('sys') - .3 });+ sys.E.style.display = 'none';+ const c1 = say(p, ['2x + y = 3, 8x + 7y = 15'], 110, 580, m('sys'), { size: 32, fill: COL.dim });+ pin(sys, 1, 1, m('sys') + 4);+ thick(sys, 0, m('sys') + 2); thick(sys, 1, m('sys') + 4.4); pulse(sys.meet, m('sys') + 7);+ hide(c1, m('elim') + 2.4, .4);+ say(p, ['2x + y = 3, 3y = 3'], 110, 580, m('elim') + 2.6, { size: 32, fill: COL.dim });+ sys.to({ a10: 0, a11: 3, b1: 3 }, m('elim') + .2, 2.6);+ thick(sys, 1, m('elim') + 3.4);+ }],++ ['pull', 'Pivots out', (m) => {+ const p = panel(0);+ text(p, 'Take the pivots out of U', 60, 110, .2, { size: 40, weight: 600 });+ const { sys, el } = table(p, { A: UOLD, b: COLD }, 'U with its right side: 2x + y = 3, 3y = 3', { t0: .3 });+ pin(sys, 1, 1, .8);+ el.focus(0, m('r1'));+ const g1 = el.ring(0, 0, m('r1') + .5);+ divLab(p, el, 0, 2, m('div1'));+ el.to({ a00: 1, a01: .5, b0: 1.5 }, m('div1') + .5, 2.2);+ hide(g1, m('div1') + 2.8, .4);+ thick(sys, 0, m('same1'));+ [[0, 3, '2·0 + 3 = 3, 0 + ½·3 = 3/2'], [2, -1, '2·2 − 1 = 3, 2 − ½·1 = 3/2']].forEach(([x, y, s], k) => {+ const t = m('same1') + 2.5 + 2.6 * k, d = G(sys.stage, { x: sys.P.PX(x), y: sys.P.PY(y), o: 0 });+ mk('circle', { r: 9, fill: COL.chalk }, d); show(d, t, .3); hide(d, m('chk1') - .2, .3);+ hide(say(p, [s], 150, 470 + 0 * k, t, { size: 28, fill: COL.dim }), t + 2.4, .3);+ });+ say(p, ['1 + ', F(1, 2), ' · 1 = ', F(3, 2), ' ✓'], 150, 560, m('chk1'), { size: 34 });+ pulse(sys.meet, m('chk1') + .4);+ el.focus(1, m('r2'));+ const g2 = el.ring(1, 1, m('r2') + .5);+ divLab(p, el, 1, 3, m('div2'));+ el.to({ a11: 1, b1: 1 }, m('div2') + .5, 2);+ hide(g2, m('div2') + 2.6, .4);+ thick(sys, 1, m('same2'));+ say(p, ['3y = 3 and y = 1: the same line'], 150, 620, m('same2'), { size: 30, fill: COL.dim });+ el.focus(null, m('new'));+ el.diag(m('new'), { color: COL.chalk });+ text(p, 'ones down the diagonal, like L', 150, 690, m('new') + .3, { size: 30, weight: 600 });+ text(p, 'and the pivots 2 and 3?', 150, 750, m('keep'), { size: 30, fill: COL.bad, weight: 600 });+ }],++ ['dmat', 'The matrix D', (m) => {+ const p = panel(0);+ text(p, 'The diagonal matrix D', 60, 110, .2, { size: 40, weight: 600 });+ const { sys, em } = two(p, { A: UNEW, b: CNEW }, 'the table with ones: x + ½y = 3/2, y = 1', { t0: .3, names: ['new U', '', 'answer', ''] });+ pin(sys, 1, 1, .8);+ put(em.Eg, { o: 0 }); show(em.Eg, m('go1') - .6, .5);+ put(em.eqSign, { o: 0 }); show(em.eqSign, m('go1') - .6, .4);+ tw(em.Pt.g, { o: 0 }, 0, 0); show(em.Pt.g, m('go1') - .6, .5);+ prog(q => em.setName(q > 0 ? 'D' : 'I'), m('go1') + .8, 0, lin);+ text(p, 'row 1 × 2', 90, 640, m('r1'), { size: 30, fill: COL.chalk, weight: 600 });+ text(p, 'row 2 × 3', 270, 640, m('r2'), { size: 30, fill: COL.chalk, weight: 600 });+ const dm = mat(p, D2, 560, 640, m('mat'), { size: 34, cw: 56, rh: 50, name: 'D =' });+ const rr1 = G(p, { o: 0 }); mk('rect', { x: 552, y: 606, width: 128, height: 44, rx: 10, fill: COL.chalk, opacity: .14 }, rr1);+ show(rr1, m('mat') + 1.5, .3); hide(rr1, m('row2'), .3);+ em.B.flash(0, m('mat') + 3.6); em.B.flash(1, m('mat') + 6.4);+ const rr2 = G(p, { o: 0 }); mk('rect', { x: 552, y: 656, width: 128, height: 44, rx: 10, fill: COL.chalk, opacity: .14 }, rr2);+ show(rr2, m('row2'), .3); hide(rr2, m('D'), .3);+ dm.ring(0, 0, m('D')); dm.ring(1, 1, m('D') + .2);+ text(p, 'diagonal matrix', 720, 676, m('D') + .4, { size: 26, fill: COL.dim, weight: 600 });+ em.work(0, m('go1'));+ em.ringE(0, 0, m('go1') + .5);+ em.to({ e00: 2 }, m('go1') + 1.4, 2.4);+ em.Pt.flash(0, m('go1') + 3.6);+ thick(sys, 0, m('still'));+ em.work(1, m('go2'));+ em.ringE(1, 1, m('go2') + .3);+ em.to({ e11: 3 }, m('go2') + .9, 2);+ em.Pt.flash(1, m('go2') + 3);+ thick(sys, 1, m('go2') + 2);+ em.work(null, m('back'));+ prog(q => em.names(q > 0 ? ['new U', '', 'old U', ''] : ['new U', '', 'answer', '']), m('back'), 0, lin);+ prog(q => em.names(q > 0 ? ['U', '', 'DU', ''] : ['new U', '', 'old U', '']), m('name') + .4, 0, lin);+ em.Pt.flash(0, m('back') + .6); em.Pt.flash(1, m('back') + .6);+ text(p, 'U: ones on the diagonal. D: the pivots.', 90, 790, m('name') + .4, { size: 30, weight: 600 });+ }],++ ['ldu', 'Multiply it out', (m, D) => {+ const p = panel(0);+ text(p, 'A = L D U', 60, 110, .2, { size: 40, weight: 600 });+ text(p, 'A = L × (old U), old U = D × U', 70, 175, m('eq'), { size: 28, fill: COL.dim, weight: 600 });+ const [Am, L, Dm, U] = chain(p, [[LECA, { name: 'A =' }], [L2, { under: 'L' }], [D2, { under: 'D' }], [UNEW, { under: 'U', cw: 58 }]], 110, 250, m('ldu'), { size: 30, cw: 50, rh: 42, gap: 22, step: .5 });+ L.glow(m('three')); Dm.glow(m('three') + 2.2); U.glow(m('three') + 4.6);+ const sys = linsys(p, { A: UOLD, b: COLD, eq: [90, 200], mat: null, sol: false, plane: { cx: 1215, u: 50 }, t0: .4 });+ sys.E.style.display = 'none';+ const g1 = G(p, { o: 0 }); show(g1, m('du') - .3, .5); hide(g1, m('lu') - .2, .4);+ const e1 = emat(g1, bare(UNEW), { A: UNEW, b: [0, 0], E: D2, at: [70, 460], size: 36, cw: 64, ecw: 56, rh: 60, gap: 60, t0: 0, noB: true, name: 'D', names: ['U', '', 'DU', ''], dens: DENS });+ e1.Pt.flash(0, m('du1')); e1.flashE(0, m('du1'));+ e1.Pt.flash(1, m('du2')); e1.flashE(1, m('du2'));+ const g2 = G(p, { o: 0 }); show(g2, m('lu'), .5);+ const e2 = emat(g2, sys, { A: UOLD, b: COLD, at: [70, 460], size: 36, cw: 64, ecw: 56, rh: 60, gap: 60, t0: 0, name: 'L', names: ['DU', '', 'A', 'b'], dens: DENS });+ e2.work(0, m('lr1'));+ e2.focusE(0, m('lr1'));+ e2.focusE(1, m('lr2')); e2.work(1, m('lr2'));+ e2.ringE(1, 0, m('lr2') + .3);+ e2.to({ e10: 4 }, m('lr2') + .8, 2.4);+ e2.Pt.flash(1, m('lr2') + 5.6);+ e2.Pt.flash(1, m('a') - .3);+ e2.focusE(null, m('a'));+ Am.glow(m('a') + 1);+ thick(sys, 1, m('pic') + .5);+ pin(sys, 1, 1, m('pic') + 1);+ }],++ ['q1', 'Quick check', () => {+ const p = panel(0);+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });+ const t = table(p, { A: [[3, 6], [0, 2]], b: [9, 4] }, 'U: 3x + 6y = 9, 2y = 4');+ S.sys = t.sys;+ }, { ask: done => quiz({ x: 40, y: 440, w: 780, cls: 'side' }, [{+ id: 'c-split', prompt: ['Pull the pivots out of U into D. The new U has ones on its diagonal.'],+ build: blanks([+ { parts: ['D has ', { box: '3' }, ' and ', { box: '2' }, ' on its diagonal'], why: 'The pivots are U’s diagonal: 3 and 2.', hint: 'Look down U’s diagonal.' },+ { parts: ['new U: (', { box: '1' }, ', ', { box: '2' }, ' | ', { box: '3' }, '), (0, ', { box: '1' }, ' | ', { box: '2' }, ')'],+ why: 'Row 1 ÷ 3 = (1, 2 | 3); row 2 ÷ 2 = (0, 1 | 2). Neither line moves.', hint: 'Divide every number of a row by its pivot, right side too.',+ fx: () => fxp(q => S.sys.set({ a00: 3 - 2 * q, a01: 6 - 4 * q, b0: 9 - 6 * q, a11: 2 - q, b1: 4 - 2 * q }), 0, 1.6) },+ ]),+ }], done) }],++ ['ex2', 'From the start', (m) => {+ const p = panel(0);+ text(p, 'A second example, from the start', 60, 110, .2, { size: 40, weight: 600 });+ const { sys, el } = table(p, { A: [[3, 6], [6, 16]], b: [0, -4] }, '3x + 6y = 0, 6x + 16y = −4', { t0: .3 });+ el.flash(0, m('A') + .3); el.flash(1, m('A') + 1.6);+ pin(sys, 2, -1, m('A') + 3);+ const lt = say(p, ['ℓ = 6 ÷ 3 = 2'], 150, 520, m('l'), { size: 34 });+ el.step(1, 0, 2, m('step'), 2.2);+ const lab = el.op_.lab.g;+ thick(sys, 1, m('step') + 3.2);+ const bot1 = G(p, { o: 0 }); show(bot1, m('LU'), .4);+ const [Lb, Ub] = chain(bot1, [[[[1, 0], [2, 1]], { name: 'L =' }], [[[3, 6], [0, 4]], { name: 'old U =' }]], 110, 640, 0, { size: 32, cw: 52, rh: 46, gap: 40 });+ Lb.glow(m('LU') + 1.6); Ub.glow(m('LU') + 4.4);+ const r1 = el.ring(0, 0, m('piv')), r2 = el.ring(1, 1, m('piv') + .3);+ hide(lab, m('div1') - .2, .3); hide(lt, m('div1') - .2, .3);+ divLab(p, el, 0, 3, m('div1'));+ el.to({ a00: 1, a01: 2, b0: 0 }, m('div1') + .4, 1.8);+ hide(r1, m('div1') + 2.2, .3);+ divLab(p, el, 1, 4, m('div2'));+ el.to({ a11: 1, b1: -1 }, m('div2') + .4, 1.6);+ hide(r2, m('div2') + 2, .3);+ hide(bot1, m('ldu') - .2, .3);+ const [Am, Lm, Dm, Um] = chain(p, [[[[3, 6], [6, 16]], { name: 'A =' }], [[[1, 0], [2, 1]], { under: 'L' }], [[[3, 0], [0, 4]], { under: 'D' }], [[[1, 2], [0, 1]], { under: 'U' }]], 110, 640, m('ldu'), { size: 32, cw: 52, rh: 46, gap: 24, step: .4 });+ const rl = Lm.ring(1, 0, m('mirror'), { color: COL.chalk }), ru = Um.ring(0, 1, m('mirror') + .6, { color: COL.chalk });+ pulse(rl, m('mirror') + 2.4); pulse(ru, m('mirror') + 2.4);+ Lm.glow(m('ldu') + 2.2); Dm.glow(m('ldu') + 3.8); Um.glow(m('ldu') + 5.6);+ Am.glow(m('mirror') + 5, 3); Am.ring(0, 1, m('mirror') + 6.2); Am.ring(1, 0, m('mirror') + 6.6);+ text(p, 'A is the same across its diagonal: 6 and 6', 110, 790, m('mirror') + 4, { size: 28, fill: COL.dim, weight: 600 });+ }],++ ['ex3', 'Three by three', (m) => {+ const p = panel(0);+ text(p, 'Three by three', 60, 110, .2, { size: 40, weight: 600 });+ const { sys, em, V } = three(p, U3OLD, 'the lecture’s system after elimination: x + 2y + z = 2, 2y − 2z = 6, 5z = −10', { t0: .3, names: ['old U', '', '', ''] });+ V.sway(5, 13);+ put(em.Eg, { o: 0 }); put(em.eqSign, { o: 0 }); tw(em.Pt.g, { o: 0 }, 0, 0);+ [0, 1, 2].forEach(i => em.B.flash(i, m('U') + .4 + 1.2 * i));+ const rings = [0, 1, 2].map(i => em.B.ring(i, i, m('piv') + .5 * i));+ const lab = (i, k, at) => say(p, [`row ${i + 1} ÷ ${k}`], 70, 470 + 54 * i, at, { size: 30 });+ lab(0, 1, m('r1'));+ lab(1, 2, m('r2')); em.to({ a11: 1, a12: -1, b1: 3 }, m('r2') + .5, 1.8);+ lab(2, 5, m('r3')); em.to({ a22: 1, b2: -2 }, m('r3') + .5, 1.8);+ rings.forEach(r => hide(r, m('still') - .2, .3));+ prog(q => em.names(q > 0 ? ['U', '', '', ''] : ['old U', '', '', '']), m('still'), 0, lin);+ V.turn({ yaw: 10 }, m('still'), 4);+ show(em.Eg, m('D'), .5); show(em.eqSign, m('D'), .4); show(em.Pt.g, m('D'), .5);+ prog(q => em.names(q > 0 ? ['U', '', 'DU', ''] : ['U', '', '', '']), m('D'), 0, lin);+ prog(q => em.setName(q > 0 ? 'D' : 'I'), m('go') + 2.6, 0, lin);+ em.to({ e11: 2, e22: 5 }, m('go') + .4, 2.4);+ em.Pt.flash(1, m('go') + 2.8); em.Pt.flash(2, m('go') + 2.8);+ const Lm = mat(p, [[1, 0, 0], [3, 1, 0], [0, 2, 1]], 400, 500, m('L'), { size: 30, cw: 46, rh: 44, name: 'L =' });+ [[1, 0], [2, 0], [2, 1]].forEach(([i, j], k) => Lm.ring(i, j, m('L') + .8 + .6 * k, { dash: true }));+ say(p, ['A = L D U'], 400, 700, m('ldu'), { size: 40 });+ }],++ ['zero', 'A zero pivot', (m) => {+ const p = panel(0);+ text(p, 'A pivot of zero', 60, 110, .2, { size: 40, weight: 600 });+ const { sys, el } = table(p, { A: [[0, 2], [3, 1]], b: [4, 5] }, 'chapter 20: 2y = 4, 3x + y = 5', { t0: .3 });+ const r0 = el.ring(0, 0, m('div'), { color: COL.bad });+ hide(say(p, ['row 1 ÷ 0 = ?'], 150, 520, m('div') + .6, { size: 34, fill: COL.bad }), m('swap') + 1.8, .4);+ hide(r0, m('swap') - .2, .3);+ el.swap(0, 1, m('swap'), 1.6);+ el.ring(0, 0, m('swap') + 2, { color: COL.good });+ text(p, 'PA = LU: chapter 34', 150, 620, m('next'), { size: 32, weight: 600 });+ }],++ ['q2', 'Your turn', () => {+ const p = panel(0);+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });+ const t = two(p, { A: [[1, 1 / 2], [0, 1]], b: [3 / 2, 1] }, 'the new U: x + ½y = 3/2, y = 1');+ S.em = t.em;+ mat(p, [[4, 2], [0, -3]], 540, 470, .4, { size: 34, cw: 60, rh: 48, name: 'target old U =', fill: () => COL.task });+ }, { ask: done => quiz(CARD2, [{+ id: 'c-d', prompt: ['Change the two numbers on D’s diagonal until D times U is the amber target.'],+ build: emTask(S.em, (v, pr) => sameU(pr, [[4, 2], [0, -3]]), 'D = 4 and −3: row 1 × 4 = (4, 2), row 2 × (−3) = (0, −3). A pivot can be negative.',+ (v, pr) => `Row 1 of the answer is (${num(pr.a00)}, …), row 2 is (0, ${num(pr.a11)}). Row 1 must start with 4; row 2’s pivot is −3.`, () => S.em.set({ e00: 4, e11: -3 }), { only: ['e00', 'e11'] }),+ }], done) }],++ ['q3', 'Quick check', () => {+ const p = panel(0);+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });+ const t = table(p, { A: [[2, 4], [6, 7]], b: [6, 13] }, 'A: 2x + 4y = 6, 6x + 7y = 13');+ S.sys = t.sys;+ }, { ask: done => quiz({ x: 40, y: 470, w: 780, cls: 'side' }, [{+ id: 'c-piv', prompt: ['A = (2, 4), (6, 7). Which numbers go on D’s diagonal?'],+ build: choice(['2 and −5', '2 and 7', '2 and 5', '1 and 1'], 0, 'ℓ = 6 ÷ 2 = 3, and 7 − 3 × 4 = −5. The pivots are 2 and −5.',+ [null, '7 is A’s number before elimination. First take 3 × row 1 away from row 2.', 'Check the sign: 7 − 3 × 4 = 7 − 12.', 'Ones are L’s diagonal. D holds the pivots, from U.'],+ () => fxp(q => S.sys.set({ a10: 6 - 6 * q, a11: 7 - 12 * q, b1: 13 - 18 * q }), 0, 1.6)),+ }], done) }],++ ['wrap', 'Summary', (m) => {+ const p = panel(0);+ [['Divide each row of U by its pivot: ones down the diagonal; nothing moves.', 'w1'], ['The pivots go into D. D times a matrix multiplies each row by its pivot.', 'w2'],+ ['A = L D U: L and U have ones on the diagonal, D holds the pivots.', 'w3'], ['Check by multiplying from the right: D scales the rows, then L mixes them.', 'w4']].forEach(([str, mark], i) => {+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });+ mk('circle', { cx: 120, cy: -12, r: 26, fill: COL.chalk }, g);+ T(g, String(i + 1), { x: 120, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });+ T(g, str, { x: 170, size: 34, weight: 600 });+ tw(g, { o: 1, x: 0 }, m(mark), .6);+ });+ }],+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{+ id: 'p-split', prompt: ['Pull the pivots out: D holds them, and the new U has ones on its diagonal. Rows are written (first number, second number, …).'],+ build: blanks(SPLITQ),+ }], done, 'Chapter practice · set 1 of 4') }],+ ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{+ id: 'p-mult', prompt: ['Multiply from the right: D scales the rows of U, then each row of L mixes them. diag(3, 1) is D with 3 and 1 on its diagonal.'],+ build: blanks(MULTQ),+ }], done, 'Chapter practice · set 2 of 4') }],+ ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{+ id: 'p-fact', prompt: ['Factor A = L D U: eliminate (ℓ), then pull the pivots out of U.'],+ build: blanks(FACTQ),+ }], done, 'Chapter practice · set 3 of 4') }],+ ['final4', 'Chapter practice', () => {+ const p = panel(0);+ text(p, 'Build D', 60, 110, .2, { size: 40, weight: 600 });+ const t = three(p, HANDS[0].sys, '');+ S.em = t.em;+ S.tg = G(p, {});+ }, { ask: done => quiz(CARD3, HANDS.map((h, k) => ({+ id: `p-hand${k + 1}`, prompt: ['Change the numbers on D’s diagonal until D times U is the amber target.'],+ build: (body, api) => {+ S.em.set(keysOf(h.sys)); S.tg.replaceChildren();+ mat(S.tg, h.target, 380, 480, null, { size: 30, cw: 52, rh: 44, name: 'target =', fill: () => COL.task });+ return emTask(S.em, (v, pr) => sameU(pr, h.target), h.why, dHint(h.target), () => S.em.set(h.ans), { only: ['e00', 'e11', 'e22'] })(body, api);+ },+ })), done, 'Chapter practice · set 4 of 4') }],+ ['play', 'Playground', (m) => {+ const p = panel(0);+ text(p, 'Playground', 60, 110, .2, { size: 40, weight: 600 });+ const t = two(p, { A: UNEW, b: CNEW }, '', { E: D2 });+ S.em = t.em;+ t.em.work(0, .3);+ const hint = text(p, 'try: a 0 on D’s diagonal; a negative pivot; a number off the diagonal', 70, 175, m('go'), { size: 24, fill: COL.dim });+ hide(hint, m('go') + 7, .6);+ }, { ask: playAsk(() => S.em, { pos: { x: 40, y: 586, w: 760, cls: 'side' }, tip: 'Your matrices. Change any number of D or of the table, drag a line, or draw on the board. Nothing is marked.' }) }],+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));++boot();+</script>+</body>+</html>diff --git a/site/linear-algebra/ch33/audio/en/chart.mp3 b/site/linear-algebra/ch33/audio/en/chart.mp3new file mode 100644index 0000000..1ea7c7fBinary files /dev/null and b/site/linear-algebra/ch33/audio/en/chart.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/double.mp3 b/site/linear-algebra/ch33/audio/en/double.mp3new file mode 100644index 0000000..35c0118Binary files /dev/null and b/site/linear-algebra/ch33/audio/en/double.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/final1.mp3 b/site/linear-algebra/ch33/audio/en/final1.mp3new file mode 100644index 0000000..bbff509Binary files /dev/null and b/site/linear-algebra/ch33/audio/en/final1.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/final2.mp3 b/site/linear-algebra/ch33/audio/en/final2.mp3new file mode 100644index 0000000..88dbd8cBinary files /dev/null and b/site/linear-algebra/ch33/audio/en/final2.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/final3.mp3 b/site/linear-algebra/ch33/audio/en/final3.mp3new file mode 100644index 0000000..14ef2d1Binary files /dev/null and b/site/linear-algebra/ch33/audio/en/final3.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/final4.mp3 b/site/linear-algebra/ch33/audio/en/final4.mp3new file mode 100644index 0000000..3028c9fBinary files /dev/null and b/site/linear-algebra/ch33/audio/en/final4.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/finish.mp3 b/site/linear-algebra/ch33/audio/en/finish.mp3new file mode 100644index 0000000..7616419Binary files /dev/null and b/site/linear-algebra/ch33/audio/en/finish.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/four.mp3 b/site/linear-algebra/ch33/audio/en/four.mp3new file mode 100644index 0000000..60f687bBinary files /dev/null and b/site/linear-algebra/ch33/audio/en/four.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/intro.mp3 b/site/linear-algebra/ch33/audio/en/intro.mp3new file mode 100644index 0000000..eef13dbBinary files /dev/null and b/site/linear-algebra/ch33/audio/en/intro.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/one.mp3 b/site/linear-algebra/ch33/audio/en/one.mp3new file mode 100644index 0000000..9d730a2Binary files /dev/null and b/site/linear-algebra/ch33/audio/en/one.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/play.mp3 b/site/linear-algebra/ch33/audio/en/play.mp3new file mode 100644index 0000000..ede8d01Binary files /dev/null and b/site/linear-algebra/ch33/audio/en/play.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/pyr.mp3 b/site/linear-algebra/ch33/audio/en/pyr.mp3new file mode 100644index 0000000..96a91f4Binary files /dev/null and b/site/linear-algebra/ch33/audio/en/pyr.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/q1.mp3 b/site/linear-algebra/ch33/audio/en/q1.mp3new file mode 100644index 0000000..724dbf0Binary files /dev/null and b/site/linear-algebra/ch33/audio/en/q1.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/q2.mp3 b/site/linear-algebra/ch33/audio/en/q2.mp3new file mode 100644index 0000000..3a950b6Binary files /dev/null and b/site/linear-algebra/ch33/audio/en/q2.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/q3.mp3 b/site/linear-algebra/ch33/audio/en/q3.mp3new file mode 100644index 0000000..2c19d1bBinary files /dev/null and b/site/linear-algebra/ch33/audio/en/q3.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/right.mp3 b/site/linear-algebra/ch33/audio/en/right.mp3new file mode 100644index 0000000..53071a4Binary files /dev/null and b/site/linear-algebra/ch33/audio/en/right.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/three.mp3 b/site/linear-algebra/ch33/audio/en/three.mp3new file mode 100644index 0000000..51c6ebeBinary files /dev/null and b/site/linear-algebra/ch33/audio/en/three.mp3 differdiff --git a/site/linear-algebra/ch33/audio/en/timings.js b/site/linear-algebra/ch33/audio/en/timings.jsnew file mode 100644index 0000000..2319aa0--- /dev/null+++ b/site/linear-algebra/ch33/audio/en/timings.js@@ -0,0 +1,630 @@+window.TIMINGS = {+ "intro": {+ "dur": 12.144,+ "marks": {+ "sub": 4.05,+ "move": 6.458+ },+ "cues": [+ [+ 0.104,+ "Chapter thirty-three."+ ],+ [+ 1.68,+ "How much work is elimination?"+ ],+ [+ 4.05,+ "We count every operation it takes."+ ],+ [+ 6.458,+ "For an n by n matrix the count grows like n cubed, divided by three."+ ]+ ]+ },+ "one": {+ "dur": 41.736,+ "marks": {+ "A": 3.945,+ "l": 10.859,+ "seven": 19.974,+ "total": 29.818,+ "rule": 33.268,+ "chart": 39.206+ },+ "cues": [+ [+ 0.104,+ "Before we count, we decide what one operation is."+ ],+ [+ 3.945,+ "Take chapter thirty's matrix: two, one, eight, seven."+ ],+ [+ 8.555,+ "Elimination changes row two."+ ],+ [+ 10.859,+ "First the eight."+ ],+ [+ 11.901,+ "We find the multiplier: eight divided by the pivot two is four, and the eight becomes zero."+ ],+ [+ 18.255,+ "That costs one division."+ ],+ [+ 19.974,+ "Then the seven: seven minus four times one is three."+ ],+ [+ 23.88,+ "That's one multiplication and one subtraction."+ ],+ [+ 27.174,+ "We count the pair as one operation."+ ],+ [+ 29.818,+ "Two numbers of row two changed, so the count is two."+ ],+ [+ 33.268,+ "So the rule is simple: every number below a pivot that changes costs one operation."+ ],+ [+ 39.206,+ "On the right, the chart keeps the score."+ ]+ ]+ },+ "three": {+ "dur": 51.504,+ "marks": {+ "A": 1.979,+ "s1": 4.557,+ "go1": 9.74,+ "row3": 17.656,+ "six": 25.495,+ "s2": 29.049,+ "go2": 34.648,+ "two": 38.997,+ "tot": 42.292,+ "corner": 45.938+ },+ "cues": [+ [+ 0.104,+ "Now three by three."+ ],+ [+ 1.979,+ "Here's a matrix with three rows."+ ],+ [+ 4.557,+ "The first pivot is two."+ ],+ [+ 6.367,+ "Below it are two rows, with three numbers each."+ ],+ [+ 9.74,+ "Row two: four becomes zero, three minus two times one is one, three minus two times one is one."+ ],+ [+ 17.656,+ "Row three: eight becomes zero, seven minus four times one is three, nine minus four times one is five."+ ],+ [+ 25.495,+ "Two rows times three numbers: six operations."+ ],+ [+ 29.049,+ "Now the pivot is the one in the middle."+ ],+ [+ 31.641,+ "Below it is one row, with two numbers."+ ],+ [+ 34.648,+ "Three becomes zero, and five minus three times one is two."+ ],+ [+ 38.997,+ "One row times two numbers: two operations."+ ],+ [+ 42.292,+ "Six plus two: eight operations for three by three."+ ],+ [+ 45.938,+ "Each step works on a smaller corner: three by three first, then two by two."+ ]+ ]+ },+ "four": {+ "dur": 34.824,+ "marks": {+ "s1": 2.839,+ "s2": 8.242,+ "s3": 12.109,+ "tot": 15.404,+ "pat": 19.128,+ "sum": 26.406+ },+ "cues": [+ [+ 0.143,+ "Four by four, without the numbers."+ ],+ [+ 2.839,+ "Below the first pivot: three rows of four numbers."+ ],+ [+ 6.68,+ "Twelve operations."+ ],+ [+ 8.242,+ "Below the second: two rows of three."+ ],+ [+ 11.12,+ "Six."+ ],+ [+ 12.109,+ "Below the third: one row of two."+ ],+ [+ 14.701,+ "Two."+ ],+ [+ 15.404,+ "Twelve, plus six, plus two: twenty."+ ],+ [+ 19.128,+ "See the pattern?"+ ],+ [+ 20.182,+ "A corner k by k costs k minus one, times k."+ ],+ [+ 24.674,+ "That's almost k squared."+ ],+ [+ 26.406,+ "For a big matrix, the whole count is close to n squared, plus n minus one squared, and so on, down to one squared."+ ]+ ]+ },+ "q1": {+ "dur": 5.4,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.107,+ "Count the operations for a five by five matrix, step by step."+ ]+ ]+ },+ "chart": {+ "dur": 39.984,+ "marks": {+ "n2": 1.94,+ "n3": 4.479,+ "n4": 6.81,+ "n5": 8.88,+ "grow": 10.925,+ "curve": 14.232,+ "close": 17.422,+ "ratio": 19.57,+ "exact": 29.036+ },+ "cues": [+ [+ 0.104,+ "Let's put the counts on a chart."+ ],+ [+ 1.94,+ "Two by two: two operations."+ ],+ [+ 4.479,+ "Three by three: eight."+ ],+ [+ 6.81,+ "Four by four: twenty."+ ],+ [+ 8.88,+ "Five by five: forty."+ ],+ [+ 10.925,+ "Keep going, up to ten by ten: three hundred thirty."+ ],+ [+ 14.232,+ "The dashed curve is n cubed over three."+ ],+ [+ 17.422,+ "The bars stay just under it."+ ],+ [+ 19.57,+ "Divide the count by n cubed over three: for ten, that's zero point nine nine."+ ],+ [+ 25.82,+ "The bigger n is, the closer it gets to one."+ ],+ [+ 29.036,+ "The exact count is n cubed minus n, over three."+ ],+ [+ 33.411,+ "For ten: a thousand minus ten is nine hundred ninety, and a third of that is three hundred thirty."+ ]+ ]+ },+ "pyr": {+ "dur": 41.712,+ "marks": {+ "stack": 1.172,+ "l1": 5.495,+ "l2": 11.628,+ "all": 15.469,+ "box": 19.01,+ "cone": 23.307,+ "third": 28.62,+ "steps": 36.432+ },+ "cues": [+ [+ 0.104,+ "Why a third?"+ ],+ [+ 1.172,+ "Stack the steps on top of the matrix, one layer for each step."+ ],+ [+ 5.495,+ "The first layer covers the corner the first step works on."+ ],+ [+ 9.102,+ "Each square on it is one operation."+ ],+ [+ 11.628,+ "The second layer sits on top, one smaller each way."+ ],+ [+ 15.469,+ "Then the third, and so on, up to the last little step."+ ],+ [+ 19.01,+ "The layers build a staircase inside a box, n by n by n."+ ],+ [+ 23.307,+ "The staircase hugs a pyramid, with a base n by n and a height of n."+ ],+ [+ 28.62,+ "A pyramid holds one third of its box: base times height, divided by three."+ ],+ [+ 34.206,+ "That's n cubed over three."+ ],+ [+ 36.432,+ "The steps leave out a sliver along the edges: that's the minus n over three."+ ]+ ]+ },+ "q2": {+ "dur": 8.16,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Your turn."+ ],+ [+ 1.055,+ "Change n until elimination needs more than a thousand operations, with n as small as it can be."+ ]+ ]+ },+ "double": {+ "dur": 28.8,+ "marks": {+ "ten": 3.151,+ "twenty": 6.458,+ "eight": 9.922,+ "big": 16.68,+ "huge": 24.518+ },+ "cues": [+ [+ 0.104,+ "What happens when the matrix gets twice as big?"+ ],+ [+ 3.151,+ "Ten by ten: three hundred thirty operations."+ ],+ [+ 6.458,+ "Twenty by twenty: two thousand six hundred sixty."+ ],+ [+ 9.922,+ "That's eight times as many, because two cubed is eight."+ ],+ [+ 13.724,+ "Twice the size, eight times the work."+ ],+ [+ 16.68,+ "A thousand by a thousand takes about three hundred thirty-three million operations."+ ],+ [+ 21.589,+ "A computer does that in well under a second."+ ],+ [+ 24.518,+ "But a million by a million would keep a fast computer busy for days."+ ]+ ]+ },+ "right": {+ "dur": 44.112,+ "marks": {+ "b": 1.68,+ "f1": 6.836,+ "f2": 10.378,+ "back": 11.693,+ "r3": 14.349,+ "r2": 16.354,+ "r1": 20.169,+ "nine": 23.021,+ "cheap": 30.378,+ "lu": 36.745+ },+ "cues": [+ [+ 0.104,+ "And the right side, b?"+ ],+ [+ 1.68,+ "Each step changes just one number of b in every row below the pivot."+ ],+ [+ 6.836,+ "For three by three: two numbers in the first step, one in the second."+ ],+ [+ 11.693,+ "Then back substitution, from the bottom up."+ ],+ [+ 14.349,+ "Row three: one division."+ ],+ [+ 16.354,+ "Row two: one multiply-subtract, and a division."+ ],+ [+ 20.169,+ "Row one: two, and a division."+ ],+ [+ 23.021,+ "Three plus six: nine operations, three squared."+ ],+ [+ 27.253,+ "For any n, b costs n squared."+ ],+ [+ 30.378,+ "So a new right side is cheap: n squared, against n cubed over three for A."+ ],+ [+ 36.745,+ "That's why we keep L and U."+ ],+ [+ 38.32,+ "We factor A once, the expensive part, and then every new b costs only n squared."+ ]+ ]+ },+ "q3": {+ "dur": 3.528,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.133,+ "Count for a six by six matrix."+ ]+ ]+ },+ "wrap": {+ "dur": 38.088,+ "marks": {+ "w1": 1.003,+ "w2": 10.339,+ "w3": 21.029,+ "w4": 29.74,+ "end": 35.925+ },+ "cues": [+ [+ 0.104,+ "Let's sum up."+ ],+ [+ 1.003,+ "One operation is one number below a pivot changing: a multiplication and a subtraction, or the division that finds the multiplier."+ ],+ [+ 10.339,+ "A step on a k by k corner costs k minus one, times k."+ ],+ [+ 15.378,+ "For n by n, the steps add up to n cubed minus n, over three."+ ],+ [+ 21.029,+ "That's about n cubed over three, a third of an n by n by n box."+ ],+ [+ 26.445,+ "Twice the size means eight times the work."+ ],+ [+ 29.74,+ "The right side b costs only n squared, so we factor A once and keep L and U."+ ],+ [+ 35.925,+ "Now try the chapter practice."+ ]+ ]+ },+ "final1": {+ "dur": 4.08,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Chapter practice."+ ],+ [+ 1.51,+ "Count the operations of one step."+ ]+ ]+ },+ "final2": {+ "dur": 3.192,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Set two."+ ],+ [+ 1.068,+ "Count the whole elimination."+ ]+ ]+ },+ "final3": {+ "dur": 3.456,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Set three."+ ],+ [+ 1.185,+ "Estimate, and compare A with b."+ ]+ ]+ },+ "final4": {+ "dur": 4.68,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Last set."+ ],+ [+ 1.289,+ "Change n with your own hands until the count is right."+ ]+ ]+ },+ "play": {+ "dur": 11.352,+ "marks": {+ "go": 4.245+ },+ "cues": [+ [+ 0.104,+ "Playground."+ ],+ [+ 1.094,+ "Nothing here is marked right or wrong."+ ],+ [+ 4.245,+ "Change n, from two up to sixty, and watch the steps, the staircase and the chart grow together."+ ]+ ]+ },+ "finish": {+ "dur": 13.272,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Well done."+ ],+ [+ 1.094,+ "That's the end of chapter thirty-three, How Much Work Is Elimination?"+ ],+ [+ 5.964,+ "Next: chapter thirty-four, where a row exchange joins the factors, and P A equals L U."+ ]+ ]+ }+};diff --git a/site/linear-algebra/ch33/audio/en/wrap.mp3 b/site/linear-algebra/ch33/audio/en/wrap.mp3new file mode 100644index 0000000..c563087Binary files /dev/null and b/site/linear-algebra/ch33/audio/en/wrap.mp3 differdiff --git a/site/linear-algebra/ch33/index.html b/site/linear-algebra/ch33/index.htmlnew file mode 100644index 0000000..b8f90a5--- /dev/null+++ b/site/linear-algebra/ch33/index.html@@ -0,0 +1,321 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>How Much Work Is Elimination?</title>+<link rel="stylesheet" href="../lib/engine.css">+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->+</head>+<body>+<script src="../lib/engine.js"></script>+<script src="../lib/math.js"></script>+<script src="../lib/cost.js"></script>+<script src="../lib/play.js"></script>+<script src="audio/en/timings.js"></script>+<script>+'use strict';+const CHAPTER = { number: 33, title: 'How Much Work Is Elimination?', minutes: 9, language: 'en', next: '../ch34/' };++/* ---------- chapter helpers ---------- */+const A2 = [[2, 1], [8, 7]]; // chapter 30's matrix (OCW 18.06, lecture 4)+const A3 = [[2, 1, 1], [4, 3, 3], [8, 7, 9]]; // pivots 2, 1, 2+const CHART = { x: 1090, y: 770, w: 440, h: 470 };+const say = (p, parts, x, y, t0, { size = 40, fill = COL.chalk, anchor = 'start' } = {}) => { const e = M(p, [].concat(parts), { x, y, size, fill, anchor, o: 0 }); show(e, t0); return e; };+const text = (p, str, x, y, t0, { size = 30, fill = COL.chalk, anchor = 'start', weight = 500 } = {}) => { const e = T(p, str, { x, y, size, fill, anchor, weight, o: 0 }); show(e, t0); return e; };+const title = (p, str) => text(p, str, 60, 110, .2, { size: 40, weight: 600 });+// hide the readout lines a beat does not use yet+const quietRead = (ce, keep = ['n', 'ops']) => ['n', 'ops', 'third', 'ratio'].forEach(k => { if (!keep.includes(k)) put(ce.parts.read[k], { o: 0 }); });+// operations c0 + 1 … c1 one at a time, spread evenly from t0 to t1+const steps = (ce, c0, c1, t0, t1) => { for (let c = c0 + 1; c <= c1; c++) ce.to({ c }, t0 + (t1 - t0) * (c - c0 - 1) / (c1 - c0), .25, lin); };+// a glow behind the dashed curve of the chart+// a soft box over cells [i, j] of a cost grid, for a moment (the cells the voice is naming)+const cellGlow = (p, { x, y, w }, n, cells, at, len = 2) => {+ const cs = w / n, g = G(p, { o: 0 });+ cells.forEach(([i, j]) => mk('rect', { x: x + j * cs + 3, y: y + i * cs + 3, width: cs - 6, height: cs - 6, rx: 8, fill: 'none', stroke: COL.chalk, 'stroke-width': 4 }, g));+ show(g, at, .25); hide(g, at + len, .4);+ return g;+};+const curveFlash = (ce, at) => { tw(ce.parts.curve, { 'a_stroke-width': 7 }, at, .3); tw(ce.parts.curve, { 'a_stroke-width': 3 }, at + 1.4, .5); };++/* ---------- practice data (every count done twice: step by step, and by (n³ − n)/3) ---------- */+const STAGEQ = [+ { parts: ['5 × 5, step 1: ', { box: '4' }, ' rows × ', { box: '5' }, ' numbers = ', { box: '20' }], why: 'Four rows below the first pivot, five numbers in each.', hint: 'Every row but the pivot row changes; every number in it changes.' },+ { parts: ['6 × 6, step 1: ', { box: '30' }, ' operations'], why: '5 rows × 6 numbers = 30.', hint: 'Rows below the pivot, times numbers in a row.' },+ { parts: ['6 × 6, step 3: the corner is ', { box: '4' }, ' × 4, so ', { box: '12' }, ' operations'], why: 'After two steps a 4 × 4 corner is left: 3 rows × 4 numbers = 12.', hint: 'Each step leaves a corner one smaller.' },+ { parts: ['7 × 7, the last step: ', { box: '2' }, ' operations'], why: 'The last corner is 2 × 2: 1 row × 2 numbers.', hint: 'The last step works on a 2 × 2 corner.' },+ { parts: ['10 × 10, step 1: ', { box: '90' }, ' operations'], why: '9 rows × 10 numbers.', hint: '(k − 1) × k with k = 10.' },+];+const TOTALQ = [+ { parts: ['3 × 3: ', { box: '8' }], why: '6 + 2 = 8; (27 − 3)/3 = 8.', hint: 'Steps of 3 × 2 and 2 × 1.' },+ { parts: ['5 × 5: ', { box: '40' }], why: '20 + 12 + 6 + 2 = 40; (125 − 5)/3 = 40.', hint: 'Add the steps, or use (n³ − n)/3.' },+ { parts: ['6 × 6: ', { box: '70' }], why: '30 + 20 + 12 + 6 + 2 = 70; (216 − 6)/3 = 70.', hint: '6³ = 216.' },+ { parts: ['7 × 7: ', { box: '112' }], why: '(343 − 7)/3 = 336/3 = 112.', hint: '7³ = 343.' },+ { parts: ['10 × 10: ', { box: '330' }], why: '(1000 − 10)/3 = 330.', hint: '10³ = 1000.' },+];+const GROWQ = [+ { parts: ['n = 30: about n³/3 = ', { box: '9000' }, ' operations'], why: '30³ = 27,000; a third is 9,000 (exactly 8,990).', hint: '30³ = 27,000.' },+ { parts: ['n doubles: the work is multiplied by about ', { box: '8' }], why: '(2n)³ = 8n³.', hint: 'What is 2³?' },+ { parts: ['n triples: the work is multiplied by about ', { box: '27' }], why: '(3n)³ = 27n³.', hint: 'What is 3³?' },+ { parts: ['n = 4: b costs ', { box: '16' }, ' operations'], why: 'b costs n² = 16 (6 forward, 10 back).', hint: 'b costs n squared.' },+ { parts: ['n = 100: b costs ', { box: '10000' }, ', A about ', { box: '333333' }], why: 'n² = 10,000; n³/3 ≈ 333,333 (exactly 333,300).', hint: '100² and 100³/3.' },+];+// near the exact count is fine for "about": within 1 %+const HANDS = [+ { n0: 4, test: v => v.n === 7, ans: 7, prompt: 'Find the n whose elimination takes exactly 112 operations.', why: 'n = 7: (343 − 7)/3 = 112.',+ hint: v => `n = ${v.n} takes ${coFmt(coTotal(v.n))}.` },+ { n0: 4, test: v => v.n === 25, ans: 25, prompt: 'Find the smallest n that needs more than 5,000 operations.', why: 'n = 25: 5,200. n = 24 needs only 4,600.',+ hint: v => v.n < 25 ? `n = ${v.n}: ${coFmt(coTotal(v.n))}, not more than 5,000 yet.` : `n = ${v.n}: ${coFmt(coTotal(v.n))}. A smaller n is enough.` },+ { n0: 4, test: v => v.n === 32, ans: 32, prompt: 'Find the smallest n that needs more than 10,000 operations.', why: 'n = 32: 10,912. n = 31 needs 9,920.',+ hint: v => v.n < 32 ? `n = ${v.n}: ${coFmt(coTotal(v.n))}, not more than 10,000 yet.` : `n = ${v.n}: ${coFmt(coTotal(v.n))}. A smaller n is enough.` },+];++/* ---------- beats ---------- */+const BEATS = [+ ['intro', 'How much work?', (m, D) => {+ const g = G(scene, { o: 0, y: 24 });+ T(g, 'Unit 4, Chapter 33', { x: 800, y: 230, size: 28, fill: COL.dim, anchor: 'middle' });+ T(g, 'How Much Work Is Elimination?', { x: 800, y: 330, size: 76, weight: 600, anchor: 'middle' });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);+ const r = text(scene, 'count every operation: about n³/3 for n × n', 800, 420, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });+ const lg = G(scene, { o: 0 }); show(lg, m('sub') + 1, .5);+ const ce = cost(lg, { n: 2, chart: { x: 560, y: 820, w: 480, h: 260, N: 10 }, t0: 0 });+ ce.to({ n: 10 }, m('move') + .3, 3.4, lin);+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);+ }],++ ['one', 'One operation', (m) => {+ const p = panel(0);+ title(p, 'What is one operation?');+ const ce = cost(p, { n: 2, A: A2, grid: { x: 140, y: 220, w: 260, work: [140, 580] }, chart: { ...CHART, N: 4 }, read: { x: 500, y: 290 }, t0: .3 });+ quietRead(ce); ce.set({ c: 0 });+ put(ce.parts.chart, { o: 0 }); show(ce.parts.chart, m('chart'), .5);+ const GR1 = { x: 140, y: 220, w: 260 };+ cellGlow(p, GR1, 2, [[1, 0], [1, 1]], m('A') + 2, 3.5);+ cellGlow(p, GR1, 2, [[1, 0]], m('l') + .3, 2.2); cellGlow(p, GR1, 2, [[0, 0]], m('l') + 2.6, 1.8);+ cellGlow(p, GR1, 2, [[1, 1]], m('seven') + .2, 2.6); cellGlow(p, GR1, 2, [[0, 1]], m('seven') + 1.4, 1.4);+ cellGlow(p, GR1, 2, [[1, 0], [1, 1]], m('total') + .4, 3);+ cellGlow(p, GR1, 2, [[1, 0], [1, 1]], m('rule') + 2, 3);+ ce.to({ c: 1 }, m('l') + 4, .3, lin);+ ce.to({ c: 2 }, m('seven') + 1.6, .3, lin);+ text(p, 'a multiply and a subtract: one operation', 140, 680, m('seven') + 5, { size: 28, fill: COL.dim, weight: 600 });+ text(p, 'every number below a pivot that changes: 1 operation', 140, 760, m('rule'), { size: 30, weight: 600 });+ }],++ ['three', 'Three by three', (m) => {+ const p = panel(0);+ title(p, 'Counting a 3 × 3');+ const ce = cost(p, { n: 3, A: A3, grid: { x: 130, y: 210, w: 330, work: [130, 610] }, chart: { ...CHART, N: 4 }, read: { x: 530, y: 260 }, t0: .3 });+ quietRead(ce); ce.set({ c: 0 });+ const GR3 = { x: 130, y: 210, w: 330 };+ cellGlow(p, GR3, 3, [[0, 0]], m('s1'), 4.5); cellGlow(p, GR3, 3, [[1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]], m('s1') + 2, 3);+ cellGlow(p, GR3, 3, [[1, 1]], m('s2'), 4.5); cellGlow(p, GR3, 3, [[2, 1], [2, 2]], m('s2') + 2.4, 3);+ cellGlow(p, GR3, 3, [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]], m('corner') + .6, 2.4);+ cellGlow(p, GR3, 3, [[1, 1], [1, 2], [2, 1], [2, 2]], m('corner') + 3.4, 2.6);+ steps(ce, 0, 3, m('go1') + .8, m('row3') - 1.5);+ steps(ce, 3, 6, m('row3') + .8, m('six') - 1.5);+ text(p, 'step 1: 2 rows × 3 numbers = 6', 530, 420, m('six'), { size: 30, weight: 600 });+ steps(ce, 6, 8, m('go2') + .6, m('two') - 1.2);+ text(p, 'step 2: 1 row × 2 numbers = 2', 530, 470, m('two'), { size: 30, weight: 600 });+ text(p, 'total: 6 + 2 = 8', 530, 530, m('tot'), { size: 30, weight: 600 });+ text(p, 'each step: a smaller corner', 130, 720, m('corner'), { size: 28, fill: COL.dim, weight: 600 });+ }],++ ['four', 'Four by four', (m) => {+ const p = panel(0);+ title(p, 'Counting a 4 × 4');+ const ce = cost(p, { n: 4, grid: { x: 130, y: 210, w: 320 }, chart: { ...CHART, N: 5 }, read: { x: 530, y: 260 }, t0: .3 });+ quietRead(ce); ce.set({ c: 0 });+ ce.count(1, m('s1') + .3, 3, lin);+ text(p, '3 rows × 4 numbers = 12', 530, 420, m('s1') + .5, { size: 30, weight: 600 });+ ce.count(2, m('s2') + .2, 2, lin);+ text(p, '2 rows × 3 numbers = 6', 530, 470, m('s2') + .4, { size: 30, weight: 600 });+ ce.count(3, m('s3') + .2, 1, lin);+ text(p, '1 row × 2 numbers = 2', 530, 520, m('s3') + .4, { size: 30, weight: 600 });+ text(p, 'total: 12 + 6 + 2 = 20', 530, 580, m('tot'), { size: 30, weight: 600 });+ say(p, ['a k × k corner: (k − 1) · k ≈ k²'], 130, 660, m('pat'), { size: 32 });+ const GR4 = { x: 130, y: 210, w: 320 }, blk = (r0, c0) => { const o = []; for (let i = r0; i < 4; i++) for (let j = c0; j < 4; j++) o.push([i, j]); return o; };+ cellGlow(p, GR4, 4, blk(0, 0), m('pat') + 1.5, 1.6); cellGlow(p, GR4, 4, blk(1, 1), m('pat') + 3.3, 1.6); cellGlow(p, GR4, 4, blk(2, 2), m('pat') + 5.1, 1.6);+ curveFlash(ce, m('sum') + 2);+ say(p, ['big n: n(n − 1) + … + 2·1 ≈ n² + (n − 1)² + … + 1²'], 130, 730, m('sum'), { size: 30, fill: COL.dim });+ }],++ ['q1', 'Quick check', () => {+ const p = panel(0);+ title(p, 'Quick check');+ const ce = cost(p, { n: 5, grid: { x: 130, y: 180, w: 240 }, chart: { ...CHART, N: 5 }, read: { x: 530, y: 260 } });+ quietRead(ce); ce.set({ c: 0 });+ S.ce = ce;+ }, { ask: done => quiz({ x: 40, y: 450, w: 800, cls: 'side' }, [{+ id: 'c-five', prompt: ['Count the operations for 5 × 5, one step at a time.'],+ build: blanks([+ { parts: ['step 1: ', { box: '4' }, ' rows × ', { box: '5' }, ' numbers = ', { box: '20' }], why: 'Four rows below the pivot, five numbers in each.', hint: 'Every row below the pivot row, every number in it.' },+ { parts: ['steps 2, 3, 4: ', { box: '12' }, ' + ', { box: '6' }, ' + ', { box: '2' }, ', total ', { box: '40' }], why: 'Corners 4 × 4, 3 × 3, 2 × 2: 12 + 6 + 2; with step 1, 20 + 12 + 6 + 2 = 40.', hint: 'Each corner is one smaller: (k − 1) · k. Then add all four steps.',+ fx: () => fxp(q => S.ce.set({ c: 40 * q }), 0, 2.4, lin) },+ ]),+ }], done) }],++ ['chart', 'The chart', (m) => {+ const p = panel(0);+ title(p, 'The counts on a chart');+ const ce = cost(p, { n: 2, grid: { x: 90, y: 470, w: 240 }, chart: { x: 760, y: 780, w: 760, h: 560, N: 5 }, read: { x: 90, y: 230 }, t0: .3 });+ quietRead(ce, ['n', 'ops', 'third']);+ put(ce.parts.read.third, { o: 0 }); show(ce.parts.read.third, m('curve'), .4);+ ce.to({ n: 3 }, m('n3'), .1); ce.to({ n: 4 }, m('n4'), .1); ce.to({ n: 5 }, m('n5'), .1);+ ce.to({ n: 10 }, m('grow') + .3, 3.4, lin);+ curveFlash(ce, m('curve') + .3);+ show(ce.parts.read.ratio, m('ratio'), .4);+ ce.to({ n: 3 }, m('ratio') + 5, .2); ce.to({ n: 10 }, m('ratio') + 5.6, 3.6, lin);+ say(p, ['= 990 ÷ 3'], 400, 845, m('exact') + 6, { size: 30, fill: COL.dim });+ say(p, ['(n³ − n)/3: (1000 − 10)/3 = 330'], 90, 790, m('exact') + 1, { size: 32 });+ }],++ ['pyr', 'Why a third', (m) => {+ const p = panel(0);+ title(p, 'Why a third?');+ const ce = cost(p, { n: 6, pyr: { x: 760, y: 790, size: 460 }, read: { x: 90, y: 260 }, t0: .3 });+ quietRead(ce); ce.set({ c: 0 });+ put(ce.parts.box, { o: 0 }); show(ce.parts.box, m('box'), .6);+ ce.count(1, m('l1') + .3, 3.5, lin);+ ce.count(2, m('l2') + .2, 2.4, lin);+ ce.to({ c: coTotal(6) }, m('all') + .2, 2.6, lin);+ text(p, 'layer 1: 5 × 6 = 30', 90, 420, m('l1') + 1, { size: 28, weight: 600 });+ text(p, 'layer 2: 4 × 5 = 20', 90, 465, m('l2') + .5, { size: 28, weight: 600 });+ text(p, '… 12, 6, 2: 70 in all', 90, 510, m('all') + 2, { size: 28, weight: 600 });+ text(p, 'box: 6 × 6 × 6 = 216', 90, 600, m('box') + .4, { size: 28, fill: COL.dim, weight: 600 });+ tw(ce.parts.cone, { o: 1 }, m('cone') + .3, .8);+ say(p, ['pyramid: ', F(1, 3), ' · base · height'], 90, 660, m('third'), { size: 30 });+ say(p, ['= ', F(1, 3), ' · 6² · 6 = 72'], 110, 720, m('third') + 2.6, { size: 30 });+ say(p, ['steps: 70 = 72 − 6/3'], 90, 800, m('steps') + .6, { size: 30, fill: COL.dim });+ tw(ce.parts.cone, { 'a_fill-opacity': .16 }, m('third') + 4, .6); tw(ce.parts.cone, { 'a_fill-opacity': 0 }, m('third') + 7, .8);+ tw(ce.parts.box, { 'a_stroke-width': 4 }, m('steps') + 2.4, .4); tw(ce.parts.box, { 'a_stroke-width': 2 }, m('steps') + 4, .6);+ }],++ ['q2', 'Your turn', () => {+ const p = panel(0);+ title(p, 'Your turn');+ const ce = cost(p, { n: 4, chart: { x: 760, y: 780, w: 760, h: 560, N: 10 }, read: { x: 90, y: 260 } });+ quietRead(ce, ['n', 'ops', 'third']);+ S.ce = ce;+ }, { ask: done => quiz({ x: 40, y: 520, w: 640, cls: 'side' }, [{+ id: 'c-thousand', prompt: ['Change n until elimination needs more than 1,000 operations, with n as small as it can be.'],+ build: costTask(S.ce, v => v.n === 15, 'n = 15: (3375 − 15)/3 = 1,120. n = 14 needs only 910.',+ v => v.n < 15 ? `n = ${v.n} needs ${coFmt(coTotal(v.n))}: not more than 1,000 yet.` : `n = ${v.n} needs ${coFmt(coTotal(v.n))}: more than 1,000, but a smaller n does it too.`, () => S.ce.set({ n: 15 })),+ }], done) }],++ ['double', 'Twice the size', (m) => {+ const p = panel(0);+ title(p, 'Twice the size');+ const ce = cost(p, { n: 10, chart: { x: 760, y: 780, w: 760, h: 560, N: 10 }, read: { x: 90, y: 260 }, t0: .3 });+ quietRead(ce, ['n', 'ops', 'third']);+ ce.to({ n: 20 }, m('twenty') + .2, 2.6, lin);+ say(p, ['2660 ÷ 330 ≈ 8 = 2³'], 90, 470, m('eight'), { size: 34 });+ say(p, ['twice n: × 8'], 90, 530, m('eight') + 4, { size: 34, fill: COL.chalk });+ curveFlash(ce, m('ten') + .5);+ text(p, '1000 × 1000: about 333,333,333 operations', 90, 600, m('big') + .5, { size: 28, weight: 600 });+ text(p, 'well under a second on a computer', 90, 645, m('big') + 5, { size: 26, fill: COL.dim, weight: 600 });+ text(p, 'a million × a million: days', 90, 730, m('huge') + .5, { size: 28, weight: 600 });+ }],++ ['right', 'And b?', (m) => {+ const p = panel(0);+ title(p, 'And the right side b?');+ const cs = 96, x0 = 140, y0 = 220, cell = (i, j) => [x0 + j * cs + (j === 3 ? 24 : 0), y0 + i * cs];+ const U = [[2, 1, 1], [0, 1, 1], [0, 0, 2]], bb = ['b₁', 'b₂', 'b₃'];+ const g = G(p, { o: 0 }); show(g, .4, .5);+ const lit = {};+ for (let i = 0; i < 3; i++) for (let j = 0; j < 4; j++) {+ const [x, y] = cell(i, j);+ const r = mk('rect', { x, y, width: cs, height: cs, fill: COL.chalk, 'fill-opacity': j === 3 ? .14 : .08, stroke: COL.faint, 'stroke-width': 1.5 }, g);+ const hl = mk('rect', { x: x + 4, y: y + 4, width: cs - 8, height: cs - 8, rx: 8, fill: COL.chalk, 'fill-opacity': .5 }, g);+ put(hl, { o: 0 }); lit[`${i}${j}`] = hl;+ M(g, j === 3 ? [bb[i]] : [num(U[i][j])], { x: x + cs / 2, y: y + cs / 2 + 13, size: 36, fill: j === 3 ? COL.task : (i > j ? COL.faint : COL.chalk), anchor: 'middle' });+ }+ path(g, `M${x0 + 3 * cs + 12} ${y0 - 6}V${y0 + 3 * cs + 6}`, { stroke: COL.dim, 'stroke-width': 2.5, 'stroke-dasharray': '6 6' });+ const on = (cells, at, len = 2.2) => cells.forEach(k => { tw(lit[k], { o: 1 }, at, .25); tw(lit[k], { o: .35 }, at + len, .5); });+ // the counter: 0 → 2 → 3 (forward), → 4 → 6 → 9 (back)+ const cnt = G(p, { o: 0 }); show(cnt, m('b'), .4);+ T(cnt, 'operations on b:', { x: 140, y: 590, size: 30, weight: 600 });+ const cv = G(cnt, {});+ let shown = -1;+ const counts = [[0, 0], [m('f1') + .6, 2], [m('f2') + .5, 3], [m('r3') + .6, 4], [m('r2') + .8, 6], [m('r1') + .8, 9]];+ counts.forEach(([t, v]) => prog(q => { if (q > 0 && shown !== v) { shown = v; cv.replaceChildren(); T(cv, String(v), { x: 400, y: 590, size: 34, fill: COL.task, weight: 700 }); } }, t, 0, lin));+ on(['13', '23'], m('f1') + .3);+ on(['23'], m('f2') + .3);+ text(p, 'forward: 2 + 1 = 3', 600, 300, m('f2') + 1.2, { size: 28, weight: 600 });+ on(['22', '23'], m('r3') + .3);+ on(['11', '12', '13'], m('r2') + .3);+ on(['00', '01', '02', '03'], m('r1') + .3);+ text(p, 'back: 1 + 2 + 3 = 6', 600, 350, m('r1') + 1.5, { size: 28, weight: 600 });+ say(p, ['3 + 6 = 9 = 3²: b costs n²'], 600, 420, m('nine') + .5, { size: 32 });+ on(['03', '13', '23'], m('nine') + 2.4, 2.6);+ const tb = G(p, { o: 0 }); show(tb, m('cheap'), .5);+ const tbh = mk('rect', { x: 588, y: 612, width: 820, height: 44, rx: 10, fill: COL.chalk, 'fill-opacity': .13 }, tb); put(tbh, { o: 0 });+ tw(tbh, { o: 1 }, m('cheap') + 3.5, .3); tw(tbh, { o: 0 }, m('lu') + 4, .6);+ [['n', 'A: about n³/3', 'b: n²'], ['10', '330', '100'], ['1000', '333,333,000', '1,000,000']].forEach((row, i) => row.forEach((s, j) =>+ T(tb, s, { x: 600 + [0, 150, 480][j], y: 520 + i * 50, size: 28, fill: i ? COL.chalk : COL.dim, weight: 600 })));+ text(p, 'factor A = LU once; each new b: n² only', 140, 760, m('lu') + 1, { size: 30, weight: 600 });+ }],++ ['q3', 'Quick check', () => {+ const p = panel(0);+ title(p, 'Quick check');+ const ce = cost(p, { n: 6, grid: { x: 130, y: 180, w: 240 }, chart: { ...CHART, N: 6 }, read: { x: 530, y: 260 } });+ quietRead(ce); ce.set({ c: 0 });+ S.ce = ce;+ }, { ask: done => quiz({ x: 40, y: 450, w: 800, cls: 'side' }, [{+ id: 'c-six', prompt: ['Count for a 6 × 6 matrix.'],+ build: blanks([+ { parts: ['elimination on A: (6³ − 6)/3 = ', { box: '70' }], why: '(216 − 6)/3 = 70: 30 + 20 + 12 + 6 + 2.', hint: '6³ = 216.', fx: () => fxp(q => S.ce.set({ c: 70 * q }), 0, 2.4, lin) },+ { parts: ['b, forward and back: ', { box: '36' }, ', n³/3 = ', { box: '72' }], why: 'b costs n² = 36 (15 forward, 21 back); 216 ÷ 3 = 72, just above the exact 70.', hint: 'b costs n squared; n³/3 is 6³ ÷ 3.' },+ ]),+ }], done) }],++ ['wrap', 'Summary', (m) => {+ const p = panel(0);+ [['One operation: one number below a pivot changes.', 'w1'], ['A k × k corner costs (k − 1) · k; n × n costs (n³ − n)/3.', 'w2'],+ ['About n³/3: a third of the box. Twice n, eight times the work.', 'w3'], ['b costs only n²: factor A once, keep L and U.', 'w4']].forEach(([str, mark], i) => {+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });+ mk('circle', { cx: 120, cy: -12, r: 26, fill: COL.chalk }, g);+ T(g, String(i + 1), { x: 120, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });+ T(g, str, { x: 170, size: 34, weight: 600 });+ tw(g, { o: 1, x: 0 }, m(mark), .6);+ });+ }],+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{+ id: 'p-stage', prompt: ['One step: the rows below the pivot, times the numbers in each row.'],+ build: blanks(STAGEQ),+ }], done, 'Chapter practice · set 1 of 4') }],+ ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{+ id: 'p-total', prompt: ['The whole elimination of A: add the steps, or use (n³ − n)/3.'],+ build: blanks(TOTALQ),+ }], done, 'Chapter practice · set 2 of 4') }],+ ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{+ id: 'p-grow', prompt: ['Estimate with n³/3 for A and n² for b.'],+ build: blanks(GROWQ),+ }], done, 'Chapter practice · set 3 of 4') }],+ ['final4', 'Chapter practice', () => {+ const p = panel(0);+ title(p, 'Find n');+ const ce = cost(p, { n: 4, chart: { x: 760, y: 780, w: 760, h: 560, N: 10 }, read: { x: 90, y: 260 } });+ quietRead(ce, ['n', 'ops', 'third']);+ S.ce = ce;+ }, { ask: done => quiz({ x: 40, y: 520, w: 640, cls: 'side' }, HANDS.map((h, k) => ({+ id: `p-hand${k + 1}`, prompt: [h.prompt],+ build: (body, api) => { S.ce.set({ n: h.n0 }); return costTask(S.ce, h.test, h.why, h.hint, () => S.ce.set({ n: h.ans }))(body, api); },+ })), done, 'Chapter practice · set 4 of 4') }],+ ['play', 'Playground', (m) => {+ const p = panel(0);+ title(p, 'Playground');+ const ce = cost(p, { n: 5, grid: { x: 420, y: 170, w: 170 }, pyr: { x: 760, y: 780, size: 300 }, chart: { x: 1080, y: 780, w: 440, h: 480, N: 10 }, read: { x: 70, y: 200, gap: 46, size: 30 } });+ S.ce = ce;+ const hint = text(p, 'try: n = 2; n = 20; n = 60', 300, 110, m('go'), { size: 24, fill: COL.dim });+ hide(hint, m('go') + 7, .6);+ }, { ask: playAsk(() => S.ce, { pos: { x: 40, y: 450, w: 540, cls: 'side' }, tip: 'Change n and watch every part follow. Draw on the board if you like. Nothing is marked.' }) }],+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));++boot();+</script>+</body>+</html>diff --git a/site/linear-algebra/ch34/audio/en/both.mp3 b/site/linear-algebra/ch34/audio/en/both.mp3new file mode 100644index 0000000..dbe1c3eBinary files /dev/null and b/site/linear-algebra/ch34/audio/en/both.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/elim.mp3 b/site/linear-algebra/ch34/audio/en/elim.mp3new file mode 100644index 0000000..09025a9Binary files /dev/null and b/site/linear-algebra/ch34/audio/en/elim.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/ex2.mp3 b/site/linear-algebra/ch34/audio/en/ex2.mp3new file mode 100644index 0000000..06ed014Binary files /dev/null and b/site/linear-algebra/ch34/audio/en/ex2.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/ex3.mp3 b/site/linear-algebra/ch34/audio/en/ex3.mp3new file mode 100644index 0000000..ff8e5e8Binary files /dev/null and b/site/linear-algebra/ch34/audio/en/ex3.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/final1.mp3 b/site/linear-algebra/ch34/audio/en/final1.mp3new file mode 100644index 0000000..00934ebBinary files /dev/null and b/site/linear-algebra/ch34/audio/en/final1.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/final2.mp3 b/site/linear-algebra/ch34/audio/en/final2.mp3new file mode 100644index 0000000..76767edBinary files /dev/null and b/site/linear-algebra/ch34/audio/en/final2.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/final3.mp3 b/site/linear-algebra/ch34/audio/en/final3.mp3new file mode 100644index 0000000..d0e1812Binary files /dev/null and b/site/linear-algebra/ch34/audio/en/final3.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/final4.mp3 b/site/linear-algebra/ch34/audio/en/final4.mp3new file mode 100644index 0000000..fbd8a02Binary files /dev/null and b/site/linear-algebra/ch34/audio/en/final4.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/finish.mp3 b/site/linear-algebra/ch34/audio/en/finish.mp3new file mode 100644index 0000000..0e6308fBinary files /dev/null and b/site/linear-algebra/ch34/audio/en/finish.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/intro.mp3 b/site/linear-algebra/ch34/audio/en/intro.mp3new file mode 100644index 0000000..2b7575bBinary files /dev/null and b/site/linear-algebra/ch34/audio/en/intro.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/inv.mp3 b/site/linear-algebra/ch34/audio/en/inv.mp3new file mode 100644index 0000000..afc52e0Binary files /dev/null and b/site/linear-algebra/ch34/audio/en/inv.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/play.mp3 b/site/linear-algebra/ch34/audio/en/play.mp3new file mode 100644index 0000000..bdbc478Binary files /dev/null and b/site/linear-algebra/ch34/audio/en/play.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/q1.mp3 b/site/linear-algebra/ch34/audio/en/q1.mp3new file mode 100644index 0000000..8636e6dBinary files /dev/null and b/site/linear-algebra/ch34/audio/en/q1.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/q2.mp3 b/site/linear-algebra/ch34/audio/en/q2.mp3new file mode 100644index 0000000..5b4ea35Binary files /dev/null and b/site/linear-algebra/ch34/audio/en/q2.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/q3.mp3 b/site/linear-algebra/ch34/audio/en/q3.mp3new file mode 100644index 0000000..94147b6Binary files /dev/null and b/site/linear-algebra/ch34/audio/en/q3.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/recall.mp3 b/site/linear-algebra/ch34/audio/en/recall.mp3new file mode 100644index 0000000..d4fbcaeBinary files /dev/null and b/site/linear-algebra/ch34/audio/en/recall.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/timings.js b/site/linear-algebra/ch34/audio/en/timings.jsnew file mode 100644index 0000000..6a44500--- /dev/null+++ b/site/linear-algebra/ch34/audio/en/timings.js@@ -0,0 +1,574 @@+window.TIMINGS = {+ "intro": {+ "dur": 14.064,+ "marks": {+ "sub": 4.427,+ "move": 8.841+ },+ "cues": [+ [+ 0.091,+ "Chapter thirty-four."+ ],+ [+ 1.693,+ "P A equals L U."+ ],+ [+ 4.427,+ "When a zero lands in a pivot spot, put the rows in a good order first."+ ],+ [+ 8.841,+ "Then elimination runs without trouble, and P A splits into L times U."+ ]+ ]+ },+ "recall": {+ "dur": 41.256,+ "marks": {+ "sys": 3.359,+ "zero": 9.427,+ "p": 15.117,+ "swap": 21.38,+ "same": 24.466,+ "u": 28.984,+ "lu": 34.818+ },+ "cues": [+ [+ 0.104,+ "Chapter twenty met a zero in the pivot spot."+ ],+ [+ 3.359,+ "Two y equals four, and three x plus y equals five."+ ],+ [+ 7.578,+ "The lines meet at one, two."+ ],+ [+ 9.427,+ "The zero can't be a pivot: no multiple of row one removes the three x."+ ],+ [+ 15.117,+ "Chapter twenty-two wrote the fix as a matrix: P, the identity with its two rows exchanged."+ ],+ [+ 21.38,+ "P times A has the rows in the new order."+ ],+ [+ 24.466,+ "The lines did not move."+ ],+ [+ 26.107,+ "The same two equations, in a new order."+ ],+ [+ 28.984,+ "P A is three, one, and zero, two: already a triangle."+ ],+ [+ 34.818,+ "So U is P A, and L is the identity."+ ],+ [+ 38.568,+ "P A equals L U."+ ]+ ]+ },+ "why": {+ "dur": 25.536,+ "marks": {+ "row1": 3.932,+ "piv": 11.302,+ "zero": 14.388,+ "so": 18.008+ },+ "cues": [+ [+ 0.104,+ "Why not A equals L U, for A itself?"+ ],+ [+ 3.932,+ "In L times U, row one of L is one, zero, zero, so row one of the product is row one of U."+ ],+ [+ 11.302,+ "That makes the top left number of A the first pivot."+ ],+ [+ 14.388,+ "Here it's zero, and a pivot is never zero."+ ],+ [+ 18.008,+ "So no L and U multiply to this A."+ ],+ [+ 20.99,+ "We factor P A instead: the same rows, in a good order."+ ]+ ]+ },+ "ex3": {+ "dur": 47.928,+ "marks": {+ "A": 3.32,+ "c1": 13.737,+ "zero": 20.768,+ "below": 23.802,+ "swap": 25.924,+ "ahead": 30.716,+ "p": 34.961,+ "pa": 40.807+ },+ "cues": [+ [+ 0.104,+ "Now three by three: chapter twenty's system."+ ],+ [+ 3.32,+ "x plus two y plus z equals one, two x plus four y plus three z equals three, and three x plus seven y plus five z equals four."+ ],+ [+ 13.737,+ "Column one: row two minus two times row one, and row three minus three times row one."+ ],+ [+ 20.768,+ "The second pivot spot now holds a zero, but the row under it has a one."+ ],+ [+ 25.924,+ "Exchange rows two and three, and the table is a triangle."+ ],+ [+ 30.716,+ "If we had known, we could have put the rows in that order before we started."+ ],+ [+ 34.961,+ "That order is rows one, three, two: the matrix P two three."+ ],+ [+ 40.807,+ "P A is one, two, one; three, seven, five; two, four, three."+ ]+ ]+ },+ "elim": {+ "dur": 38.208,+ "marks": {+ "l21": 3.021,+ "l31": 7.331,+ "l32": 12.487,+ "u": 17.109,+ "L": 23.047,+ "look": 29.427,+ "moved": 35.026+ },+ "cues": [+ [+ 0.104,+ "Eliminate P A from the start."+ ],+ [+ 3.021,+ "Row two minus three times row one: zero, one, two."+ ],+ [+ 7.331,+ "Row three minus two times row one: zero, zero, one."+ ],+ [+ 12.487,+ "Row three has no y left, so the last multiplier is zero."+ ],+ [+ 17.109,+ "U is one, two, one; zero, one, two; zero, zero, one."+ ],+ [+ 23.047,+ "L holds the multipliers: three and two in column one, zero under the second pivot."+ ],+ [+ 29.427,+ "Look at column one of L."+ ],+ [+ 31.107,+ "Before the exchange, the multipliers were two and three."+ ],+ [+ 35.026,+ "They traded places, along with their rows."+ ]+ ]+ },+ "both": {+ "dur": 47.688,+ "marks": {+ "left": 5.286,+ "pa": 9.766,+ "right": 14.87,+ "r1": 17.904,+ "r2": 23.086,+ "r3": 32.096,+ "eq": 40.573,+ "pic": 43.125+ },+ "cues": [+ [+ 0.104,+ "Now check P A equals L U, by multiplying out both sides."+ ],+ [+ 5.286,+ "The left side: P takes rows one, three and two of A."+ ],+ [+ 9.766,+ "One, two, one; three, seven, five; two, four, three."+ ],+ [+ 14.87,+ "The right side: L times U, row by row."+ ],+ [+ 17.904,+ "Row one of L is one, zero, zero: just row one of U, one, two, one."+ ],+ [+ 23.086,+ "Row two of L is three, one, zero: three times one, two, one, plus zero, one, two."+ ],+ [+ 29.766,+ "That's three, seven, five."+ ],+ [+ 32.096,+ "Row three is two, zero, one: two times one, two, one, plus zero, zero, one."+ ],+ [+ 39.141,+ "Two, four, three."+ ],+ [+ 40.573,+ "Both sides match, number by number."+ ],+ [+ 43.125,+ "And in the picture, L turns U's planes back into the planes of P A."+ ]+ ]+ },+ "q1": {+ "dur": 3.84,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.172,+ "Factor P A for this two by two."+ ]+ ]+ },+ "ex2": {+ "dur": 54.816,+ "marks": {+ "A": 3.073,+ "zero": 8.268,+ "swap": 10.742,+ "l21": 16.419,+ "l31": 23.255,+ "l32": 28.737,+ "LU": 33.945,+ "check": 44.219+ },+ "cues": [+ [+ 0.104,+ "Another one, with the zero right at the start."+ ],+ [+ 3.073,+ "A is zero, one, one; one, two, one; two, seven, nine."+ ],+ [+ 8.268,+ "The first pivot spot is zero."+ ],+ [+ 10.742,+ "Row two has a one there, so exchange rows one and two: P is P one two."+ ],+ [+ 16.419,+ "Now eliminate P A."+ ],+ [+ 18.828,+ "Row two already starts with zero: its multiplier is zero."+ ],+ [+ 23.255,+ "Row three minus two times row one: zero, three, seven."+ ],+ [+ 28.737,+ "Row three minus three times row two: zero, zero, four."+ ],+ [+ 33.945,+ "L has zero, two and three below its diagonal."+ ],+ [+ 38.255,+ "U is one, two, one; zero, one, one; zero, zero, four."+ ],+ [+ 44.219,+ "Check row three of L U: two times row one of U, plus three times row two, plus row three."+ ],+ [+ 51.341,+ "Two, seven, nine: row three of P A."+ ]+ ]+ },+ "q2": {+ "dur": 6.864,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Your turn."+ ],+ [+ 1.003,+ "Change the numbers of P until elimination on P A needs no exchange."+ ]+ ]+ },+ "q3": {+ "dur": 2.352,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.159,+ "Can a P fix this one?"+ ]+ ]+ },+ "inv": {+ "dur": 51.264,+ "marks": {+ "undo": 1.836,+ "cycle": 11.992,+ "back": 20.99,+ "flip": 28.828,+ "name": 35.091,+ "check": 39.779,+ "rule": 43.607,+ "next": 48.372+ },+ "cues": [+ [+ 0.104,+ "One more fact about P."+ ],+ [+ 1.836,+ "To undo P, put the rows back."+ ],+ [+ 4.544,+ "For one exchange, P undoes itself: P times P is the identity, as in chapter twenty-two."+ ],+ [+ 11.992,+ "But take P that moves every row: zero, zero, one; one, zero, zero; zero, one, zero."+ ],+ [+ 20.99,+ "The matrix that undoes it is zero, one, zero; zero, zero, one; one, zero, zero."+ ],+ [+ 28.828,+ "Look closely: it's P flipped across its diagonal."+ ],+ [+ 32.656,+ "Row one of P becomes column one."+ ],+ [+ 35.091,+ "That flip is called the transpose, written P with a small T."+ ],+ [+ 39.779,+ "Multiply: P transpose times P is the identity."+ ],+ [+ 43.607,+ "For every permutation, P inverse is P transpose."+ ],+ [+ 48.372,+ "Transposes are the subject of the next chapter."+ ]+ ]+ },+ "wrap": {+ "dur": 32.52,+ "marks": {+ "w1": 1.016,+ "w2": 9.805,+ "w3": 17.565,+ "w4": 23.997,+ "end": 30.404+ },+ "cues": [+ [+ 0.104,+ "Let's sum up."+ ],+ [+ 1.016,+ "A zero in a pivot spot is fixed by a row exchange, and a permutation P can make every exchange before elimination starts."+ ],+ [+ 9.805,+ "Then P A equals L U: L holds the multipliers, U the pivots, and no exchange is needed on the way."+ ],+ [+ 17.565,+ "Check it by multiplying out both sides: P reorders the rows of A, L mixes the rows of U."+ ],+ [+ 23.997,+ "P inverse is P transpose."+ ],+ [+ 26.875,+ "If no row below has a number, no P can help."+ ],+ [+ 30.404,+ "Now try the chapter practice."+ ]+ ]+ },+ "final1": {+ "dur": 3.312,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Chapter practice."+ ],+ [+ 1.589,+ "Which rows must be exchanged?"+ ]+ ]+ },+ "final2": {+ "dur": 3.744,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Set two."+ ],+ [+ 1.172,+ "Factor P A equals L U."+ ]+ ]+ },+ "final3": {+ "dur": 3.552,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Set three."+ ],+ [+ 1.224,+ "Multiply, and undo P."+ ]+ ]+ },+ "final4": {+ "dur": 5.808,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Last set."+ ],+ [+ 1.146,+ "Build P with your own hands, so elimination needs no exchange."+ ]+ ]+ },+ "play": {+ "dur": 12.6,+ "marks": {+ "go": 3.984+ },+ "cues": [+ [+ 0.104,+ "Playground."+ ],+ [+ 1.12,+ "Nothing here is marked right or wrong."+ ],+ [+ 3.984,+ "Change the numbers of P, or of the system, turn the picture, and see which orders of the rows let elimination run."+ ]+ ]+ },+ "finish": {+ "dur": 11.544,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Well done."+ ],+ [+ 1.12,+ "That's the end of chapter thirty-four, P A equals L U, and the end of unit four."+ ],+ [+ 7.07,+ "Next: unit five, transposes and vector spaces."+ ]+ ]+ }+};diff --git a/site/linear-algebra/ch34/audio/en/why.mp3 b/site/linear-algebra/ch34/audio/en/why.mp3new file mode 100644index 0000000..162b73bBinary files /dev/null and b/site/linear-algebra/ch34/audio/en/why.mp3 differdiff --git a/site/linear-algebra/ch34/audio/en/wrap.mp3 b/site/linear-algebra/ch34/audio/en/wrap.mp3new file mode 100644index 0000000..a4aff59Binary files /dev/null and b/site/linear-algebra/ch34/audio/en/wrap.mp3 differdiff --git a/site/linear-algebra/ch34/index.html b/site/linear-algebra/ch34/index.htmlnew file mode 100644index 0000000..f41d462--- /dev/null+++ b/site/linear-algebra/ch34/index.html@@ -0,0 +1,386 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>PA = LU</title>+<link rel="stylesheet" href="../lib/engine.css">+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->+</head>+<body>+<script src="../lib/engine.js"></script>+<script src="../lib/math.js"></script>+<script src="../lib/linsys.js"></script>+<script src="../lib/space3.js"></script>+<script src="../lib/elim.js"></script>+<script src="../lib/emat.js"></script>+<script src="../lib/play.js"></script>+<script src="audio/en/timings.js"></script>+<script>+'use strict';+const CHAPTER = { number: 34, title: 'PA = LU', minutes: 9, language: 'en', next: '../ch35/' };++/* ---------- chapter helpers (chapters 21, 22 and 32) ---------- */+const ZERO2 = { A: [[0, 2], [3, 1]], b: [4, 5] }; // chapter 20's 2 × 2+const Z3 = { A: [[1, 2, 1], [2, 4, 3], [3, 7, 5]], b: [1, 3, 4] }; // chapter 20's 3 × 3, x = (2, −1, 1)+const PZ3 = { A: [[1, 2, 1], [3, 7, 5], [2, 4, 3]], b: [1, 4, 3] }; // its rows in the order 1, 3, 2+const U3 = { A: [[1, 2, 1], [0, 1, 2], [0, 0, 1]], b: [1, 1, 1] };+const L3 = [[1, 0, 0], [3, 1, 0], [2, 0, 1]], P23 = [[1, 0, 0], [0, 0, 1], [0, 1, 0]];+const EX2 = { A: [[0, 1, 1], [1, 2, 1], [2, 7, 9]], b: [2, 4, 18] }; // x = (1, 1, 1)+const CYC = [[0, 0, 1], [1, 0, 0], [0, 1, 0]], CYCT = [[0, 1, 0], [0, 0, 1], [1, 0, 0]];+const AT2 = [70, 290], AT3 = [64, 262];+const CARD3 = { x: 40, y: 640, w: 820, cls: 'side' };+const say = (p, parts, x, y, t0, { size = 40, fill = COL.chalk, anchor = 'start' } = {}) => { const e = M(p, [].concat(parts), { x, y, size, fill, anchor, o: 0 }); show(e, t0); return e; };+const text = (p, str, x, y, t0, { size = 30, fill = COL.chalk, anchor = 'start', weight = 500 } = {}) => { const e = T(p, str, { x, y, size, fill, anchor, weight, o: 0 }); show(e, t0); return e; };+const title = (p, str) => text(p, str, 60, 110, .2, { size: 40, weight: 600 });+const thick = (sys, i, t0) => { tw(sys.lines[i].l, { 'a_stroke-width': 10 }, t0, .35); tw(sys.lines[i].l, { 'a_stroke-width': 5 }, t0 + .9, .6); };+const pin = (sys, x, y, t0) => { const g = G(sys.stage, { x: sys.P.PX(x), y: sys.P.PY(y), o: 0 }); mk('circle', { r: 20, fill: 'none', stroke: COL.chalk, 'stroke-width': 3.5, 'stroke-dasharray': '6 5' }, g); show(g, t0, .4); return g; };+const triangle = (el, t0) => el.upper(t0, { color: COL.chalk });+const two = (p, { A, b }, caption, { t0 = .1, E = null } = {}) => {+ const sys = linsys(p, { A, b, eq: [90, 200], mat: null, sol: false, plane: { cx: 1215, u: 50 }, t0 });+ sys.E.style.display = 'none';+ if (caption) say(p, [caption], 70, 175, t0 + .1, { size: 28, fill: COL.dim });+ const em = emat(p, sys, { A, b, E, name: 'P', names: ['A', 'b', 'PA', 'Pb'], at: AT2, size: 38, cw: 64, ecw: 56, rh: 62, gap: 66, t0 });+ return { sys, em };+};+const three = (p, { A, b }, caption, { t0 = .1, E = null, view = { yaw: -30, pitch: 22 } } = {}) => {+ const sys = lin3(p, { A, b, eq: [90, 190], mat: null, sol: false, space: { cx: 1262, size: 520, ...view }, t0 });+ sys.E.style.display = 'none';+ if (caption) say(p, [caption], 64, 160, t0 + .1, { size: 26, fill: COL.dim });+ const em = emat(p, sys, { A, b, E, name: 'P', names: ['A', 'b', 'PA', 'Pb'], at: AT3, size: 32, cw: 52, ecw: 44, rh: 54, gap: 64, t0 });+ return { sys, em, V: sys.space };+};+// 3D with an elimination table (chapter 20's layout)+const table3 = (p, { A, b }, caption, { t0 = .1, view = { yaw: -30, pitch: 22 } } = {}) => {+ const sys = lin3(p, { A, b, eq: [90, 190], mat: null, sol: false, space: { cx: 1262, size: 520, ...view }, t0 });+ sys.E.style.display = 'none';+ if (caption) say(p, [caption], 64, 160, t0 + .1, { size: 26, fill: COL.dim });+ const el = elim(p, sys, { at: [130, 300], size: 38, cw: 76, rh: 60, t0 });+ return { sys, el, V: sys.space };+};+const bare = (A, b = A.map(() => 0)) => {+ const v = {}, fs = [];+ A.forEach((r, i) => { r.forEach((x, j) => { v[`a${i}${j}`] = x; }); v[`b${i}`] = b[i]; });+ return { v, set(to) { Object.assign(v, to); fs.forEach(f => f(v)); }, onChange: f => fs.push(f), solve: () => ({}), live() {}, to() {} };+};+// A small matrix in brackets with its name to the left; t0 null: at once. .cx(j), .ry(i), .ring(i, j, at, opts), .glow(at)+const mat = (p, rows, x, y, t0, { size = 30, cw = 46, rh = 42, name = '', fill = () => COL.chalk, under = '' } = {}) => {+ const g = G(p, { o: t0 === null ? 1 : 0 }), n = rows.length, w = rows[0].length * cw, top = y - size * .95, bot = y + (n - 1) * rh + size * .4;+ const hl = mk('rect', { x: x - 8, y: top - 6, width: w + 16, height: bot - top + 12, rx: 12, fill: COL.chalk, 'fill-opacity': .13 }, g);+ put(hl, { o: 0 });+ path(g, `M${x + 12} ${top}H${x}V${bot}H${x + 12}M${x + w - 12} ${top}H${x + w}V${bot}H${x + w - 12}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });+ rows.forEach((r, i) => r.forEach((v, j) => v !== '' && M(g, [num(v)], { x: x + cw * (j + .5), y: y + i * rh, size, fill: fill(i, j), anchor: 'middle' })));+ if (name) M(g, [].concat(name), { x: x - 14, y: y + (n - 1) * rh / 2 + size * .3, size: size * 1.05, fill: COL.chalk, anchor: 'end' });+ if (under) M(g, [under], { x: x + w / 2, y: bot + size * .95, size: 24, fill: COL.dim, anchor: 'middle' });+ if (t0 !== null) show(g, t0, .5);+ const cx = j => x + cw * (j + .5), ry = i => y + i * rh;+ const ring = (i, j, at, { color = COL.chalk, dash = false } = {}) => {+ const rg = G(p, { x: cx(j), y: ry(i) - size * .32, o: 0 });+ mk('ellipse', { rx: cw * .46, ry: size * .66, fill: 'none', stroke: color, 'stroke-width': 3.5, ...(dash ? { 'stroke-dasharray': '7 6' } : {}) }, rg);+ show(rg, at, .35);+ return rg;+ };+ const glow = (at, len = 1.4) => { tw(hl, { o: 1 }, at, .25); tw(hl, { o: 0 }, at + len, .6); };+ return { g, cx, ry, w, x, ring, glow };+};+const keysOf = ({ A, b }, E = null) => {+ const o = {}, n = A.length;+ A.forEach((r, i) => { r.forEach((x, j) => { o[`a${i}${j}`] = x; o[`e${i}${j}`] = E ? E[i][j] : +(i === j); }); o[`b${i}`] = b[i]; });+ return o;+};+const isPerm = (v, n) => { const I = [...Array(n).keys()], ok = x => x === 0 || x === 1; return I.every(i => I.every(j => ok(v[`e${i}${j}`]))) && I.every(i => I.reduce((s, j) => s + v[`e${i}${j}`], 0) === 1) && I.every(j => I.reduce((s, i) => s + v[`e${i}${j}`], 0) === 1); };+// elimination on PA meets no zero pivot: the corners 1 × 1 and 2 × 2 of PA are not 0 (A itself can be undone)+const noSwap = pr => Math.abs(pr.a00) > 1e-9 && Math.abs(pr.a00 * pr.a11 - pr.a01 * pr.a10) > 1e-9;+const permHint = (v, pr) => !isPerm(v, 3) ? 'P must be the identity with its rows in a new order: one 1 in every row and every column.'+ : Math.abs(pr.a00) < 1e-9 ? 'PA still starts with 0: the first pivot spot needs a row whose first number is not 0.'+ : 'After column 1 of PA, the second pivot spot is 0: try another row in second place.';++/* ---------- practice data (every factorization multiplied back: P A and L U agree) ---------- */+const SWAPQ = [+ { parts: ['A = (0, 3), (2, 1): exchange rows ', { box: '1' }, ' and ', { box: '2' }], why: 'The first pivot spot is 0 and row 2 has a 2 there.', hint: 'Look down column 1 for a number that is not 0.' },+ { parts: ['A = (1, 1, 1), (2, 2, 5), (4, 6, 8): exchange rows ', { box: '2' }, ' and ', { box: '3' }], why: 'Column 1 leaves (0, 0, 3) and (0, 2, 4): the second pivot spot is 0, the row below has 2.', hint: 'Do column 1 first: row 2 − 2 × row 1, row 3 − 4 × row 1.' },+ { parts: ['A = (0, 0, 1), (0, 2, 3), (4, 5, 6): exchange rows ', { box: '1' }, ' and ', { box: '3' }], why: 'Only row 3 has a first number; after the exchange the table is already a triangle.', hint: 'Which row can give the first pivot?' },+ { parts: ['A = (2, 1, 1), (4, 2, 3), (2, 5, 0): exchange rows ', { box: '2' }, ' and ', { box: '3' }], why: 'Column 1 leaves (0, 0, 1) and (0, 4, −1): a 0 in the second pivot spot.', hint: 'Row 2 − 2 × row 1, row 3 − row 1.' },+];+const LUQ = [+ { parts: ['A = (0, 2), (3, 4), P = P₁₂: U = (3, 4), (0, ', { box: '2' }, '), ℓ₂₁ = ', { box: '0' }], why: 'PA = (3, 4), (0, 2) is already a triangle: L = I.', hint: 'Exchange first, then eliminate.' },+ { parts: ['A = (0, 1, 1), (1, 2, 1), (2, 7, 9), P = P₁₂: row 3 of L = (', { box: '2' }, ', ', { box: '3' }, ', 1), row 3 of U = (0, 0, ', { box: '4' }, ')'], why: 'PA: row 3 − 2 × row 1 = (0, 3, 7), then − 3 × row 2 = (0, 0, 4).', hint: 'The example of the chapter.' },+ { parts: ['A = (1, 2, 1), (2, 4, 3), (3, 7, 5), P = P₂₃: column 1 of L below the 1: ', { box: '3' }, ', ', { box: '2' }], why: 'PA = (1, 2, 1), (3, 7, 5), (2, 4, 3): ℓ₂₁ = 3, ℓ₃₁ = 2.', hint: 'Multipliers of PA, not of A.' },+ { parts: ['A = (1, 1, 1), (2, 2, 5), (4, 6, 8), P = P₂₃: ℓ₂₁ = ', { box: '4' }, ', ℓ₃₁ = ', { box: '2' }, ', ℓ₃₂ = ', { box: '0' }, ', U’s last pivot ', { box: '3' }], why: 'PA = (1, 1, 1), (4, 6, 8), (2, 2, 5): rows become (0, 2, 4) and (0, 0, 3).', hint: 'Swap rows 2 and 3 of A, then eliminate.' },+];+const CHECKQ = [+ { parts: ['P₁₂ A for A = (0, 2), (3, 4): row 1 = (', { box: '3' }, ', ', { box: '4' }, ')'], why: 'P₁₂ puts row 2 of A first.', hint: 'Row 1 of P₁₂ is (0, 1).' },+ { parts: ['L = (1,0,0), (3,1,0), (2,0,1), U = (1,2,1), (0,1,2), (0,0,1): row 2 of LU = (', { box: '3' }, ', ', { box: '7' }, ', ', { box: '5' }, ')'], why: '3 × (1, 2, 1) + (0, 1, 2) = (3, 7, 5).', hint: 'Row 2 of L: 3 of row 1 of U, plus row 2.' },+ { parts: ['P = P₂₃: row 2 of P⁻¹ = (', { box: '0' }, ', ', { box: '0' }, ', ', { box: '1' }, ')'], why: 'One exchange undoes itself: P⁻¹ = P.', hint: 'Exchange rows 2 and 3 again.' },+ { parts: ['P = (0,1,0), (0,0,1), (1,0,0): row 1 of Pᵀ = (', { box: '0' }, ', ', { box: '0' }, ', ', { box: '1' }, ')'], why: 'Row 1 of Pᵀ is column 1 of P: (0, 0, 1).', hint: 'Read P’s first column, top to bottom.' },+ { parts: ['3 × 3 permutation matrices: ', { box: '6' }], why: '3 · 2 · 1 = 6 (chapter 22).', hint: '3 choices for row 1, then 2, then 1.' },+];+const HANDS = [+ { sys: EX2, prompt: 'Build P so that elimination on PA needs no exchange.', ans: [[0, 1, 0], [1, 0, 0], [0, 0, 1]], why: 'P₁₂ works (so do P₁₃ and both cycles): PA starts with a number that is not 0, and the second pivot is not 0.' },+ { sys: { A: [[0, 0, 1], [0, 2, 3], [4, 5, 6]], b: [1, 5, 15] }, prompt: 'Build P so that elimination on PA needs no exchange.', ans: [[0, 0, 1], [0, 1, 0], [1, 0, 0]], why: 'Only P₁₃: row 3 must come first, and then row 2 is the only one with a y.' },+ { sys: { A: [[1, 1, 1], [2, 2, 5], [4, 6, 8]], b: [3, 9, 18] }, prompt: 'Build P so that elimination on PA needs no exchange.', ans: [[1, 0, 0], [0, 0, 1], [0, 1, 0]], why: 'P₂₃ works (as do three others): rows 1 and 2 of A alone give a 0 second pivot.' },+];+const eKeys = P => Object.fromEntries(P.flatMap((r, i) => r.map((x, j) => [`e${i}${j}`, x])));++/* ---------- beats ---------- */+const BEATS = [+ ['intro', 'PA = LU', (m, D) => {+ const g = G(scene, { o: 0, y: 24 });+ T(g, 'Unit 4, Chapter 34', { x: 800, y: 250, size: 28, fill: COL.dim, anchor: 'middle' });+ T(g, 'PA = LU', { x: 800, y: 360, size: 88, weight: 600, anchor: 'middle' });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);+ const r = text(scene, 'put the rows in a good order first, then eliminate', 800, 460, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });+ const lg = G(scene, { o: 0 }); show(lg, m('sub') + 1, .5);+ const em = emat(lg, bare(ZERO2.A, ZERO2.b), { A: ZERO2.A, b: ZERO2.b, at: [420, 640], size: 36, cw: 62, ecw: 54, rh: 56, t0: 0, name: 'P', names: ['A', 'b', 'PA', 'Pb'] });+ const z = em.B.ring(0, 0, m('sub') + 2, { color: COL.bad });+ hide(z, m('move'), .3);+ emSwap(em, 0, 1, m('move') + .2, 1.4);+ em.Pt.ring(0, 0, m('move') + 1.8, { color: COL.good });+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);+ }],++ ['recall', 'A zero pivot', (m) => {+ const p = panel(0);+ title(p, 'A zero in the pivot spot');+ const { sys, em } = two(p, ZERO2, 'chapter 20: 2y = 4, 3x + y = 5', { t0: .4 });+ pin(sys, 1, 2, m('sys') + 3);+ put(em.Eg, { o: 0 }); show(em.Eg, m('p'), .5);+ put(em.eqSign, { o: 0 }); show(em.eqSign, m('p'), .4);+ tw(em.Pt.g, { o: 0 }, 0, 0); show(em.Pt.g, m('p'), .5);+ em.setName('I');+ const z = em.B.ring(0, 0, m('zero'), { color: COL.bad });+ hide(em.B.ring(1, 0, m('zero') + 3, { dash: true }), m('swap'), .3);+ hide(z, m('swap'), .3);+ em.flashE(0, m('p') + 2.4); em.flashE(1, m('p') + 3.6);+ emSwap(em, 0, 1, m('swap') + .3, 1.6, { sys });+ prog(q => em.setName(q > 0 ? 'P' : 'I'), m('swap') + 2, 0, lin);+ thick(sys, 0, m('same')); thick(sys, 1, m('same') + 1);+ pulse(sys.meet, m('same') + 2.4);+ triangle(em.Pt, m('u'));+ em.Pt.ring(0, 0, m('u') + .6, { color: COL.good });+ em.Pt.flash(0, m('u') + 2.5); em.Pt.flash(1, m('u') + 3.5);+ say(p, ['U = PA, L = I: PA = LU'], 70, 640, m('lu') + .3, { size: 36 });+ }],++ ['why', 'Why not A = LU?', (m) => {+ const p = panel(0);+ title(p, 'Why not A = LU?');+ const e = emat(p, bare(U3.A), { A: U3.A, b: [0, 0, 0], E: L3, at: [64, 300], size: 34, cw: 56, ecw: 48, rh: 56, gap: 60, t0: .3, noB: true, name: 'L', names: ['U', '', 'LU', ''] });+ e.focusE(0, m('row1')); e.work(0, 0, { times: [m('row1') + 1.5, m('row1') + 2.5, m('row1') + 3, m('row1') + 4] });+ e.Pt.flash(0, m('row1') + 4.4);+ e.work(null, m('piv'));+ e.focusE(null, m('piv'));+ e.B.ring(0, 0, m('piv') + .2); e.Pt.ring(0, 0, m('piv') + .6);+ text(p, 'top-left of LU = the first pivot of U', 64, 620, m('piv') + 1, { size: 28, weight: 600 });+ const A = mat(p, ZERO2.A, 1120, 330, m('zero') - .2, { size: 40, cw: 64, rh: 58, name: 'A =' });+ A.ring(0, 0, m('zero') + .6, { color: COL.bad });+ text(p, 'a pivot is never 0', 1060, 500, m('zero') + 1.2, { size: 30, fill: COL.bad, weight: 600 });+ text(p, 'no L and U make this A', 1060, 560, m('so'), { size: 30, weight: 600 });+ say(p, ['so: factor PA'], 1060, 640, m('so') + 3, { size: 36 });+ }],++ ['ex3', 'Three by three', (m) => {+ const p = panel(0);+ title(p, 'Three equations, one exchange');+ const { sys, el, V } = table3(p, Z3, 'chapter 20: x + 2y + z = 1, 2x + 4y + 3z = 3, 3x + 7y + 5z = 4', { t0: .4 });+ V.sway(5, 13);+ [0, 1, 2].forEach(i => el.flash(i, m('A') + .3 + 2.3 * i));+ el.step(1, 0, 2, m('c1') + .3, 1.8);+ el.step(2, 0, 3, m('c1') + 3.2, 1.8);+ const lab = el.op_.lab.g;+ hide(lab, m('zero') - .2, .3);+ const z = el.ring(1, 1, m('zero'), { color: COL.bad }), w = el.ring(2, 1, m('below'), { color: COL.good, dash: true });+ hide(z, m('swap'), .3); hide(w, m('swap'), .3);+ sys.planes[1].fade(.3, m('swap'), .4); sys.planes[2].fade(.3, m('swap'), .4);+ el.swap(1, 2, m('swap') + .3, 1.6);+ sys.planes[1].fade(1, m('swap') + 2.1, .5); sys.planes[2].fade(1, m('swap') + 2.1, .5);+ triangle(el, m('swap') + 2.4);+ const Pm = mat(p, P23, 190, 600, m('p'), { size: 30, cw: 46, rh: 42, name: 'P₂₃ =' });+ text(p, 'rows 1, 3, 2', 140, 770, m('p') + .8, { size: 26, fill: COL.dim, weight: 600 });+ mat(p, PZ3.A, 560, 600, m('pa'), { size: 30, cw: 46, rh: 42, name: 'PA =' });+ Pm.glow(m('p') + .4, 2);+ }],++ ['elim', 'Eliminate PA', (m) => {+ const p = panel(0);+ title(p, 'Eliminate PA: no exchange needed');+ const { sys, el, V } = table3(p, PZ3, 'PA: x + 2y + z = 1, 3x + 7y + 5z = 4, 2x + 4y + 3z = 3', { t0: .4 });+ V.sway(5, 13);+ el.step(1, 0, 3, m('l21') + .2, 1.8);+ el.step(2, 0, 2, m('l31') + .2, 1.8);+ el.op(2, 1, 0, m('l32') + .3);+ triangle(el, m('u'));+ [0, 1, 2].forEach(i => el.ring(i, i, m('u') + 1 + .4 * i));+ const Lm = mat(p, L3, 190, 600, m('L'), { size: 30, cw: 46, rh: 42, name: 'L =' });+ const r1 = Lm.ring(1, 0, m('L') + 1, { dash: true }), r2 = Lm.ring(2, 0, m('L') + 1.4, { dash: true });+ Lm.ring(2, 1, m('L') + 3.2, { dash: true });+ const bf = G(p, { o: 0 }); show(bf, m('look') + 2, .4);+ T(bf, 'A’s multipliers:', { x: 470, y: 590, size: 26, fill: COL.dim, weight: 600 });+ M(bf, ['ℓ₂₁ = 2, ℓ₃₁ = 3'], { x: 470, y: 636, size: 30, fill: COL.dim, anchor: 'start' });+ const af = G(p, { o: 0 }); show(af, m('moved'), .4);+ T(af, 'PA’s multipliers:', { x: 470, y: 690, size: 26, fill: COL.chalk, weight: 600 });+ M(af, ['ℓ₂₁ = 3, ℓ₃₁ = 2'], { x: 470, y: 736, size: 30, fill: COL.chalk, anchor: 'start' });+ pulse(r1, m('moved') + .8); pulse(r2, m('moved') + .8);+ }],++ ['both', 'Both sides', (m, D) => {+ const p = panel(0);+ title(p, 'PA = LU: multiply out both sides');+ const sys = lin3(p, { A: U3.A, b: U3.b, eq: [90, 190], mat: null, sol: false, space: { cx: 1280, size: 480, yaw: -30, pitch: 22 }, t0: .4 });+ sys.E.style.display = 'none';+ sys.space.sway(5, 13);+ const top = G(p, { o: 0 }); show(top, m('left'), .5);+ const e1 = emat(top, bare(PZ3.A, PZ3.b), { A: Z3.A, b: Z3.b, E: P23, at: [64, 220], size: 28, cw: 46, ecw: 40, rh: 46, gap: 56, t0: 0, name: 'P', names: ['A', 'b', 'PA', 'Pb'] });+ [0, 1, 2].forEach(i => e1.Pt.flash(i, m('pa') + 1.4 * i));+ const bot = G(p, { o: 0 }); show(bot, m('right'), .5);+ const e2 = emat(bot, sys, { A: U3.A, b: U3.b, at: [64, 450], size: 28, cw: 46, ecw: 40, rh: 46, gap: 56, t0: 0, name: 'L', names: ['U', 'c', 'LU', 'Lc'] });+ e2.focusE(0, m('r1')); e2.work(0, m('r1') + .3);+ e2.focusE(1, m('r2')); e2.work(1, m('r2') + .2); e2.ringE(1, 0, m('r2') + .4);+ e2.to({ e10: 3 }, m('r2') + 1, 2.4);+ e2.focusE(2, m('r3')); e2.work(2, m('r3') + .2); e2.ringE(2, 0, m('r3') + .4);+ e2.to({ e20: 2 }, m('r3') + 1, 2.4);+ e2.work(null, m('eq')); e2.focusE(null, m('eq'));+ [0, 1, 2].forEach(i => { e1.Pt.flash(i, m('eq') + .4 + .9 * i); e2.Pt.flash(i, m('eq') + .4 + .9 * i); });+ say(p, ['PA = LU ✓'], 64, 700, m('eq') + 2, { size: 40, fill: COL.good });+ }],++ ['q1', 'Quick check', () => {+ const p = panel(0);+ title(p, 'Quick check');+ const t = two(p, { A: [[0, 1], [2, 3]], b: [1, 5] }, 'y = 1, 2x + 3y = 5');+ S.em = t.em;+ }, { ask: done => quiz({ x: 40, y: 430, w: 760, cls: 'side' }, [{+ id: 'c-pa2', prompt: ['A = (0, 1), (2, 3). Choose P, then factor PA = LU.'],+ build: blanks([+ { parts: ['P exchanges rows ', { box: '1' }, ' and ', { box: '2' }], why: 'The first pivot spot is 0; row 2 has a 2 there.', hint: 'Which row has a number in column 1?',+ fx: () => fxp(q => { if (q >= 1) S.em.set({ e00: 0, e01: 1, e10: 1, e11: 0 }); }, 0, .2) },+ { parts: ['U = PA = (', { box: '2' }, ', ', { box: '3' }, '), (0, ', { box: '1' }, '), L = I'], why: 'PA = (2, 3), (0, 1) is already a triangle: L = I.', hint: 'Write the rows of A in the new order.' },+ ]),+ }], done) }],++ ['ex2', 'A zero at the start', (m) => {+ const p = panel(0);+ title(p, 'A zero right at the start');+ const { sys, el, V } = table3(p, EX2, 'y + z = 2, x + 2y + z = 4, 2x + 7y + 9z = 18', { t0: .4 });+ V.sway(5, 13);+ const z = el.ring(0, 0, m('zero'), { color: COL.bad });+ hide(z, m('swap') + .2, .3);+ sys.planes[0].fade(.3, m('swap') + .2, .4); sys.planes[1].fade(.3, m('swap') + .2, .4);+ el.swap(0, 1, m('swap') + .5, 1.6);+ sys.planes[0].fade(1, m('swap') + 2.3, .5); sys.planes[1].fade(1, m('swap') + 2.3, .5);+ el.ring(0, 0, m('swap') + 2.4, { color: COL.good });+ el.op(1, 0, 0, m('l21') + 2);+ el.step(2, 0, 2, m('l31') + .2, 1.8);+ el.step(2, 1, 3, m('l32') + .2, 1.8);+ triangle(el, m('LU') - .4);+ const Lm = mat(p, [[1, 0, 0], [0, 1, 0], [2, 3, 1]], 160, 600, m('LU'), { size: 30, cw: 46, rh: 42, name: 'L =' });+ const Um = mat(p, [[1, 2, 1], [0, 1, 1], [0, 0, 4]], 440, 600, m('LU') + 2.4, { size: 30, cw: 46, rh: 42, name: 'U =' });+ Lm.ring(2, 0, m('check') + .6); Lm.ring(2, 1, m('check') + .6);+ Um.glow(m('check') + 1.6, 3);+ say(p, ['2·(1, 2, 1) + 3·(0, 1, 1) + (0, 0, 4) = (2, 7, 9)'], 64, 790, m('check') + 4, { size: 30 });+ }],++ ['q2', 'Your turn', () => {+ const p = panel(0);+ title(p, 'Your turn');+ const t = three(p, Z3, 'chapter 20: x + 2y + z = 1, 2x + 4y + 3z = 3, 3x + 7y + 5z = 4');+ S.em = t.em;+ }, { ask: done => quiz(CARD3, [{+ id: 'c-perm', prompt: ['Change the numbers of P until elimination on PA meets no zero pivot.'],+ build: emTask(S.em, (v, pr) => isPerm(v, 3) && noSwap(pr), 'Rows 1, 3, 2 (P₂₃) work, and so do three other orders. Only rows 1 and 2 on top fail: their 2 × 2 corner gives a 0 pivot.',+ permHint, () => S.em.set(eKeys(P23)), { only: ['e00', 'e01', 'e02', 'e10', 'e11', 'e12', 'e20', 'e21', 'e22'] }),+ }], done) }],++ ['q3', 'Quick check', () => {+ const p = panel(0);+ title(p, 'Quick check');+ const t = two(p, { A: [[0, 2], [0, 5]], b: [4, 10] }, '2y = 4, 5y = 10');+ S.em = t.em;+ }, { ask: done => quiz({ x: 40, y: 450, w: 780, cls: 'side' }, [{+ id: 'c-none', prompt: ['A = (0, 2), (0, 5). Can a permutation P make elimination work?'],+ build: choice(['Yes: P₁₂', 'No: column 1 has no number that can be a pivot', 'Yes: P = I already works'], 1,+ 'Every row starts with 0, so no order of the rows gives a first pivot: chapter 20’s permanent trouble.',+ ['P₁₂ puts (0, 5) on top: the first pivot spot is still 0.', null, 'With P = I the first pivot spot is 0.']),+ }], done) }],++ ['inv', 'Undoing P', (m) => {+ const p = panel(0);+ title(p, 'Undoing P');+ const ex = G(p, { o: 0 }); show(ex, m('undo') + .3, .4); hide(ex, m('cycle') - .2, .4);+ say(ex, ['P₂₃ P₂₃ = I'], 64, 190, 0, { size: 34 });+ const pp = emat(ex, bare(P23), { A: P23, b: [0, 0, 0], E: P23, at: [64, 290], size: 30, cw: 46, ecw: 40, rh: 46, gap: 56, t0: 0, noB: true, name: 'P₂₃', names: ['P₂₃', '', 'I', ''] });+ [0, 1, 2].forEach(i => { pp.flashE(i, m('undo') + 3.5 + 1.6 * i); pp.Pt.flash(i, m('undo') + 4 + 1.6 * i); });+ const Pm = mat(p, CYC, 160, 330, m('cycle'), { size: 36, cw: 56, rh: 50, name: 'P =' });+ text(p, 'moves every row', 110, 480, m('cycle') + .6, { size: 26, fill: COL.dim, weight: 600 });+ [[0, 2], [1, 0], [2, 1]].forEach(([i, j], k) => hide(Pm.ring(i, j, m('cycle') + 2.4 + 1.4 * k), m('flip') - .3, .3));+ const Pv = mat(p, CYCT, 500, 330, m('back'), { size: 36, cw: 56, rh: 50, name: 'P⁻¹ =' });+ [[0, 1], [1, 2], [2, 0]].forEach(([i, j], k) => hide(Pv.ring(i, j, m('back') + 2 + 1.3 * k), m('flip') - .3, .3));+ text(p, 'puts every row back', 450, 480, m('back') + 5, { size: 26, fill: COL.dim, weight: 600 });+ // the flip: P's diagonal dashed, every number flies from (i, j) to (j, i) of a new matrix+ const dg = path(p, `M${Pm.cx(0) - 20} ${Pm.ry(0) - 30}L${Pm.cx(2) + 20} ${Pm.ry(2) + 12}`, { stroke: COL.chalk, 'stroke-width': 2.5, 'stroke-dasharray': '8 7', fill: 'none' }, { d: 0 });+ tw(dg, { d: 1 }, m('flip'), .8); hide(dg, m('name') + 1, .5);+ const Tm = mat(p, CYCT.map(r => r.map(() => '')), 880, 330, m('flip') + .4, { size: 36, cw: 56, rh: 50, name: 'Pᵀ =' });+ CYC.forEach((r, i) => r.forEach((v, j) => {+ const t = G(p, { x: Pm.cx(j), y: Pm.ry(i), o: 0 });+ M(t, [num(v)], { size: 36, fill: v ? COL.chalk : COL.dim, anchor: 'middle' });+ const at = m('flip') + 1 + .25 * (i * 3 + j);+ show(t, at, .1);+ tw(t, { x: Tm.cx(i), y: Tm.ry(j) }, at, 1.4);+ }));+ say(p, ['P⁻¹ = Pᵀ'], 880, 520, m('name') + 2, { size: 40 });+ const e = emat(p, bare(CYC), { A: CYC, b: [0, 0, 0], E: CYCT, at: [64, 690], size: 28, cw: 46, ecw: 40, rh: 44, gap: 56, t0: m('check') - .2, noB: true, name: 'Pᵀ', names: ['P', '', 'I', ''] });+ [0, 1, 2].forEach(i => e.Pt.flash(i, m('check') + 1 + .7 * i));+ text(p, 'every permutation: P⁻¹ = Pᵀ', 880, 600, m('rule'), { size: 30, weight: 600 });+ text(p, 'the transpose: chapter 35', 880, 660, m('next'), { size: 28, fill: COL.dim, weight: 600 });+ }],++ ['wrap', 'Summary', (m) => {+ const p = panel(0);+ [['A zero pivot is fixed by a row exchange; P can make every exchange first.', 'w1'], ['Then PA = LU: L holds the multipliers, U the pivots.', 'w2'],+ ['Check by multiplying out: P reorders the rows of A, L mixes the rows of U.', 'w3'], ['P⁻¹ = Pᵀ. If no row below has a number, no P can help.', 'w4']].forEach(([str, mark], i) => {+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });+ mk('circle', { cx: 120, cy: -12, r: 26, fill: COL.chalk }, g);+ T(g, String(i + 1), { x: 120, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });+ T(g, str, { x: 170, size: 34, weight: 600 });+ tw(g, { o: 1, x: 0 }, m(mark), .6);+ });+ }],+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{+ id: 'p-swap', prompt: ['Eliminate until a pivot spot holds 0, and name the rows to exchange (smaller number first).'],+ build: blanks(SWAPQ),+ }], done, 'Chapter practice · set 1 of 4') }],+ ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{+ id: 'p-lu', prompt: ['Put the rows in P’s order, then eliminate PA: L holds the multipliers ℓ, U the result.'],+ build: blanks(LUQ),+ }], done, 'Chapter practice · set 2 of 4') }],+ ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{+ id: 'p-check', prompt: ['Multiply, and undo P. Rows are written (first number, second number, …).'],+ build: blanks(CHECKQ),+ }], done, 'Chapter practice · set 3 of 4') }],+ ['final4', 'Chapter practice', () => {+ const p = panel(0);+ title(p, 'Build P');+ const t = three(p, HANDS[0].sys, '');+ S.em = t.em;+ }, { ask: done => quiz(CARD3, HANDS.map((h, k) => ({+ id: `p-hand${k + 1}`, prompt: [h.prompt],+ build: (body, api) => {+ S.em.set(keysOf(h.sys));+ return emTask(S.em, (v, pr) => isPerm(v, 3) && noSwap(pr), h.why, permHint, () => S.em.set(eKeys(h.ans)), { only: ['e00', 'e01', 'e02', 'e10', 'e11', 'e12', 'e20', 'e21', 'e22'] })(body, api);+ },+ })), done, 'Chapter practice · set 4 of 4') }],+ ['play', 'Playground', (m) => {+ const p = panel(0);+ title(p, 'Playground');+ const t = three(p, Z3, '', { E: P23 });+ S.em = t.em;+ const hint = text(p, 'try: P = I; rows 2, 1, 3; a 0 in A’s first column', 64, 160, m('go'), { size: 24, fill: COL.dim });+ hide(hint, m('go') + 7, .6);+ }, { ask: playAsk(() => S.em, { pos: { x: 40, y: 480, w: 820, cls: 'side' }, tip: 'Your matrices. Change any number of P or of A | b, turn the picture, or draw on the board. Nothing is marked.' }) }],+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));++boot();+</script>+</body>+</html>diff --git a/site/linear-algebra/lib/cost.js b/site/linear-algebra/lib/cost.jsnew file mode 100644index 0000000..ac8d3c9--- /dev/null+++ b/site/linear-algebra/lib/cost.js@@ -0,0 +1,292 @@+// How much work is elimination (chapter 33): an n × n matrix counted cell by cell, drawn three ways from one state.+// One operation = one number of a row below the pivot changing: "new = old − ℓ × the number above it" is a multiply and a+// subtract; the first number of the row becomes 0, and its operation is the division that finds ℓ. Stage s (pivot in+// row s, column s, counting from 1) has n − s rows below the pivot and n − s + 1 numbers in each: (k − 1) · k operations+// for the k × k corner still to do, and the total for A is n(n − 1) + … + 2·1 = (n³ − n)/3, about n³/3.+//+// const ce = cost(p, { n: 3, A, grid: { x, y, w, work: [x, y] }, chart: { x, y, w, h, N }, pyr: { x, y, size }, read: { x, y } })+// ce.v → { n, c } c = operations counted so far (0 … coTotal(n)); set({ n }) alone counts everything+// ce.to({ c: 8 }, at, dur) on the beat clock: cells light one by one, the counter, the chart's bar and the pyramid follow+// ce.count(s, at, dur) just stage s (its cells from coStart(n, s) to coStart(n, s + 1))+// ce.to({ n: 10 }, at, dur) n steps through the sizes (each fully counted): the chart's bars grow one by one+// ce.live(on) the reader scrubs n (drag the n number sideways, or Tab to it and ↑/↓); playAsk works+// costTask(ce, test(v), why, hint, reveal) is the question type+//+// grid: the matrix seen flat, cells (A's numbers for its own n when A is given, with the working of the last operation+// at work); the current stage's corner outlined, its counted cells lit, its pivot boxed, the zeros left empty.+// chart: bars of (m³ − m)/3 for m = 2 … n (the bar for n grows while counting) under the dashed curve m³/3; N is the+// least width of the n axis (it widens past N as n grows, and the scale with it).+// pyr: the stages stacked as layers on the matrix (stage s = layer s, its top face = its cells): a stepped pyramid in the+// dashed n × n × n box; ce.parts.cone is the smooth pyramid (a third of the box) to show on a word.+// read: "n = 4", "operations: 20", "n³/3 ≈ 21.3" (parts.read.n / .ops / .third / .ratio, each a group to show).+// Loads after engine.js.+const coTotal = n => (n * n * n - n) / 3;+const coStage = (n, s) => (n - s) * (n - s + 1);+const coStart = (n, s) => { let t = 0; for (let k = 1; k < s; k++) t += coStage(n, k); return t; };+const coFmt = v => (v < 0 ? '−' : '') + Math.round(Math.abs(v)).toLocaleString('en-US');+const coThird = n => { const v = n * n * n / 3; return Math.abs(v - Math.round(v)) < 1e-9 ? coFmt(v) : (v >= 1000 ? coFmt(v) : (Math.round(v * 10) / 10).toFixed(1)); };+// the cell counted as operation k (from 0): stage s, row r, column j (rows and columns from 0)+const coCell = (n, k) => { let s = 1; while (s < n - 1 && k >= coStage(n, s)) { k -= coStage(n, s); s++; } const w = n - s + 1; return { s, r: s + Math.floor(k / w), j: s - 1 + k % w }; };+const coParts = v => {+ const r = Math.round(v);+ if (Math.abs(v - r) < 1e-9) return [num(r)];+ for (let d = 2; d <= 60; d++) { const k = Math.round(v * d); if (Math.abs(v * d - k) < 1e-9) return k < 0 ? ['−', F(-k, d)] : [F(k, d)]; }+ return [num(Math.round(v * 100) / 100)];+};+const CO = { top: '#3d4f48', front: '#2a3833', left: '#33443e', lit: '#a9a596', cur: '#ece8dc' };++function cost(p, { n = 3, A = null, grid = null, chart = null, pyr = null, read = null, t0 = .1, max = 60, o = 0 } = {}) {+ const svg = $('stage'), s = { n, c: coTotal(n) };+ let plan = { ...s };+ const g = G(p, { o });+ show(g, t0 + .2);+ const parts = {};+ const listeners = [];+ const keyOf = () => `${s.n}|${Math.floor(s.c + 1e-9)}`;+ let drawn = '';++ /* ---------- the flat matrix ---------- */+ let GR = null;+ if (grid) {+ const gg = G(g, {});+ const pl = path(gg, '', { fill: COL.chalk, 'fill-opacity': .1, stroke: 'none' });+ const blk = path(gg, '', { fill: COL.chalk, 'fill-opacity': .1, stroke: 'none' });+ const lit = path(gg, '', { fill: COL.chalk, 'fill-opacity': .5, stroke: 'none' });+ const lines = path(gg, '', { fill: 'none', stroke: COL.faint, 'stroke-width': 1.5 });+ const frame = path(gg, '', { fill: 'none', stroke: COL.chalk, 'stroke-width': 2.5, 'stroke-dasharray': '8 6' });+ const piv = path(gg, '', { fill: 'none', stroke: COL.chalk, 'stroke-width': 4 });+ const nums = G(gg, {}), work = G(g, {});+ GR = { gg, pl, blk, lit, lines, frame, piv, nums, work };+ parts.grid = gg; parts.work = work;+ }+ const cellR = (x, y, w) => `M${x.toFixed(1)} ${y.toFixed(1)}h${w.toFixed(1)}v${w.toFixed(1)}h${(-w).toFixed(1)}z`;+ function simulate(N, upto) { // A's numbers after `upto` operations, and the working of the last one+ const a = A.map(r => r.slice()), ls = {};+ let last = null;+ for (let k = 0; k < upto; k++) {+ const { s: st, r, j } = coCell(N, k), pr = st - 1;+ if (j === pr) { const l = a[r][j] / a[pr][pr]; last = { kind: 'l', num: a[r][j], piv: a[pr][pr], l, r, j }; ls[r] = l; a[r][j] = 0; }+ else { const old = a[r][j], nw = old - ls[r] * a[pr][j]; last = { kind: 'ms', old, l: ls[r], top: a[pr][j], nw, r, j }; a[r][j] = nw; }+ }+ return { a, last };+ }+ function drawGrid(N, c) {+ const { x, y, w } = grid, cs = w / N, TT = coTotal(N), cur = c < TT ? coCell(N, c).s : null;+ const idx = (st, i, j) => coStart(N, st) + (i - st) * (N - st + 1) + (j - st + 1);+ let pl = '', blk = '', lit = '';+ for (let i = 0; i < N; i++) for (let j = 0; j < N; j++) {+ const r = cellR(x + j * cs, y + i * cs, cs);+ if (i > j && idx(j + 1, i, j) < c) continue; // a zero: left empty+ if (cur && i >= cur && j >= cur - 1) { if (idx(cur, i, j) < c) lit += r; else blk += r; }+ else pl += r;+ }+ GR.pl.setAttribute('d', pl); GR.blk.setAttribute('d', blk); GR.lit.setAttribute('d', lit);+ let ln = '';+ if (N <= 40) for (let k = 0; k <= N; k++) ln += `M${x} ${(y + k * cs).toFixed(1)}h${w}M${(x + k * cs).toFixed(1)} ${y}v${w}`;+ else ln = `M${x} ${y}h${w}v${w}h${-w}z`;+ GR.lines.setAttribute('d', ln);+ GR.frame.setAttribute('d', cur ? `M${x + (cur - 1) * cs} ${y + cur * cs}h${(N - cur + 1) * cs}v${(N - cur) * cs}h${-(N - cur + 1) * cs}z` : '');+ GR.piv.setAttribute('d', cur ? cellR(x + (cur - 1) * cs, y + (cur - 1) * cs, cs) : '');+ GR.nums.replaceChildren(); GR.work.replaceChildren();+ if (!A || A.length !== N) return;+ const { a, last } = simulate(N, c), fs = Math.min(40, cs * .4);+ a.forEach((row, i) => row.forEach((v, j) => {+ const zero = i > j && idx(j + 1, i, j) < c;+ M(GR.nums, coParts(v), { x: x + (j + .5) * cs, y: y + (i + .5) * cs + fs * .36, size: fs, fill: zero ? COL.faint : COL.chalk, anchor: 'middle' });+ }));+ if (!grid.work || !last) return;+ const [wx, wy] = grid.work, pf = v => v < 0 ? ['(', ...coParts(v), ')'] : coParts(v);+ const ps = last.kind === 'l' ? ['ℓ = ', ...coParts(last.num), ' ÷ ', ...pf(last.piv), ' = ', ...coParts(last.l), ', so it becomes 0']+ : [...coParts(last.old), ' − ', ...pf(last.l), ' × ', ...pf(last.top), ' = ', ...coParts(last.nw)];+ M(GR.work, ps, { x: wx, y: wy, size: 34, fill: COL.chalk, anchor: 'start' });+ T(GR.work, `row ${last.r + 1}, column ${last.j + 1}`, { x: wx, y: wy + 38, size: 22, fill: COL.dim, weight: 600 });+ }++ /* ---------- the chart ---------- */+ let CH = null;+ if (chart) {+ const cg = G(g, {});+ const axes = path(cg, '', { fill: 'none', stroke: COL.dim, 'stroke-width': 2.5 });+ const ticks = G(cg, {});+ const old = path(cg, '', { fill: COL.chalk, 'fill-opacity': .32, stroke: 'none' });+ const bar = path(cg, '', { fill: COL.chalk, 'fill-opacity': .85, stroke: 'none' });+ const curve = path(cg, '', { fill: 'none', stroke: COL.chalk, 'stroke-width': 3, 'stroke-dasharray': '9 7' });+ const lab = G(cg, {});+ CH = { cg, axes, ticks, old, bar, curve, lab, key: '' };+ parts.chart = cg; parts.curve = curve;+ }+ const nice = v => { const e = 10 ** Math.floor(Math.log10(v)); for (const m of [1, 2, 2.5, 5, 10]) if (m * e >= v) return m * e; return 10 * e; };+ function drawChart(N, c) {+ const { x, y, w, h, N: N0 = 10 } = chart, xm = Math.max(N0, N), top = (xm + .3) ** 3 / 3, stp = nice(top / 4), ym = Math.ceil(top / stp) * stp;+ const X = m => x + w * m / (xm + .6), Y = v => y - h * v / ym, bw = Math.max(1.5, w / (xm + .6) * .62);+ const sk = `${xm}|${ym}`;+ if (sk !== CH.key) {+ CH.key = sk;+ CH.axes.setAttribute('d', `M${x} ${y - h - 10}V${y}H${x + w + 10}`);+ CH.ticks.replaceChildren();+ const every = xm <= 12 ? 1 : xm <= 30 ? 5 : xm <= 60 ? 10 : 20;+ for (let m = 1; m <= xm; m++) if (m % every === 0 || (every === 1 && m >= 1)) T(CH.ticks, String(m), { x: X(m), y: y + 30, size: 22, fill: COL.dim, anchor: 'middle' });+ for (let k = 1; k * stp <= ym + 1e-9; k++) {+ const v = k * stp;+ path(CH.ticks, `M${x - 8} ${Y(v)}H${x + w}`, { stroke: COL.faint, 'stroke-width': 1, 'stroke-opacity': .5 });+ T(CH.ticks, coFmt(v), { x: x - 14, y: Y(v) + 8, size: 22, fill: COL.dim, anchor: 'end' });+ }+ M(CH.ticks, ['n'], { x: x + w + 24, y: y + 8, size: 30, fill: COL.dim, anchor: 'start' });+ T(CH.ticks, 'operations', { x, y: y - h - 24, size: 24, fill: COL.dim, weight: 600, anchor: 'start' });+ let d = '';+ for (let q = 0; q <= 120; q++) { const m = (xm + .3) * q / 120; d += `${q ? 'L' : 'M'}${X(m).toFixed(1)} ${Y(m ** 3 / 3).toFixed(1)}`; }+ CH.curve.setAttribute('d', d);+ }+ let od = '';+ for (let m = 2; m < N; m++) od += `M${(X(m) - bw / 2).toFixed(1)} ${y}V${Y(coTotal(m)).toFixed(1)}h${bw.toFixed(1)}V${y}z`;+ CH.old.setAttribute('d', od);+ const cv = Math.min(c, coTotal(N));+ CH.bar.setAttribute('d', N >= 2 ? `M${(X(N) - bw / 2).toFixed(1)} ${y}V${Y(cv).toFixed(1)}h${bw.toFixed(1)}V${y}z` : '');+ CH.lab.replaceChildren();+ T(CH.lab, coFmt(cv), { x: X(N), y: Y(cv) - 14, size: 26, fill: COL.task, weight: 700, anchor: N > xm * .75 ? 'end' : 'middle' });+ M(CH.lab, ['n³/3'], { x: X(xm + .3) + 6, y: Y((xm + .3) ** 3 / 3) + 30, size: 26, fill: COL.chalk, anchor: 'start' });+ }++ /* ---------- the pyramid ---------- */+ let PY = null;+ const K = .5, ca = Math.cos(Math.PI * 35 / 180), sa = Math.sin(Math.PI * 35 / 180);+ if (pyr) {+ const pg = G(g, {});+ const floor = path(pg, '', { fill: COL.chalk, 'fill-opacity': .06, stroke: COL.faint, 'stroke-width': 1.2 });+ const layers = G(pg, {});+ const box = path(pg, '', { fill: 'none', stroke: COL.dim, 'stroke-width': 2, 'stroke-dasharray': '6 7' });+ const cone = path(pg, '', { fill: COL.chalk, 'fill-opacity': 0, stroke: COL.chalk, 'stroke-width': 3, 'stroke-dasharray': '12 8' });+ put(cone, { o: 0 });+ PY = { pg, floor, layers, box, cone };+ parts.pyr = pg; parts.cone = cone; parts.box = box;+ }+ function drawPyr(N, c) {+ const { x, y, size } = pyr, u = size / N;+ const P_ = (cc, d, hh) => `${(x + cc * u - d * u * K * ca).toFixed(1)} ${(y - d * u * K * sa - hh * u).toFixed(1)}`;+ const poly = pts => `M${pts.map(q => P_(...q)).join('L')}z`;+ let fl = poly([[0, 0, 0], [N, 0, 0], [N, N, 0], [0, N, 0]]);+ if (N <= 40) for (let k = 1; k < N; k++) fl += `M${P_(k, 0, 0)}L${P_(k, N, 0)}M${P_(0, k, 0)}L${P_(N, k, 0)}`;+ PY.floor.setAttribute('d', fl);+ const B = (a, b) => `M${P_(...a)}L${P_(...b)}`;+ PY.box.setAttribute('d', [B([0, 0, N], [N, 0, N]), B([N, 0, N], [N, N, N]), B([N, N, N], [0, N, N]), B([0, N, N], [0, 0, N]),+ B([0, 0, 0], [0, 0, N]), B([N, 0, 0], [N, 0, N]), B([0, N, 0], [0, N, N]), B([N, N, 0], [N, N, N])].join(''));+ PY.cone.setAttribute('d', `M${P_(0, 0, 0)}L${P_(N, 0, N)}M${P_(0, N, 0)}L${P_(N, 0, N)}M${P_(N, N, 0)}L${P_(N, 0, N)}M${P_(N, 0, 0)}L${P_(N, 0, N)}` + poly([[0, 0, 0], [N, 0, 0], [N, N, 0], [0, N, 0]]));+ PY.layers.replaceChildren();+ const T_ = coTotal(N), cs = c < T_ ? coCell(N, c).s : null;+ for (let st = 1; st < N; st++) {+ const s0 = coStart(N, st), done = Math.min(Math.max(c - s0, 0), coStage(N, st));+ if (done <= 0) break;+ const L = st - 1, D = N - st, lo = st - 1, hi = st, curSt = st === cs;+ path(PY.layers, poly([[L, 0, lo], [L, D, lo], [L, D, hi], [L, 0, hi]]), { fill: CO.left, stroke: COL.board, 'stroke-width': 1 });+ path(PY.layers, poly([[L, 0, lo], [N, 0, lo], [N, 0, hi], [L, 0, hi]]), { fill: CO.front, stroke: COL.board, 'stroke-width': 1 });+ path(PY.layers, poly([[L, 0, hi], [N, 0, hi], [N, D, hi], [L, D, hi]]), { fill: CO.top, stroke: COL.board, 'stroke-width': 1 });+ // the counted cells of this stage on its top face: row r of the matrix is depth N − r − 1 … N − r+ const w = N - st + 1;+ let lit = '';+ for (let k = 0; k < Math.floor(done); k++) {+ const r = st + Math.floor(k / w), j = L + k % w, d0 = N - r - 1;+ lit += poly([[j, d0, hi], [j + 1, d0, hi], [j + 1, d0 + 1, hi], [j, d0 + 1, hi]]);+ }+ path(PY.layers, lit, { fill: curSt ? CO.cur : CO.lit, 'fill-opacity': curSt ? .75 : .5, stroke: N <= 30 ? COL.board : 'none', 'stroke-width': 1 });+ }+ }++ /* ---------- the readout ---------- */+ let RD = null;+ if (read) {+ const rg = G(g, {}), { x, y, gap = 54, size = 34 } = read;+ const ng = G(rg, {}), og = G(rg, {}), tg = G(rg, {}), qg = G(rg, {});+ M(ng, ['n ='], { x, y, size, fill: COL.chalk, anchor: 'start' });+ const nBox = mk('rect', { x: x + 64, y: y - size * .95, width: 92, height: size * 1.3, rx: 10, fill: 'transparent', 'stroke-dasharray': '4 6' }, ng);+ nBox.setAttribute('aria-label', 'n');+ const nT = G(ng, {}); nT.style.pointerEvents = 'none';+ T(og, 'operations:', { x, y: y + gap, size: size * .85, fill: COL.chalk, weight: 600 });+ const oT = G(og, {});+ const tT = G(tg, {}), qT = G(qg, {});+ RD = { rg, ng, og, tg, qg, nBox, nT, oT, tT, qT, x, y, gap, size };+ parts.read = { g: rg, n: ng, ops: og, third: tg, ratio: qg };+ }+ function drawRead(N, c) {+ const { x, y, gap, size } = RD;+ RD.nT.replaceChildren(); T(RD.nT, String(N), { x: x + 110, y, size, fill: COL.chalk, font: MATH, anchor: 'middle' });+ RD.oT.replaceChildren(); T(RD.oT, coFmt(Math.min(c, coTotal(N))), { x: x + 190, y: y + gap, size, fill: COL.task, weight: 700 });+ RD.tT.replaceChildren(); M(RD.tT, ['n³/3 ≈ ', coThird(N)], { x, y: y + 2 * gap, size: size * .9, fill: COL.chalk, anchor: 'start' });+ RD.qT.replaceChildren(); T(RD.qT, `operations ÷ n³/3 = ${(Math.min(c, coTotal(N)) / (N ** 3 / 3)).toFixed(3)}`, { x, y: y + 3 * gap, size: size * .75, fill: COL.dim, weight: 600 });+ }++ function draw() {+ const k = keyOf();+ if (k === drawn) return;+ drawn = k;+ const N = s.n, c = Math.floor(s.c + 1e-9);+ if (GR) drawGrid(N, c);+ if (CH) drawChart(N, c);+ if (PY) drawPyr(N, c);+ if (RD) drawRead(N, c);+ listeners.forEach(f => f({ ...s }));+ }+ const edit = to => {+ if ('n' in to) { s.n = Math.max(2, Math.min(max, Math.round(to.n))); s.c = 'c' in to ? Math.max(0, Math.min(coTotal(s.n), to.c)) : coTotal(s.n); }+ else if ('c' in to) s.c = Math.max(0, Math.min(coTotal(s.n), to.c));+ draw();+ };++ /* ---------- hands on: n ---------- */+ let live = false;+ if (RD) {+ const bx = RD.nBox;+ let drag = null;+ bx.addEventListener('pointerdown', e => { if (!live) return; e.preventDefault(); drag = { x: e.clientX, from: s.n }; bx.setPointerCapture(e.pointerId); });+ bx.addEventListener('pointermove', e => { if (!drag) return; const k = svg.getScreenCTM().a; edit({ n: drag.from + Math.round((e.clientX - drag.x) / k / 22) }); });+ const end = () => { drag = null; };+ bx.addEventListener('pointerup', end);+ bx.addEventListener('lostpointercapture', end);+ bx.addEventListener('keydown', e => {+ if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); bx.blur(); P.keys?.(e); return; }+ if (!live) return;+ const d = { ArrowUp: 1, ArrowRight: 1, ArrowDown: -1, ArrowLeft: -1, PageUp: 10, PageDown: -10 }[e.key];+ if (!d) return;+ e.preventDefault(); e.stopPropagation();+ edit({ n: s.n + d });+ });+ }++ draw();+ return {+ g, parts, total: coTotal, stage: n_ => coStage(s.n, n_), start: st => coStart(s.n, st),+ get v() { return { ...s }; },+ get plan() { return plan; },+ set(vals) { edit(vals); plan = { ...s }; },+ // on the beat clock: n and c move together (n in whole steps; with n alone every size is fully counted)+ to(next, at, dur = 1.4, ease = io) {+ const from = { ...plan }, goal = { ...plan, ...next };+ if ('n' in next && !('c' in next)) goal.c = coTotal(goal.n);+ plan = goal;+ prog(q => {+ if ('n' in next && !('c' in next)) { const nn = Math.round(from.n + (goal.n - from.n) * q); edit({ n: nn }); }+ else edit({ n: Math.round(from.n + (goal.n - from.n) * q), c: from.c + (goal.c - from.c) * q });+ }, at, dur, ease);+ return at + dur;+ },+ count(st, at, dur = 2, ease = lin) { return this.to({ c: coStart(plan.n, st + 1) }, at, dur, ease); },+ live(on) {+ live = on;+ if (!RD) return;+ RD.nBox.style.cursor = on ? 'ew-resize' : '';+ RD.nBox.setAttribute('stroke', on ? COL.faint : 'none');+ if (on) RD.nBox.setAttribute('tabindex', 0); else RD.nBox.removeAttribute('tabindex');+ },+ onChange(f) { listeners.push(f); },+ };+}++// A question on n: the reader scrubs n until test(v) holds.+const costTask = (ce, test, why, hint, reveal) => (body, api) => {+ ce.live(true);+ return {+ check: () => { const v = ce.v, ok = test(v); api.grade(ok, ok ? why : typeof hint === 'function' ? hint(v) : hint); },+ reveal: () => { reveal?.(); return why; },+ lock: () => ce.live(false),+ hint: [kbd('Tab'), ' to n, ', kbd('↑'), kbd('↓'), ' to change it, or drag it sideways'],+ };+};