An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
feat(linear-algebra): Unit 3 begins: mm.js, chapters 23-25
yzr7c120f8c09a9
diff --git a/site/linear-algebra/ch23/audio/en/cols2.mp3 b/site/linear-algebra/ch23/audio/en/cols2.mp3new file mode 100644index 0000000..df9219bBinary files /dev/null and b/site/linear-algebra/ch23/audio/en/cols2.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/entry.mp3 b/site/linear-algebra/ch23/audio/en/entry.mp3new file mode 100644index 0000000..7bf0fe6Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/entry.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/entry2.mp3 b/site/linear-algebra/ch23/audio/en/entry2.mp3new file mode 100644index 0000000..ca472d9Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/entry2.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/final1.mp3 b/site/linear-algebra/ch23/audio/en/final1.mp3new file mode 100644index 0000000..6c61d48Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/final1.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/final2.mp3 b/site/linear-algebra/ch23/audio/en/final2.mp3new file mode 100644index 0000000..402d1feBinary files /dev/null and b/site/linear-algebra/ch23/audio/en/final2.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/final3.mp3 b/site/linear-algebra/ch23/audio/en/final3.mp3new file mode 100644index 0000000..2fb0b07Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/final3.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/final4.mp3 b/site/linear-algebra/ch23/audio/en/final4.mp3new file mode 100644index 0000000..e7cfe57Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/final4.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/finish.mp3 b/site/linear-algebra/ch23/audio/en/finish.mp3new file mode 100644index 0000000..964addaBinary files /dev/null and b/site/linear-algebra/ch23/audio/en/finish.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/intro.mp3 b/site/linear-algebra/ch23/audio/en/intro.mp3new file mode 100644index 0000000..9803f0cBinary files /dev/null and b/site/linear-algebra/ch23/audio/en/intro.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/nomatch.mp3 b/site/linear-algebra/ch23/audio/en/nomatch.mp3new file mode 100644index 0000000..1d1f851Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/nomatch.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/play.mp3 b/site/linear-algebra/ch23/audio/en/play.mp3new file mode 100644index 0000000..2686088Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/play.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/q1.mp3 b/site/linear-algebra/ch23/audio/en/q1.mp3new file mode 100644index 0000000..ce69fe4Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/q1.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/q2.mp3 b/site/linear-algebra/ch23/audio/en/q2.mp3new file mode 100644index 0000000..73fa4cdBinary files /dev/null and b/site/linear-algebra/ch23/audio/en/q2.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/q3.mp3 b/site/linear-algebra/ch23/audio/en/q3.mp3new file mode 100644index 0000000..609dc39Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/q3.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/recall.mp3 b/site/linear-algebra/ch23/audio/en/recall.mp3new file mode 100644index 0000000..52799e7Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/recall.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/side.mp3 b/site/linear-algebra/ch23/audio/en/side.mp3new file mode 100644index 0000000..14efc38Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/side.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/sizes.mp3 b/site/linear-algebra/ch23/audio/en/sizes.mp3new file mode 100644index 0000000..9497e30Binary files /dev/null and b/site/linear-algebra/ch23/audio/en/sizes.mp3 differdiff --git a/site/linear-algebra/ch23/audio/en/timings.js b/site/linear-algebra/ch23/audio/en/timings.jsnew file mode 100644index 0000000..6c58490--- /dev/null+++ b/site/linear-algebra/ch23/audio/en/timings.js@@ -0,0 +1,701 @@+window.TIMINGS = {+ "intro": {+ "dur": 13.92,+ "marks": {+ "sub": 3.789,+ "move": 7.539+ },+ "cues": [+ [+ 0.104,+ "Chapter twenty-three."+ ],+ [+ 1.888,+ "Matrix times matrix."+ ],+ [+ 3.789,+ "A matrix B is just a few columns standing side by side."+ ],+ [+ 7.539,+ "To multiply A times B, A multiplies each column of B, one after another."+ ]+ ]+ },+ "recall": {+ "dur": 52.368,+ "marks": {+ "A": 2.93,+ "g1": 10.859,+ "v1": 13.789,+ "x": 15.925,+ "mix": 18.294,+ "o1": 23.581,+ "o2": 25.169,+ "land": 26.484,+ "st1": 31.628,+ "st2": 32.852,+ "x2": 36.185,+ "mix2": 39.245,+ "mn": 41.888,+ "land2": 46.016,+ "st3": 48.828,+ "st4": 50.664+ },+ "cues": [+ [+ 0.143,+ "First, chapter nine again, in one minute."+ ],+ [+ 2.93,+ "Here is a matrix A: two, one in the first row, and one, three in the second."+ ],+ [+ 10.3,+ "Its columns are the green arrow, two, one, and the violet arrow, one, three."+ ],+ [+ 15.925,+ "Take x equals one, one."+ ],+ [+ 18.294,+ "A times x is a mix of the columns of A, and x says how much of each: one of column one, plus one of column two."+ ],+ [+ 26.484,+ "Two, one plus one, three is three, four."+ ],+ [+ 30.482,+ "In the picture: one green step, one violet step, and we land on three, four."+ ],+ [+ 36.185,+ "Now a second x: two, minus one."+ ],+ [+ 39.245,+ "Two of column one is four, two."+ ],+ [+ 41.888,+ "Minus one of column two is minus one, minus three."+ ],+ [+ 46.016,+ "Together, three, minus one: two green steps forward, and one violet step back."+ ]+ ]+ },+ "side": {+ "dur": 39.84,+ "marks": {+ "side": 0.104,+ "B": 6.471,+ "ask": 11.341,+ "rule": 12.812,+ "c1": 16.94,+ "put1": 20.104,+ "c2": 21.927,+ "put2": 25.456,+ "ab": 27.331,+ "r1": 28.086,+ "r2": 30.898,+ "pic": 33.555+ },+ "cues": [+ [+ 0.104,+ "Now stand the two x's side by side: one, one on the left, and two, minus one on the right."+ ],+ [+ 6.471,+ "Columns standing side by side make a matrix."+ ],+ [+ 10.339,+ "Call it B."+ ],+ [+ 11.341,+ "So what is A times B?"+ ],+ [+ 12.812,+ "It's exactly what we just did: A times each column of B."+ ],+ [+ 16.94,+ "A times column one of B is three, four."+ ],+ [+ 20.104,+ "That's column one of the answer."+ ],+ [+ 21.927,+ "A times column two of B is three, minus one."+ ],+ [+ 25.456,+ "That's column two of the answer."+ ],+ [+ 27.331,+ "So A B is three, three in the first row, and four, minus one in the second."+ ],+ [+ 33.555,+ "In the picture, each column of B is a point, and A carries it to the matching column of A B."+ ]+ ]+ },+ "cols2": {+ "dur": 65.376,+ "marks": {+ "A": 2.812,+ "a1": 3.112,+ "a2": 5.925,+ "B": 8.229,+ "n": 15.208,+ "c1": 19.023,+ "c2": 26.927,+ "c3": 35.365,+ "ab": 42.487,+ "r1": 43.086,+ "r2": 46.276,+ "change": 48.958,+ "only": 54.987,+ "why": 61.576+ },+ "cues": [+ [+ 0.104,+ "Another one, with three columns."+ ],+ [+ 2.812,+ "A is one, minus one in the first row, and two, one in the second."+ ],+ [+ 8.229,+ "B has three columns: one, one; then two, one; then zero, three."+ ],+ [+ 15.208,+ "Three columns in B, so three columns in A B."+ ],+ [+ 19.023,+ "Column one: one of column one of A, plus one of column two."+ ],+ [+ 22.982,+ "One, two plus minus one, one is zero, three."+ ],+ [+ 26.927,+ "Column two: two of column one, plus one of column two."+ ],+ [+ 31.445,+ "Two, four plus minus one, one is one, five."+ ],+ [+ 35.365,+ "Column three: none of column one, and three of column two."+ ],+ [+ 40.352,+ "That's minus three, three."+ ],+ [+ 42.487,+ "So A B is zero, one, minus three on top, and three, five, three below."+ ],+ [+ 48.958,+ "Now watch while one number of B changes."+ ],+ [+ 51.589,+ "The bottom of column three goes from three down to one."+ ],+ [+ 54.987,+ "Only column three of A B moves, to minus one, one."+ ],+ [+ 58.737,+ "Columns one and two stay where they are."+ ],+ [+ 61.576,+ "Each column of A B depends only on its own column of B."+ ]+ ]+ },+ "q1": {+ "dur": 3.696,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.081,+ "Work out A B, one column at a time."+ ]+ ]+ },+ "entry": {+ "dur": 58.296,+ "marks": {+ "back": 4.01,+ "top": 5.521,+ "ch9": 9.323,+ "rx": 12.083,+ "mx": 13.971,+ "e11": 16.693,+ "ra": 18.112,+ "cb": 20.742,+ "m11": 22.357,+ "s11": 25.169,+ "e21": 26.888,+ "e12": 32.8,+ "e22": 40.482,+ "rule": 48.607,+ "ri": 52.747,+ "cj": 53.958,+ "name": 55.352+ },+ "cues": [+ [+ 0.117,+ "Sometimes we want just one number of A B, not a whole column."+ ],+ [+ 4.01,+ "Back to our first pair."+ ],+ [+ 5.521,+ "The top number of column one is three."+ ],+ [+ 8.164,+ "Where does it come from?"+ ],+ [+ 9.323,+ "In chapter nine, each number of A times x was a row of A times x: multiply number by number, then add."+ ],+ [+ 16.693,+ "So the top of column one is row one of A, two, one, times column one of B, one, one."+ ],+ [+ 22.357,+ "Two times one, plus one times one."+ ],+ [+ 25.169,+ "Two plus one is three."+ ],+ [+ 26.888,+ "Row two with column one: one times one, plus three times one, is four."+ ],+ [+ 32.8,+ "Row one with column two: two times two, plus one times minus one."+ ],+ [+ 38.346,+ "Four minus one is three."+ ],+ [+ 40.482,+ "Row two with column two: one times two, plus three times minus one."+ ],+ [+ 46.107,+ "Two minus three is minus one."+ ],+ [+ 48.607,+ "The rule: the number in row i, column j of A B is row i of A times column j of B."+ ],+ [+ 55.352,+ "We call it the i, j entry of A B."+ ]+ ]+ },+ "entry2": {+ "dur": 50.376,+ "marks": {+ "A": 4.036,+ "B": 7.682,+ "e11": 10.651,+ "e12": 18.359,+ "e21": 25.82,+ "e22": 33.529,+ "ab": 41.237,+ "four": 46.445+ },+ "cues": [+ [+ 0.104,+ "Let's use the rule on bigger numbers, too big for our picture."+ ],+ [+ 4.036,+ "A is one, two, and three, four."+ ],+ [+ 7.682,+ "B is five, six, and seven, eight."+ ],+ [+ 10.651,+ "Row one times column one: one times five, plus two times seven."+ ],+ [+ 15.807,+ "Five plus fourteen is nineteen."+ ],+ [+ 18.359,+ "Row one times column two: one times six, plus two times eight."+ ],+ [+ 23.438,+ "Six plus sixteen is twenty-two."+ ],+ [+ 25.82,+ "Row two times column one: three times five, plus four times seven."+ ],+ [+ 30.833,+ "Fifteen plus twenty-eight is forty-three."+ ],+ [+ 33.529,+ "Row two times column two: three times six, plus four times eight."+ ],+ [+ 38.464,+ "Eighteen plus thirty-two is fifty."+ ],+ [+ 41.237,+ "So A B is nineteen, twenty-two, and forty-three, fifty."+ ],+ [+ 46.445,+ "Four entries, and each one is a row times a column."+ ]+ ]+ },+ "q2": {+ "dur": 6.216,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Your turn."+ ],+ [+ 1.029,+ "Change column two of B until column two of A B lands on the target."+ ]+ ]+ },+ "sizes": {+ "dur": 65.688,+ "marks": {+ "A": 1.484,+ "B": 6.836,+ "inner": 11.654,+ "pair": 16.471,+ "e11": 18.529,+ "e12": 28.372,+ "e21": 36.211,+ "e22": 42.344,+ "outer": 48.672,+ "rule": 54.844,+ "in2": 60.781,+ "out2": 62.917+ },+ "cues": [+ [+ 0.104,+ "Now the sizes."+ ],+ [+ 1.484,+ "This A has two rows and three columns: we say it is two by three."+ ],+ [+ 6.836,+ "This B has three rows and two columns: it is three by two."+ ],+ [+ 11.654,+ "A row of A has three numbers, and a column of B has three numbers too."+ ],+ [+ 16.354,+ "So they pair up, one with one."+ ],+ [+ 18.529,+ "Entry one, one: one times one, plus two times two, plus zero times zero."+ ],+ [+ 25.599,+ "One plus four plus zero is five."+ ],+ [+ 28.372,+ "Entry one, two: one times one, plus two times zero, plus zero times three, is one."+ ],+ [+ 36.211,+ "Entry two, one: zero, plus two, plus zero, is two."+ ],+ [+ 42.344,+ "Entry two, two: zero, plus zero, plus three, is three."+ ],+ [+ 48.672,+ "A B has two rows, like A, and two columns, like B: it is two by two."+ ],+ [+ 54.844,+ "So the rule for sizes: m by n, times n by p, gives m by p."+ ],+ [+ 60.781,+ "The inside numbers must match."+ ],+ [+ 62.917,+ "The outside numbers give the size of the answer."+ ]+ ]+ },+ "nomatch": {+ "dur": 41.184,+ "marks": {+ "drop": 2.37,+ "row": 5.964,+ "cb": 8.477,+ "no": 11.068,+ "nd": 13.659,+ "flip": 17.5,+ "sz": 23.138,+ "big": 29.714,+ "order": 33.177,+ "mat": 37.201+ },+ "cues": [+ [+ 0.104,+ "What if the inside numbers don't match?"+ ],+ [+ 2.37,+ "Take away the last row of B, so B is two by two."+ ],+ [+ 5.964,+ "Now a row of A has three numbers, but a column of B has only two."+ ],+ [+ 11.068,+ "The third number of the row has no partner."+ ],+ [+ 13.659,+ "A B is not defined: there is no product at all."+ ],+ [+ 17.5,+ "Now put B back as it was, three by two, and try the other order: B times A."+ ],+ [+ 23.138,+ "Three by two, times two by three."+ ],+ [+ 25.859,+ "The inside numbers are two and two: they match."+ ],+ [+ 29.714,+ "And the answer, B A, is three by three."+ ],+ [+ 33.177,+ "So A B was two by two, but B A is three by three."+ ],+ [+ 37.201,+ "The order matters."+ ],+ [+ 38.503,+ "More about that in chapter twenty-five."+ ]+ ]+ },+ "q3": {+ "dur": 1.872,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check on sizes."+ ]+ ]+ },+ "wrap": {+ "dur": 31.08,+ "marks": {+ "w1": 1.055,+ "w2": 7.656,+ "w3": 15.638,+ "w4": 22.604,+ "end": 28.802+ },+ "cues": [+ [+ 0.104,+ "Let's sum up."+ ],+ [+ 1.055,+ "A times B is A times each column of B: column j of A B is A times column j of B."+ ],+ [+ 7.656,+ "Each column of A B is a mix of the columns of A, so in the picture, A carries each column of B to a column of A B."+ ],+ [+ 15.638,+ "One entry at a time: the i, j entry of A B is row i of A times column j of B."+ ],+ [+ 22.604,+ "m by n, times n by p, gives m by p."+ ],+ [+ 26.615,+ "The inside numbers must match."+ ],+ [+ 28.802,+ "Now try the chapter practice."+ ]+ ]+ },+ "final1": {+ "dur": 4.176,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Chapter practice."+ ],+ [+ 1.55,+ "Work out A B, one column at a time."+ ]+ ]+ },+ "final2": {+ "dur": 4.344,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Now entry by entry: each one is a row times a column."+ ]+ ]+ },+ "final3": {+ "dur": 4.608,+ "marks": {},+ "cues": [+ [+ 0.117,+ "Sizes."+ ],+ [+ 1.263,+ "Which products are allowed, and how big is the answer?"+ ]+ ]+ },+ "final4": {+ "dur": 5.184,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Last set."+ ],+ [+ 1.224,+ "Move the columns of B in the picture to hit each target."+ ]+ ]+ },+ "play": {+ "dur": 12.312,+ "marks": {+ "go": 4.102+ },+ "cues": [+ [+ 0.117,+ "Playground."+ ],+ [+ 1.107,+ "Nothing here is marked right or wrong."+ ],+ [+ 4.102,+ "Change any number of A or B, drag the points and arrows, or change the sizes, and watch A B follow."+ ]+ ]+ },+ "finish": {+ "dur": 10.896,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Well done."+ ],+ [+ 1.12,+ "That's the end of chapter twenty-three, matrix times matrix."+ ],+ [+ 5.651,+ "Next: four ways to multiply, and the same product four times over."+ ]+ ]+ }+};diff --git a/site/linear-algebra/ch23/audio/en/wrap.mp3 b/site/linear-algebra/ch23/audio/en/wrap.mp3new file mode 100644index 0000000..9df5f4dBinary files /dev/null and b/site/linear-algebra/ch23/audio/en/wrap.mp3 differdiff --git a/site/linear-algebra/ch23/index.html b/site/linear-algebra/ch23/index.htmlnew file mode 100644index 0000000..7334cfc--- /dev/null+++ b/site/linear-algebra/ch23/index.html@@ -0,0 +1,382 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>Matrix Times Matrix</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/grid2.js"></script>+<script src="../lib/mm.js"></script>+<script src="../lib/play.js"></script>+<script src="audio/en/timings.js"></script>+<script>+'use strict';+const CHAPTER = { number: 23, title: 'Matrix Times Matrix', minutes: 10, language: 'en', next: '../ch24/' };++/* ---------- chapter drawing helpers ---------- */+const GREEN = MM_COL[0], VIOLET = MM_COL[1];+const A1 = [[2, 1], [1, 3]], B1 = [[1, 2], [1, -1]]; // the first pair: AB = [[3, 3], [4, −1]]+const A2 = [[1, -1], [2, 1]], B2 = [[1, 2, 0], [1, 1, 3]]; // three columns: AB = [[0, 1, −3], [3, 5, 3]]+const AT = [70, 260]; // where A B = AB starts beside the plane+const PLANE = { cx: 1190, cy: 450, u: 50 };+const CARD = { x: 40, y: 610, w: 780, 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 });+// The plane of chapter 9: A's columns as green and violet arrows, x as a ring, Ax as the amber arrow (no grid).+const plane2 = (p, A, x, o = {}) => {+ const g = grid2(p, { A, x, mat: null, grid: false, square: false, units: false, brackets: true, plane: PLANE, ...o });+ g.labels(['col 1', 'col 2']);+ return g;+};+// A B = AB beside the plane, linked: the plane's x is a column of B, its Ax that column of AB.+const pair = (p, A, B, { col = 0, dots = true, hideC = false, t0 = .1, at = AT, x = null } = {}) => {+ const g = plane2(p, A, x || B.map(r => r[col]), { t0 });+ const P_ = mm(p, { A, B, at, tintA: 'cols', hideC, t0 });+ P_.link(g, { col, dots });+ return { g, P: P_ };+};+// A line of vectors and words, each piece arriving on its own time: items are [t, parts] or [t, { v: [..], fill }].+const vline = (p, x, y, items, { size = 30 } = {}) => {+ items.forEach(([t, it]) => {+ const e = G(p, { o: 0 });+ if (it.v) x += mmSmall(e, it.v.map(q => [q]), x, y, { size, fill: () => it.fill || COL.chalk }) + 10;+ else { const w = M(e, [].concat(it), { x, y: y + size * .36, size, fill: COL.chalk, anchor: 'start' }); x += (w._w || 20) + 10; }+ show(e, t, .35);+ });+};+const target = (P2, [x, y], into, t0 = .3) => {+ const g = G(into, { x: P2.PX(x), y: P2.PY(y), o: 0 });+ mk('circle', { r: 17, fill: 'none', stroke: COL.task, 'stroke-width': 3, 'stroke-dasharray': '5 5' }, g);+ T(g, `target (${num(x)}, ${num(y)})`, { x: 22, y: 40, size: 22, fill: COL.task, font: MATH });+ show(g, t0, .4);+ return g;+};+// A stroke that swells for a moment: the arrow the voice names.+const thick = (e, t0, w = 5) => { tw(e, { 'a_stroke-width': w + 5 }, t0, .3); tw(e, { 'a_stroke-width': w }, t0 + 1.2, .6); };+const flashEl = (e, t0, col = COL.task) => { const c0 = e.getAttribute('fill'); tw(e, { c_fill: col }, t0, .25); tw(e, { c_fill: c0 }, t0 + 1.2, .6); };+const ruleCard = (p, x, y, t0, size = 40) => {+ const g = G(p, { o: 0 });+ M(g, ['(m × n)(n × p) = m × p'], { x, y, size, fill: COL.chalk, anchor: 'start' });+ show(g, t0, .5);+ return g;+};+const pairEl = (A, B) => ['A = ', mmEl(A, { fill: (i, j) => MM_COL[j] }), ' B = ', mmEl(B)];+const sizeEq = (a, b) => `${a[0]} × ${a[1]} times ${b[0]} × ${b[1]}`;++/* ---------- practice data (every answer worked twice: by columns and by entries) ---------- */+const COLQ = [+ { A: [[1, 1], [0, 2]], B: [[2, 1], [3, -1]], C: [[5, 0], [6, -2]] },+ { A: [[3, 0], [1, 1]], B: [[1, 2], [2, 0]], C: [[3, 6], [3, 2]] },+ { A: [[2, -1], [1, 0]], B: [[1, 0, 2], [1, 1, 1]], C: [[1, -1, 3], [1, 0, 2]] },+ { A: [[1, 2], [-1, 1]], B: [[0, 1], [1, 1]], C: [[2, 3], [1, 0]] },+];+const colRows = ({ A, B, C }) => C[0].map((_, j) => ({+ parts: [`column ${j + 1} of AB = (`, { box: String(C[0][j]) }, ', ', { box: String(C[1][j]) }, ')'],+ why: `${B[0][j] < 0 ? '(' + num(B[0][j]) + ')' : num(B[0][j])}·(${num(A[0][0])}, ${num(A[1][0])}) + ${B[1][j] < 0 ? '(' + num(B[1][j]) + ')' : num(B[1][j])}·(${num(A[0][1])}, ${num(A[1][1])}) = (${num(C[0][j])}, ${num(C[1][j])}).`,+ hint: `Column ${j + 1} of B is (${num(B[0][j])}, ${num(B[1][j])}): that much of column 1 of A, plus that much of column 2.`,+}));+const ENTQ = [+ { A: [[1, 2], [3, 4]], B: [[2, 0], [1, 3]], C: [[4, 6], [10, 12]] },+ { A: [[2, -1], [0, 3]], B: [[1, 4], [2, -2]], C: [[0, 10], [6, -6]] },+ { A: [[1, 0, 2], [3, 1, -1]], B: [[2, 1], [0, 4], [1, -2]], C: [[4, -3], [5, 9]] },+];+const dotStr = (r, c) => r.map((v, k) => `${v < 0 ? '(' + num(v) + ')' : num(v)}·${c[k] < 0 ? '(' + num(c[k]) + ')' : num(c[k])}`).join(' + ');+const entRows = ({ A, B, C }) => C.map((r, i) => ({+ parts: [`row ${i + 1} of AB = (`, ...r.flatMap((v, j) => [...(j ? [', '] : []), { box: String(v) }]), ')'],+ why: r.map((v, j) => `entry (${i + 1}, ${j + 1}): ${dotStr(A[i], B.map(q => q[j]))} = ${num(v)}`).join('; ') + '.',+ hint: `Row ${i + 1} of A times each column of B: multiply number by number, then add.`,+}));+const FITQ = [+ { s: [[2, 3], [3, 5]], ok: true }, { s: [[3, 2], [3, 2]], ok: false }, { s: [[1, 4], [4, 1]], ok: true },+ { s: [[4, 1], [1, 4]], ok: true }, { s: [[2, 2], [3, 3]], ok: false }, { s: [[3, 3], [3, 1]], ok: true },+].map(({ s, ok }) => ({ parts: [sizeEq(...s)], ans: [ok ? 'y' : 'n'],+ why: ok ? `Inside numbers ${s[0][1]} and ${s[1][0]} match: the answer is ${s[0][0]} × ${s[1][1]}.` : `Inside numbers ${s[0][1]} and ${s[1][0]} differ: a row of the first has ${s[0][1]} numbers, a column of the second ${s[1][0]}.` }));+const SIZEQ = [+ { s: [[2, 3], [3, 5]], r: [2, 5] }, { s: [[1, 4], [4, 1]], r: [1, 1] }, { s: [[4, 1], [1, 4]], r: [4, 4] }, { s: [[3, 3], [3, 1]], r: [3, 1] },+].map(({ s, r }) => ({ parts: [sizeEq(...s) + ' gives ', { box: String(r[0]) }, ' × ', { box: String(r[1]) }],+ why: `The outside numbers: ${r[0]} rows (from the first), ${r[1]} columns (from the second).`, hint: 'Rows from the first matrix, columns from the second.' }));+const HANDS = [+ { A: [[1, 1], [0, 1]], B: [[0, 0], [0, 0]], col: 0, tgt: [3, 1], ans: { b00: 2, b10: 1 }, prompt: 'Move column 1 of B (the ring x) until column 1 of AB lands on the target.',+ why: 'Column 1 of B = (2, 1): 2·(1, 0) + 1·(1, 1) = (3, 1).' },+ { A: [[2, 0], [0, 1]], B: [[1, 0], [1, 0]], col: 1, tgt: [-2, 3], ans: { b01: -1, b11: 3 }, prompt: 'Now column 2: make column 2 of AB land on the target.',+ why: 'Column 2 of B = (−1, 3): −1·(2, 0) + 3·(0, 1) = (−2, 3).' },+ { A: [[1, 0], [0, 1]], B: [[1, 0], [0, 1]], col: 0, tgt: null, ans: { a00: 2, a01: 1, a10: 1, a11: 2 }, prompt: 'B is the identity. Change A (its numbers or its arrows) until AB = [2 1; 1 2].',+ why: 'B = I, so AB = A: A must be [2 1; 1 2] itself. Each column of I picks one column of A.' },+];++/* ---------- beats ---------- */+const BEATS = [+ ['intro', 'Matrix times matrix', (m, D) => {+ const g = G(scene, { o: 0, y: 24 });+ T(g, 'Unit 3, Chapter 23', { x: 800, y: 250, size: 28, fill: COL.dim, anchor: 'middle' });+ T(g, 'Unit 3 · Multiplication and inverse matrices', { x: 800, y: 205, size: 24, fill: COL.faint, anchor: 'middle' });+ T(g, 'Matrix Times Matrix', { x: 800, y: 360, size: 88, weight: 600, anchor: 'middle' });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);+ const r = text(scene, 'A multiplies each column of B, one after another', 800, 460, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });+ const lg = G(scene, { o: 0 });+ const P_ = mm(lg, { A: A1, B: B1, at: [530, 600], size: 36, cw: 56, tintA: 'cols', hideC: true, sizes: false, t0: 0 });+ show(lg, m('sub') + 1, .5);+ put(P_.W, { o: 0 });+ P_.show('cols', 0, m('move') + .3); P_.reveal({ col: 0 }, m('move') + 1.3);+ P_.show('cols', 1, m('move') + 2.6); P_.reveal({ col: 1 }, m('move') + 3.6);+ P_.show(null, null, m('move') + 5);+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);+ }],++ ['recall', 'A times x', (m) => {+ const p = panel(0);+ title(p, 'Chapter 9 again: A times x');+ const g = grid2(p, { A: A1, x: [1, 1], mat: [90, 250], grid: false, square: false, units: false, brackets: true, plane: PLANE, t0: m('A') - .4 });+ g.labels(['col 1', 'col 2']);+ const res = [0, 1].map(i => g.res(i));+ res.forEach(e => { put(e, { o: 0 }); show(e, m('land'), .4); });+ put(g.parts.x, { o: 0 }); show(g.parts.x, m('x'), .4);+ ['x0', 'x1'].forEach(k => g.num(k).forEach(e => { put(e, { o: 0 }); show(e, m('x'), .4); }));+ [0, 1].forEach(j => { put(g.cols[j], { o: 0 }); show(g.cols[j], m('A') + 2.2 + j * 2, .5); put(g.tipLabels[j], { o: 0 }); show(g.tipLabels[j], m('A') + 2.2 + j * 2, .5); });+ vline(p, 90, 520, [[m('o1'), ['1·']], [m('o1'), { v: [2, 1], fill: GREEN }], [m('o2'), ['+ 1·']], [m('o2'), { v: [1, 3], fill: VIOLET }], [m('land'), ['=']], [m('land'), { v: [3, 4], fill: COL.task }]]);+ g.to({ x0: 2, x1: -1 }, m('x2'), 1.6);+ vline(p, 90, 660, [[m('mix2'), ['2·']], [m('mix2'), { v: [2, 1], fill: GREEN }], [m('mn'), ['+ (−1)·']], [m('mn'), { v: [1, 3], fill: VIOLET }], [m('land2'), ['=']], [m('land2'), { v: [3, -1], fill: COL.task }]]);+ pulse(g.axDot, m('land') + .4); pulse(g.axDot, m('land2') + .4);+ thick(g.cols[0], m('g1')); thick(g.cols[1], m('v1'));+ thick(g.cols[0], m('mix') + 2.2); thick(g.cols[1], m('mix') + 2.2);+ ['x0', 'x1'].forEach((k, i) => g.num(k).forEach(e => flashEl(e, m(i ? 'o2' : 'o1'))));+ thick(g.combo[0], m('st1'), 4); thick(g.combo[1], m('st2'), 4); thick(g.combo[0], m('st3'), 4); thick(g.combo[1], m('st4'), 4);+ ['x0', 'x1'].forEach((k, i) => g.num(k).forEach(e => flashEl(e, m(i ? 'mn' : 'mix2'))));+ }],++ ['side', 'Side by side', (m) => {+ const p = panel(0);+ title(p, 'Two columns side by side: a matrix B');+ const { g, P: P_ } = pair(p, A1, B1, { hideC: true, t0: m('side') - .3 });+ put(P_.g, { o: 0 }); show(P_.g, m('side'), .5);+ put(g.parts.cols, { o: 1 });+ P_.flash('b', { col: 0 }, m('side') + .6); P_.flash('b', { col: 1 }, m('side') + 3);+ P_.flash('b', 'all', m('B') + .3);+ put(P_.L.c.g, { o: 0 }); show(P_.L.c.g, m('ask'), .4);+ const rl = text(p, 'A B = A times each column of B', 70, 720, m('rule'), { size: 32, weight: 600 });+ P_.linkCol(0, m('c1')); P_.show('cols', 0, m('c1'), { times: [m('c1'), m('c1') + 1.4, m('c1') + 2.4] });+ P_.reveal({ col: 0 }, m('put1'));+ P_.linkCol(1, m('c2')); P_.show('cols', 1, m('c2'), { times: [m('c2'), m('c2') + 1.4, m('c2') + 2.6] });+ P_.reveal({ col: 1 }, m('put2'));+ P_.show(null, null, m('ab')); P_.flash('c', { row: 0 }, m('r1')); P_.flash('c', { row: 1 }, m('r2'));+ hide(rl, m('ab'), .3);+ text(p, 'each column of B is a point; A carries it to the same column of AB', 70, 720, m('pic') + .3, { size: 26, fill: COL.dim, weight: 600 });+ pulse(g.axDot, m('pic') + 1.5);+ P_.linkCol(0, m('pic') + 3); P_.linkCol(1, m('pic') + 5.5);+ }],++ ['cols2', 'Three columns', (m) => {+ const p = panel(0);+ title(p, 'B with three columns');+ const { g, P: P_ } = pair(p, A2, B2, { hideC: true, t0: m('A') - .3 });+ put(P_.L.b.g, { o: 0 }); show(P_.L.b.g, m('B'), .5);+ put(P_.L.c.g, { o: 0 }); show(P_.L.c.g, m('n'), .5);+ put(g.parts.x, { o: 0 }); show(g.parts.x, m('c1'), .4);+ P_.flash('a', { row: 0 }, m('a1')); P_.flash('a', { row: 1 }, m('a2'));+ [0, 1, 2].forEach(j => P_.flash('b', { col: j }, m('B') + .8 + j * 1.1));+ P_.flash('c', 'all', m('n') + .5);+ [['c1', 0], ['c2', 1], ['c3', 2]].forEach(([k, j]) => {+ P_.linkCol(j, m(k)); P_.show('cols', j, m(k), { times: [m(k) + .2, m(k) + 2.4, m(k) + 3.6] });+ P_.reveal({ col: j }, m(k) + 3.8);+ });+ P_.show(null, null, m('ab')); P_.flash('c', { row: 0 }, m('r1')); P_.flash('c', { row: 1 }, m('r2'));+ P_.show('cols', 2, m('change'));+ P_.to({ b12: 1 }, m('change') + 2.6, 1.8);+ P_.flash('c', { col: 2 }, m('only') + .2);+ P_.flash('c', { col: 0 }, m('only') + 2.6); P_.flash('c', { col: 1 }, m('only') + 2.9);+ text(p, 'column j of AB uses only column j of B', 70, 740, m('why'), { size: 30, weight: 600 });+ P_.flash('b', { col: 2 }, m('why') + .3); P_.flash('c', { col: 2 }, m('why') + 1.6);+ }],++ ['q1', 'Quick check', () => {+ const p = panel(0);+ title(p, 'Quick check');+ const t = pair(p, [[1, 2], [0, 1]], [[3, 1], [1, 2]], { hideC: true });+ S.P = t.P;+ }, { ask: done => quiz({ ...CARD, y: 470 }, [{+ id: 'c-cols', prompt: ['Work out AB one column at a time: A times each column of B.'],+ build: blanks([+ { parts: ['column 1 of AB = (', { box: '5' }, ', ', { box: '1' }, ')'], why: '3·(1, 0) + 1·(2, 1) = (5, 1).', hint: 'Column 1 of B is (3, 1): 3 of column 1 of A, plus 1 of column 2.',+ fx: () => fxp(q => { if (q > 0) S.P.uncover({ col: 0 }); }, 0, .1) },+ { parts: ['column 2 of AB = (', { box: '5' }, ', ', { box: '2' }, ')'], why: '1·(1, 0) + 2·(2, 1) = (5, 2).', hint: 'Column 2 of B is (1, 2): 1 of column 1 of A, plus 2 of column 2.',+ fx: () => fxp(q => { if (q > 0) S.P.uncover({ col: 1 }); }, 0, .1) },+ ]),+ }], done) }],++ ['entry', 'One entry at a time', (m) => {+ const p = panel(0);+ title(p, 'One number at a time: row times column');+ const { P: P_ } = pair(p, A1, B1);+ P_.flash('c', 'all', .6); P_.flash('c', { cell: [0, 0] }, m('top') + .2); P_.flash('c', { cell: [0, 0] }, m('top') + 2.4);+ P_.flash('a', { row: 0 }, m('rx')); P_.flash('b', { col: 0 }, m('rx') + 1.2); P_.flash('a', { row: 1 }, m('mx')); P_.flash('b', { col: 0 }, m('mx') + 1);+ P_.flash('a', { row: 0 }, m('ra')); P_.flash('b', { col: 0 }, m('cb'));+ text(p, 'chapter 9: each number of Ax = a row of A times x', 70, 720, m('ch9'), { size: 26, fill: COL.dim, weight: 600 });+ P_.show('entry', [0, 0], m('e11'), { times: [m('m11'), m('s11'), m('s11') + 1.2] });+ P_.show('entry', [1, 0], m('e21'), { times: [m('e21') + 1.2, m('e21') + 3.4, m('e21') + 4.4] });+ P_.linkCol(1, m('e12'));+ P_.show('entry', [0, 1], m('e12'), { times: [m('e12') + 1.2, m('e12') + 4, m('e12') + 4.9] });+ P_.show('entry', [1, 1], m('e22'), { times: [m('e22') + 1.2, m('e22') + 4.2, m('e22') + 5.1] });+ P_.show(null, null, m('rule'));+ const rg = G(p, { o: 0 });+ M(rg, ['entry (i, j) of AB = row i of A · column j of B'], { x: 70, y: 790, size: 32, fill: COL.chalk, anchor: 'start' });+ show(rg, m('rule') + .3, .5);+ P_.flash('a', { row: 1 }, m('ri')); P_.flash('b', { col: 0 }, m('cj'));+ P_.show('entry', [1, 0], m('name') + .2);+ }],++ ['entry2', 'Bigger numbers', (m) => {+ const p = panel(0);+ title(p, 'The rule on bigger numbers');+ const P_ = mm(p, { A: [[1, 2], [3, 4]], B: [[5, 6], [7, 8]], at: [380, 270], size: 46, cw: 70, cwC: 92, rh: 68, hideC: true, t0: m('A') - .3, wsize: 34 });+ put(P_.L.b.g, { o: 0 }); show(P_.L.b.g, m('B'), .5);+ P_.flash('a', 'all', m('A') + .3); P_.flash('b', 'all', m('B') + .3);+ [['e11', [0, 0]], ['e12', [0, 1]], ['e21', [1, 0]], ['e22', [1, 1]]].forEach(([k, c]) => {+ P_.show('entry', c, m(k), { times: [m(k) + 1.5, m(k) + 4.6, m(k) + 5.3] });+ P_.reveal({ cell: c }, m(k) + 5.3);+ });+ P_.show(null, null, m('ab')); P_.flash('c', 'all', m('ab') + .3);+ text(p, 'four entries, each one a row times a column', 380, 640, m('four'), { size: 30, weight: 600 });+ }],++ ['q2', 'Your turn', () => {+ const p = panel(0);+ title(p, 'Your turn');+ const t = pair(p, A2, [[1, 0], [1, 0]], { col: 1 });+ S.P = t.P; S.g = t.g;+ target(t.g.P, [1, 5], p, .3);+ t.P.show('cols', 1, .4);+ }, { ask: done => quiz(CARD, [{+ id: 'c-land', prompt: ['Change column 2 of B (drag the ring x, or its numbers) until column 2 of AB lands on the target.'],+ build: mmTask(S.P, (v, C) => C[0][1] === 1 && C[1][1] === 5, 'Column 2 of B = (2, 1): 2·(1, 2) + 1·(−1, 1) = (1, 5).',+ (v, C) => `Column 2 of AB is (${num(Math.round(C[0][1] * 10) / 10)}, ${num(Math.round(C[1][1] * 10) / 10)}). It is ${num(Math.round(v.b01))} of column 1 of A plus ${num(Math.round(v.b11))} of column 2.`,+ () => S.P.set({ b01: 2, b11: 1 }), { only: ['b01', 'b11'] }),+ }], done) }],++ ['sizes', 'Sizes', (m) => {+ const p = panel(0);+ title(p, 'Sizes: two by three times three by two');+ const P_ = S.P = mm(p, { A: [[1, 2, 0], [0, 1, 1]], B: [[1, 1], [2, 0], [0, 3]], at: [300, 260], hideC: true, t0: m('A') - .3 });+ put(P_.L.b.g, { o: 0 }); show(P_.L.b.g, m('B'), .5);+ put(P_.L.sz, { o: 0 }); show(P_.L.sz, m('A') + 1.5, .5);+ P_.flash('a', { row: 0 }, m('A') + 1.5); P_.flash('a', { col: 2 }, m('A') + 3);+ P_.inner(m('inner'));+ P_.show('entry', [0, 0], m('inner') + .3);+ P_.flash('a', { row: 0 }, m('inner') + 1); P_.flash('b', { col: 0 }, m('inner') + 3); P_.flash('a', { row: 0 }, m('pair')); P_.flash('b', { col: 0 }, m('pair'));+ [['e11', [0, 0]], ['e12', [0, 1]], ['e21', [1, 0]], ['e22', [1, 1]]].forEach(([k, c], i) => {+ const long = i === 0;+ P_.show('entry', c, m(k), { times: [m(k) + (long ? 1 : 1.1), m(k) + (long ? 5.6 : 4), m(k) + (long ? 7 : 4.6)] });+ P_.reveal({ cell: c }, m(k) + (long ? 7 : 4.6));+ });+ P_.show(null, null, m('outer'));+ P_.outer(m('outer'));+ ruleCard(p, 300, 720, m('rule'), 44);+ P_.inner(m('in2') - .2, false); P_.inner(m('in2') + .4); P_.outer(m('out2') - .2, false); P_.outer(m('out2') + .4);+ text(p, 'inside numbers must match; outside numbers give the size of the answer', 300, 790, m('rule') + 5, { size: 26, fill: COL.dim, weight: 600 });+ }],++ ['nomatch', 'No product', (m, D) => {+ const p = panel(0);+ title(p, 'When the inside numbers differ');+ const top = G(p, {});+ const P_ = mm(top, { A: [[1, 2, 0], [0, 1, 1]], B: [[1, 1], [2, 0], [0, 3]], at: [300, 260], t0: 0 });+ P_.inner(0);+ P_.to({ nB: 2 }, m('drop') + .4, .1);+ P_.flash('a', { row: 0 }, m('row') + .2); P_.flash('b', { col: 0 }, m('cb'));+ P_.flash('a', { cell: [0, 2] }, m('no'), { color: COL.bad }); P_.flash('a', { cell: [1, 2] }, m('no') + 1, { color: COL.bad });+ P_.flash('b', 'all', m('nd'), { color: COL.bad });+ hide(top, m('flip'), .5);+ const bot = G(p, { o: 0 }); show(bot, m('flip') + .6, .5);+ const Q = mm(bot, { A: [[1, 1], [2, 0], [0, 3]], B: [[1, 2, 0], [0, 1, 1]], names: ['B', 'A', 'BA'], at: [240, 260], hideC: true, t0: 0 });+ Q.inner(m('sz'));+ Q.flash('a', 'all', m('flip') + 1.5); Q.flash('b', 'all', m('flip') + 3);+ Q.outer(m('big')); Q.reveal('all', m('big') + .3);+ Q.flash('c', 'all', m('mat'));+ text(p, 'AB was 2 × 2, BA is 3 × 3: the order matters (chapter 25)', 240, 780, m('order'), { size: 28, weight: 600 });+ }],++ ['q3', 'Quick check', () => {+ const p = panel(0);+ title(p, 'Quick check');+ ruleCard(p, 70, 220, .3, 40);+ }, { ask: done => quiz({ x: 40, y: 300, w: 900, cls: 'side' }, [{+ id: 'c-fit', prompt: ['A is 3 × 2 and B is 3 × 2. What is AB?'],+ build: choice([['a 3 × 2 matrix'], ['a 2 × 2 matrix'], ['not defined']], 2, 'A row of A has 2 numbers, a column of B has 3: the inside numbers 2 and 3 differ, so AB is not defined.',+ ['That would need the inside numbers to match. A row of A has 2 numbers; a column of B has 3.', 'Look at the inside numbers: 3 × 2 times 3 × 2. Do 2 and 3 match?']),+ }, {+ id: 'c-size', prompt: ['A is 2 × 3 and B is 3 × 4.'],+ build: blanks([{ parts: ['AB is ', { box: '2' }, ' × ', { box: '4' }], why: 'Inside 3 and 3 match; outside 2 and 4 give the size.', hint: 'Rows from A, columns from B.' }]),+ }], done) }],++ ['wrap', 'Summary', (m) => {+ const p = panel(0);+ [['A B = A times each column of B: column j of AB is A times column j of B.', 'w1'], ['Each column of AB mixes the columns of A: A carries B’s columns to AB’s.', 'w2'],+ ['Entry (i, j) of AB is row i of A times column j of B.', 'w3'], ['(m × n)(n × p) = m × p: the inside numbers must match.', '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, COLQ.map((q, k) => ({+ id: `p-col${k + 1}`, prompt: ['Work out AB one column at a time. ', ...pairEl(q.A, q.B)],+ build: blanks(colRows(q)),+ })), done, 'Chapter practice · set 1 of 4') }],+ ['final2', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [...ENTQ.map((q, k) => ({+ id: `p-ent${k + 1}`, prompt: ['Each entry: a row of A times a column of B. ', ...pairEl(q.A, q.B)],+ build: blanks(entRows(q)),+ })), {+ id: 'p-ent4', prompt: ['Just one entry. ', ...pairEl([[5, 1], [2, 3]], [[1, 7], [4, 2]])],+ build: blanks([{ parts: ['entry (2, 1) of AB = ', { box: '14' }], why: 'Row 2 of A times column 1 of B: 2·1 + 3·4 = 2 + 12 = 14.', hint: 'Entry (2, 1): row 2 of A, column 1 of B.' }]),+ }, {+ id: 'p-ent5', prompt: ['A 1 × 2 times a 2 × 3. ', ...pairEl([[1, 1]], [[1, 2, 3], [4, 5, 6]])],+ build: blanks([{ parts: ['AB = (', { box: '5' }, ', ', { box: '7' }, ', ', { box: '9' }, ')'], why: '(1, 1) times each column adds its two numbers: 1 + 4, 2 + 5, 3 + 6.', hint: 'AB is 1 × 3: one row, three entries, each row 1 of A times a column of B.' }]),+ }], done, 'Chapter practice · set 2 of 4') }],+ ['final3', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{+ id: 'p-fit', prompt: ['Is the product defined?'],+ build: grid(FITQ, [['y', 'Yes', COL.good, 'Y'], ['n', 'No', COL.bad, 'N']], { multi: false, text: true }),+ }, {+ id: 'p-size', prompt: ['How big is the answer?'],+ build: blanks(SIZEQ),+ }], done, 'Chapter practice · set 3 of 4') }],+ ['final4', 'Chapter practice', () => {+ const p = panel(0);+ title(p, 'Hit the targets');+ const t = pair(p, HANDS[0].A, HANDS[0].B, { col: 0 });+ S.P = t.P; S.g = t.g; S.tg = G(p, {});+ }, { ask: done => quiz(CARD, HANDS.map((h, k) => ({+ id: `p-hand${k + 1}`, prompt: [h.prompt],+ build: (body, api) => {+ const B = h.B, A = h.A;+ S.P.set({ a00: A[0][0], a01: A[0][1], a10: A[1][0], a11: A[1][1], b00: B[0][0], b01: B[0][1], b10: B[1][0], b11: B[1][1] });+ S.tg.replaceChildren();+ if (h.tgt) { target(S.g.P, h.tgt, S.tg, 0); put(S.tg.lastChild, { o: 1 }); }+ const only = h.tgt ? [`b0${h.col}`, `b1${h.col}`] : ['a00', 'a01', 'a10', 'a11'];+ S.P.show('cols', h.col, 0);+ const test = h.tgt ? (v, C) => C[0][h.col] === h.tgt[0] && C[1][h.col] === h.tgt[1] : (v, C) => C[0][0] === 2 && C[0][1] === 1 && C[1][0] === 1 && C[1][1] === 2;+ const hint = h.tgt ? (v, C) => `Column ${h.col + 1} of AB is (${num(Math.round(C[0][h.col] * 10) / 10)}, ${num(Math.round(C[1][h.col] * 10) / 10)}). Which mix of A’s columns gives (${num(h.tgt[0])}, ${num(h.tgt[1])})?`+ : (v, C) => `AB is [${num(C[0][0])} ${num(C[0][1])}; ${num(C[1][0])} ${num(C[1][1])}]. With B = I, AB is just A.`;+ return mmTask(S.P, test, h.why, hint, () => S.P.set(h.ans), { only })(body, api);+ },+ })), done, 'Chapter practice · set 4 of 4') }],+ ['play', 'Playground', (m, D) => {+ const p = panel(0);+ title(p, 'Playground');+ const t = pair(p, A1, B1);+ S.P = t.P;+ const hint = text(p, 'try: B = the identity · two equal columns in B · a size of 3', 70, 170, m('go'), { size: 24, fill: COL.dim });+ hide(hint, Math.min(m('go') + 9, D - .7), .6);+ }, { ask: playAsk(() => S.P, { pos: { ...CARD, y: 470 }, live: { sizes: true }, tip: 'Your A and B. Change any number or size, drag the ring x or the arrows, 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/ch24/audio/en/columns.mp3 b/site/linear-algebra/ch24/audio/en/columns.mp3new file mode 100644index 0000000..357401bBinary files /dev/null and b/site/linear-algebra/ch24/audio/en/columns.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/entries.mp3 b/site/linear-algebra/ch24/audio/en/entries.mp3new file mode 100644index 0000000..0822221Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/entries.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/final1.mp3 b/site/linear-algebra/ch24/audio/en/final1.mp3new file mode 100644index 0000000..95795c2Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/final1.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/final2.mp3 b/site/linear-algebra/ch24/audio/en/final2.mp3new file mode 100644index 0000000..e5a94d4Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/final2.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/final3.mp3 b/site/linear-algebra/ch24/audio/en/final3.mp3new file mode 100644index 0000000..1353cd5Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/final3.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/final4.mp3 b/site/linear-algebra/ch24/audio/en/final4.mp3new file mode 100644index 0000000..182e5c1Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/final4.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/finish.mp3 b/site/linear-algebra/ch24/audio/en/finish.mp3new file mode 100644index 0000000..75a90a6Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/finish.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/handy.mp3 b/site/linear-algebra/ch24/audio/en/handy.mp3new file mode 100644index 0000000..803e77eBinary files /dev/null and b/site/linear-algebra/ch24/audio/en/handy.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/intro.mp3 b/site/linear-algebra/ch24/audio/en/intro.mp3new file mode 100644index 0000000..baa4eeaBinary files /dev/null and b/site/linear-algebra/ch24/audio/en/intro.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/outer.mp3 b/site/linear-algebra/ch24/audio/en/outer.mp3new file mode 100644index 0000000..b065c2fBinary files /dev/null and b/site/linear-algebra/ch24/audio/en/outer.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/outer2.mp3 b/site/linear-algebra/ch24/audio/en/outer2.mp3new file mode 100644index 0000000..4c543e8Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/outer2.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/pair.mp3 b/site/linear-algebra/ch24/audio/en/pair.mp3new file mode 100644index 0000000..f34ffccBinary files /dev/null and b/site/linear-algebra/ch24/audio/en/pair.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/play.mp3 b/site/linear-algebra/ch24/audio/en/play.mp3new file mode 100644index 0000000..ebd139dBinary files /dev/null and b/site/linear-algebra/ch24/audio/en/play.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/q1.mp3 b/site/linear-algebra/ch24/audio/en/q1.mp3new file mode 100644index 0000000..3737d10Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/q1.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/q2.mp3 b/site/linear-algebra/ch24/audio/en/q2.mp3new file mode 100644index 0000000..4c87ad7Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/q2.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/q3.mp3 b/site/linear-algebra/ch24/audio/en/q3.mp3new file mode 100644index 0000000..a792b24Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/q3.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/rows.mp3 b/site/linear-algebra/ch24/audio/en/rows.mp3new file mode 100644index 0000000..7c6c7d6Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/rows.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/rows2.mp3 b/site/linear-algebra/ch24/audio/en/rows2.mp3new file mode 100644index 0000000..f7bd7bdBinary files /dev/null and b/site/linear-algebra/ch24/audio/en/rows2.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/timings.js b/site/linear-algebra/ch24/audio/en/timings.jsnew file mode 100644index 0000000..57fd2d8--- /dev/null+++ b/site/linear-algebra/ch24/audio/en/timings.js@@ -0,0 +1,650 @@+window.TIMINGS = {+ "intro": {+ "dur": 12.408,+ "marks": {+ "sub": 3.294,+ "move": 7.292+ },+ "cues": [+ [+ 0.104,+ "Chapter twenty-four."+ ],+ [+ 1.706,+ "Four ways to multiply."+ ],+ [+ 3.294,+ "One product, A times B, worked out four different ways."+ ],+ [+ 7.292,+ "Every way gives the same answer, and each one is handy for something."+ ]+ ]+ },+ "pair": {+ "dur": 30.336,+ "marks": {+ "A": 2.812,+ "B": 5.352,+ "ab": 8.763,+ "w1": 13.151,+ "w2": 18.008,+ "last": 21.302,+ "w3": 23.763,+ "w4": 26.003+ },+ "cues": [+ [+ 0.117,+ "Here is the pair we'll use all chapter."+ ],+ [+ 2.812,+ "A is two, one, and one, one."+ ],+ [+ 5.352,+ "B is one, minus one, and two, one."+ ],+ [+ 8.763,+ "A B is four, minus one, and three, zero."+ ],+ [+ 13.151,+ "The first way: one entry at a time, a row of A times a column of B."+ ],+ [+ 18.008,+ "The second way: A times each column of B."+ ],+ [+ 21.302,+ "Those two we met in chapter twenty-three."+ ],+ [+ 23.763,+ "The third way goes by rows, and the fourth way adds up whole pieces, a column times a row."+ ]+ ]+ },+ "entries": {+ "dur": 40.032,+ "marks": {+ "e11": 2.096,+ "e12": 9.714,+ "e21": 18.021,+ "e22": 23.724,+ "count": 30.143,+ "handy": 36.536+ },+ "cues": [+ [+ 0.104,+ "Way one: entries."+ ],+ [+ 2.096,+ "Row one of A times column one of B: two times one, plus one times two."+ ],+ [+ 7.5,+ "Two plus two is four."+ ],+ [+ 9.714,+ "Row one times column two: two times minus one, plus one times one."+ ],+ [+ 15.182,+ "Minus two plus one is minus one."+ ],+ [+ 18.021,+ "Row two times column one: one times one, plus one times two, is three."+ ],+ [+ 23.724,+ "Row two times column two: one times minus one, plus one times one, is zero."+ ],+ [+ 30.143,+ "Four entries, and each one needs two multiplications: eight multiplications in all."+ ],+ [+ 36.536,+ "This way is handy when you need just one number of A B."+ ]+ ]+ },+ "columns": {+ "dur": 40.2,+ "marks": {+ "c1": 1.628,+ "land1": 10.573,+ "c2": 15.156,+ "land2": 27.812,+ "mix": 31.38,+ "handy": 35.013+ },+ "cues": [+ [+ 0.104,+ "Way two: columns."+ ],+ [+ 1.628,+ "A times column one of B, one, two: one of column one of A, plus two of column two."+ ],+ [+ 7.461,+ "Two, one plus two, two is four, three."+ ],+ [+ 10.573,+ "In the picture, A carries the point one, two to four, three."+ ],+ [+ 15.156,+ "A times column two of B, minus one, one: minus one of column one, plus one of column two."+ ],+ [+ 22.565,+ "Minus two, minus one, plus one, one is minus one, zero."+ ],+ [+ 27.812,+ "The point minus one, one lands on minus one, zero."+ ],+ [+ 31.38,+ "So every column of A B is a mix of the columns of A."+ ],+ [+ 35.013,+ "This way is handy when you want to see what A does: it moves each column of B."+ ]+ ]+ },+ "q1": {+ "dur": 3.432,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.094,+ "One entry, and one whole column."+ ]+ ]+ },+ "rows": {+ "dur": 45.504,+ "marks": {+ "turn": 2.292,+ "r1": 4.883,+ "m1": 11.823,+ "s1": 16.667,+ "pic1": 20.234,+ "r2": 31.94,+ "s2": 36.38,+ "mix": 42.188+ },+ "cues": [+ [+ 0.104,+ "Way three: rows."+ ],+ [+ 2.292,+ "Now each row of A works on all of B."+ ],+ [+ 4.883,+ "Row one of A is two, one."+ ],+ [+ 7.161,+ "It says: take two of row one of B, plus one of row two of B."+ ],+ [+ 11.823,+ "Two times one, minus one is two, minus two."+ ],+ [+ 15.43,+ "Plus two, one."+ ],+ [+ 16.667,+ "That's four, minus one: row one of A B."+ ],+ [+ 20.234,+ "In the picture, the arrows are now the rows of B: blue for row one, coral for row two."+ ],+ [+ 26.992,+ "Two blue steps and one coral step land on four, minus one."+ ],+ [+ 31.94,+ "Row two of A is one, one: one of each row of B."+ ],+ [+ 36.38,+ "One, minus one plus two, one is three, zero: row two of A B."+ ],+ [+ 42.188,+ "So every row of A B is a mix of the rows of B."+ ]+ ]+ },+ "rows2": {+ "dur": 39.624,+ "marks": {+ "E": 1.667,+ "sys": 6.576,+ "r1": 13.971,+ "r2": 18.385,+ "s2": 24.883,+ "step": 30.964,+ "handy": 36.094+ },+ "cues": [+ [+ 0.104,+ "We have seen this before."+ ],+ [+ 1.667,+ "In chapter twenty-one, a matrix E on the left mixed the rows."+ ],+ [+ 6.576,+ "E is one, zero, and minus three, one."+ ],+ [+ 10.651,+ "A is one, two, and three, four."+ ],+ [+ 13.971,+ "Row one of E is one, zero: just row one of A, one, two."+ ],+ [+ 18.385,+ "Row two of E is minus three, one: minus three times row one, plus row two."+ ],+ [+ 24.883,+ "Minus three, minus six, plus three, four is zero, minus two."+ ],+ [+ 30.964,+ "That's the elimination step: row two minus three times row one."+ ],+ [+ 36.094,+ "So the row way is the one to use for elimination."+ ]+ ]+ },+ "q2": {+ "dur": 5.136,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Your turn."+ ],+ [+ 1.042,+ "Change row two of A until row two of A B lands on the target."+ ]+ ]+ },+ "outer": {+ "dur": 62.448,+ "marks": {+ "cr": 4.466,+ "sz": 8.737,+ "each": 16.458,+ "look": 27.174,+ "pair": 35.742,+ "p1": 36.953,+ "p2": 41.172,+ "sum": 47.044,+ "same": 57.734+ },+ "cues": [+ [+ 0.104,+ "Way four is the surprise."+ ],+ [+ 2.318,+ "First, a column times a row."+ ],+ [+ 4.466,+ "Take the column two, one, and the row one, minus one."+ ],+ [+ 8.737,+ "That's two by one, times one by two."+ ],+ [+ 11.419,+ "The inside numbers are one and one: they match."+ ],+ [+ 14.805,+ "The answer is two by two."+ ],+ [+ 16.458,+ "Each entry is a single product: two times one is two, two times minus one is minus two, one times one is one, one times minus one is minus one."+ ],+ [+ 27.174,+ "Look at the rows: two, minus two is just two times one, minus one."+ ],+ [+ 32.734,+ "Every row is a multiple of the same row."+ ],+ [+ 35.742,+ "Now our pair."+ ],+ [+ 36.953,+ "Column one of A times row one of B: that's the piece we just made."+ ],+ [+ 41.172,+ "Column two of A, one, one, times row two of B, two, one: two, one, and two, one."+ ],+ [+ 47.044,+ "Add the two pieces: two plus two is four, minus two plus one is minus one, one plus two is three, minus one plus one is zero."+ ],+ [+ 57.734,+ "Four, minus one, three, zero."+ ],+ [+ 60.703,+ "The same A B again."+ ]+ ]+ },+ "outer2": {+ "dur": 32.472,+ "marks": {+ "p1": 7.8,+ "p2": 14.896,+ "sum": 23.919,+ "same": 28.62+ },+ "cues": [+ [+ 0.091,+ "Once more, with chapter twenty-three's bigger pair: one, two, three, four times five, six, seven, eight."+ ],+ [+ 7.8,+ "Column one of A, one, three, times row one of B, five, six: five, six, and fifteen, eighteen."+ ],+ [+ 14.896,+ "Column two, two, four, times row two, seven, eight: fourteen, sixteen, and twenty-eight, thirty-two."+ ],+ [+ 23.919,+ "Add them: nineteen, twenty-two, forty-three, fifty."+ ],+ [+ 28.62,+ "Exactly what we got entry by entry in chapter twenty-three."+ ]+ ]+ },+ "why": {+ "dur": 32.784,+ "marks": {+ "table": 1.784,+ "eight": 8.398,+ "e": 9.753,+ "c": 12.331,+ "r": 14.857,+ "g": 17.292,+ "v": 22.513,+ "same": 26.823+ },+ "cues": [+ [+ 0.104,+ "Why do all four ways agree?"+ ],+ [+ 1.784,+ "Here is every entry of A B, written out: each one is a sum of two products."+ ],+ [+ 8.398,+ "Eight products in all."+ ],+ [+ 9.753,+ "Way one adds them up one entry at a time."+ ],+ [+ 12.331,+ "Way two takes a whole column at once."+ ],+ [+ 14.857,+ "Way three takes a whole row at once."+ ],+ [+ 17.292,+ "Way four collects all the first products, the green ones: that's the first piece."+ ],+ [+ 22.513,+ "And all the second products, the violet ones: the second piece."+ ],+ [+ 26.823,+ "It's always the same eight products."+ ],+ [+ 28.88,+ "Only the order of adding changes, so the answer can't change."+ ]+ ]+ },+ "q3": {+ "dur": 3.912,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.042,+ "Build A B from two pieces."+ ]+ ]+ },+ "handy": {+ "dur": 24.624,+ "marks": {+ "one": 1.771,+ "two": 5.664,+ "three": 9.818,+ "four": 15.065+ },+ "cues": [+ [+ 0.104,+ "So which way should you use?"+ ],+ [+ 1.771,+ "For one number: way one, a row times a column."+ ],+ [+ 5.664,+ "To see what A does to vectors: way two, by columns."+ ],+ [+ 9.818,+ "For elimination, where rows are mixed: way three, by rows."+ ],+ [+ 15.065,+ "And way four, columns times rows, splits a product into simple pieces, each with all its rows in step."+ ],+ [+ 22.578,+ "We'll need that much later in the course."+ ]+ ]+ },+ "wrap": {+ "dur": 31.128,+ "marks": {+ "w1": 1.016,+ "w2": 7.175,+ "w3": 13.281,+ "w4": 19.31,+ "end": 26.901+ },+ "cues": [+ [+ 0.104,+ "Let's sum up."+ ],+ [+ 1.016,+ "Entries: entry i, j is row i of A times column j of B."+ ],+ [+ 7.175,+ "Columns: each column of A B is A times a column of B, a mix of the columns of A."+ ],+ [+ 13.281,+ "Rows: each row of A B is a row of A times B, a mix of the rows of B."+ ],+ [+ 19.31,+ "Columns times rows: A B is column one times row one, plus column two times row two, and so on."+ ],+ [+ 26.901,+ "All four use the same products."+ ],+ [+ 28.932,+ "Now try the chapter practice."+ ]+ ]+ },+ "final1": {+ "dur": 3.624,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Chapter practice."+ ],+ [+ 1.51,+ "Work out A B by rows."+ ]+ ]+ },+ "final2": {+ "dur": 3.144,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Now in pieces: columns times rows."+ ]+ ]+ },+ "final3": {+ "dur": 1.872,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Which way is it?"+ ]+ ]+ },+ "final4": {+ "dur": 4.776,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Last set."+ ],+ [+ 1.185,+ "Move the rows of A in the picture to hit each target."+ ]+ ]+ },+ "play": {+ "dur": 10.104,+ "marks": {+ "go": 3.958+ },+ "cues": [+ [+ 0.091,+ "Playground."+ ],+ [+ 1.081,+ "Nothing here is marked right or wrong."+ ],+ [+ 3.958,+ "Change any number, drag the row arrows or the ring, and watch the rows of A B move."+ ]+ ]+ },+ "finish": {+ "dur": 11.4,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Well done."+ ],+ [+ 1.107,+ "That's the end of chapter twenty-four, four ways to multiply."+ ],+ [+ 5.3,+ "Next: the rules of matrix arithmetic, and why A B is usually not B A."+ ]+ ]+ }+};diff --git a/site/linear-algebra/ch24/audio/en/why.mp3 b/site/linear-algebra/ch24/audio/en/why.mp3new file mode 100644index 0000000..c44bd00Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/why.mp3 differdiff --git a/site/linear-algebra/ch24/audio/en/wrap.mp3 b/site/linear-algebra/ch24/audio/en/wrap.mp3new file mode 100644index 0000000..a4faa39Binary files /dev/null and b/site/linear-algebra/ch24/audio/en/wrap.mp3 differdiff --git a/site/linear-algebra/ch24/index.html b/site/linear-algebra/ch24/index.htmlnew file mode 100644index 0000000..808ef5b--- /dev/null+++ b/site/linear-algebra/ch24/index.html@@ -0,0 +1,405 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>Four Ways to Multiply</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/grid2.js"></script>+<script src="../lib/mm.js"></script>+<script src="../lib/play.js"></script>+<script src="audio/en/timings.js"></script>+<script>+'use strict';+const CHAPTER = { number: 24, title: 'Four Ways to Multiply', minutes: 10, language: 'en', next: '../ch25/' };++/* ---------- chapter drawing helpers ---------- */+const GREEN = MM_COL[0], VIOLET = MM_COL[1], BLUE = MM_ROW[0], CORAL = MM_ROW[1];+const A0 = [[2, 1], [1, 1]], B0 = [[1, -1], [2, 1]]; // the chapter's pair: AB = [[4, −1], [3, 0]]+const AT = [70, 260];+const PLANE = { cx: 1190, cy: 450, u: 50 };+const CARD = { x: 40, y: 610, w: 780, 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 = (e, t0, w = 5) => { tw(e, { 'a_stroke-width': w + 5 }, t0, .3); tw(e, { 'a_stroke-width': w }, t0 + 1.2, .6); };+// The column way's picture (chapter 23): A's columns as arrows, x = a column of B, Ax = that column of AB.+const colPic = (p, P_, col = 0, t0 = .1) => {+ const g = grid2(p, { A: [[P_.v.a00, P_.v.a01], [P_.v.a10, P_.v.a11]], x: [0, 0], mat: null, grid: false, square: false, units: false, brackets: true, plane: PLANE, t0 });+ g.labels(['col 1', 'col 2']);+ P_.link(g, { col, dots: true });+ return g;+};+// The row way's picture: the arrows are the rows of B (blue, coral), x = a row of A, Ax = that row of AB.+const rowPic = (p, P_, row = 0, t0 = .1) => {+ const g = grid2(p, { A: [[0, 0], [0, 0]], x: [0, 0], mat: null, grid: false, square: false, units: false, brackets: true, plane: PLANE, t0 });+ g.labels(['row 1 of B', 'row 2 of B']);+ [0, 1].forEach(j => {+ [g.cols[j], g.combo[j]].forEach(e => { e.setAttribute('stroke', MM_ROW[j]); e.setAttribute('fill', MM_ROW[j]); });+ g.tips[j]._ring.setAttribute('stroke', MM_ROW[j]);+ g.tipLabels[j].querySelectorAll('text, tspan').forEach(t => t.setAttribute('fill', MM_ROW[j]));+ });+ P_.link(g, { col: row, dots: true, rows: true });+ return g;+};+const target = (P2, [x, y], into, t0 = .3) => {+ const g = G(into, { x: P2.PX(x), y: P2.PY(y), o: 0 });+ mk('circle', { r: 17, fill: 'none', stroke: COL.task, 'stroke-width': 3, 'stroke-dasharray': '5 5' }, g);+ T(g, `target (${num(x)}, ${num(y)})`, { x: 22, y: 40, size: 22, fill: COL.task, font: MATH });+ show(g, t0, .4);+ return g;+};+// The four ways as a list, each line lit while the chapter is on it.+const WAYS = ['1 entries: a row times a column', '2 columns: A times each column of B', '3 rows: each row of A times B', '4 pieces: columns times rows, added'];+const waysList = (p, x, y, times, { size = 30 } = {}) => WAYS.map((s, k) => text(p, s, x, y + k * 52, times[k], { size, weight: 600 }));+const pairEl = (A, B) => ['A = ', mmEl(A), ' B = ', mmEl(B)];+const fac = v => v < 0 ? `(${num(v)})` : num(v);++/* ---------- practice data (every answer worked twice: by the asked way and entry by entry) ---------- */+const ROWQ = [+ { A: [[1, 2], [0, 1]], B: [[1, 1], [2, -1]], C: [[5, -1], [2, -1]] },+ { A: [[3, -1], [1, 1]], B: [[1, 0], [2, 2]], C: [[1, -2], [3, 2]] },+ { A: [[1, 0], [-2, 1]], B: [[2, 1], [4, 5]], C: [[2, 1], [0, 3]] },+ { A: [[1, 1], [2, 0]], B: [[1, 2, 3], [0, 1, -1]], C: [[1, 3, 2], [2, 4, 6]] },+];+const rowRows = ({ A, B, C }) => C.map((r, i) => ({+ parts: [`row ${i + 1} of AB = (`, ...r.flatMap((v, j) => [...(j ? [', '] : []), { box: String(v) }]), ')'],+ why: `${fac(A[i][0])}·(${B[0].map(num).join(', ')}) + ${fac(A[i][1])}·(${B[1].map(num).join(', ')}) = (${r.map(num).join(', ')}).`,+ hint: `Row ${i + 1} of A is (${A[i].map(num).join(', ')}): that much of row 1 of B, plus that much of row 2 of B.`,+}));+const PIECEQ = [+ { prompt: ['Column times row: ', mmEl([[2], [3]]), ' ', mmEl([[1, 4]])], rows: [+ { parts: ['row 1 = (', { box: '2' }, ', ', { box: '8' }, ')'], why: '2·1 = 2 and 2·4 = 8.', hint: 'Row 1: the top of the column, 2, times the row (1, 4).' },+ { parts: ['row 2 = (', { box: '3' }, ', ', { box: '12' }, ')'], why: '3·1 = 3 and 3·4 = 12: 3 times the same row.', hint: 'Row 2: 3 times the row (1, 4).' }] },+ { prompt: ['Column times row, 2 × 1 times 1 × 3: ', mmEl([[1], [-1]]), ' ', mmEl([[2, 1, 3]])], rows: [+ { parts: ['row 1 = (', { box: '2' }, ', ', { box: '1' }, ', ', { box: '3' }, ')'], why: '1 times the row.', hint: 'Each row is the top number of the column times (2, 1, 3).' },+ { parts: ['row 2 = (', { box: '-2' }, ', ', { box: '-1' }, ', ', { box: '-3' }, ')'], why: '−1 times the row: every sign flips.', hint: 'Row 2 is −1 times (2, 1, 3).' }] },+ { prompt: ['AB in pieces. ', ...pairEl([[1, 0], [2, 1]], [[3, 1], [1, 4]])], rows: [+ { parts: ['piece 1 = (column 1)(row 1) = [', { box: '3' }, ' ', { box: '1' }, '; ', { box: '6' }, ' ', { box: '2' }, ']'], why: '(1, 2) times (3, 1): rows (3, 1) and (6, 2).', hint: 'Column 1 of A is (1, 2); row 1 of B is (3, 1).' },+ { parts: ['piece 2 = (column 2)(row 2) = [', { box: '0' }, ' ', { box: '0' }, '; ', { box: '1' }, ' ', { box: '4' }, ']'], why: '(0, 1) times (1, 4): rows (0, 0) and (1, 4).', hint: 'Column 2 of A is (0, 1); row 2 of B is (1, 4).' },+ { parts: ['AB = [', { box: '3' }, ' ', { box: '1' }, '; ', { box: '7' }, ' ', { box: '6' }, ']'], why: 'The pieces added: [3 1; 7 6]. Entry by entry: 3 + 0, 1 + 0, 6 + 1, 2 + 4.', hint: 'Add the two pieces number by number.' }] },+ { prompt: ['Chapter 23’s first pair in pieces. ', ...pairEl([[2, 1], [1, 3]], [[1, 2], [1, -1]])], rows: [+ { parts: ['piece 1 = [', { box: '2' }, ' ', { box: '4' }, '; ', { box: '1' }, ' ', { box: '2' }, ']'], why: '(2, 1) times (1, 2).', hint: 'Column 1 of A times row 1 of B.' },+ { parts: ['piece 2 = [', { box: '1' }, ' ', { box: '-1' }, '; ', { box: '3' }, ' ', { box: '-3' }, ']'], why: '(1, 3) times (1, −1).', hint: 'Column 2 of A times row 2 of B.' },+ { parts: ['AB = [', { box: '3' }, ' ', { box: '3' }, '; ', { box: '4' }, ' ', { box: '-1' }, ']'], why: 'The same AB as in chapter 23.', hint: 'Add the two pieces.' }] },+];+const WAYQ = [+ ['1·5 + 2·7 = 19', 'e'], ['5·(column 1 of A) + 7·(column 2 of A)', 'c'], ['1·(row 1 of B) + 2·(row 2 of B)', 'r'],+ ['(column 1 of A)(row 1 of B) + (column 2 of A)(row 2 of B)', 'p'], ['row 2 of A times column 1 of B: one number', 'e'], ['row 2 of E mixes the rows of A (elimination)', 'r'],+].map(([s, k]) => ({ parts: [s], ans: [k], why: { e: 'One entry: a row times a column.', c: 'A mix of the columns of A: one column of AB.', r: 'A mix of the rows of the right matrix: one row of the answer.', p: 'Pieces added: columns times rows.' }[k] }));+const HANDS = [+ { A: [[0, 0], [1, 1]], B: [[1, -1], [2, 1]], row: 0, tgt: [3, 0], ans: { a00: 1, a01: 1 }, prompt: 'Move row 1 of A (the ring x, or its numbers) until row 1 of AB lands on the target.',+ why: 'Row 1 of A = (1, 1): (1, −1) + (2, 1) = (3, 0).' },+ { A: [[1, 0], [0, 0]], B: [[1, 0], [1, 1]], row: 1, tgt: [-1, 2], ans: { a10: -3, a11: 2 }, prompt: 'New rows of B. Make row 2 of AB land on the target.',+ why: 'Row 2 of A = (−3, 2): −3·(1, 0) + 2·(1, 1) = (−1, 2).' },+ { A: [[1, 0], [0, 1]], B: [[1, 0], [0, 1]], row: 0, tgt: null, ans: { b00: 1, b01: 2, b10: 3, b11: 1 }, prompt: 'A is the identity. Change B (its numbers, or drag the row arrows) until AB = [1 2; 3 1].',+ why: 'A = I, so each row of AB is just a row of B: B = [1 2; 3 1].' },+];++/* ---------- beats ---------- */+const BEATS = [+ ['intro', 'Four ways to multiply', (m, D) => {+ const g = G(scene, { o: 0, y: 24 });+ T(g, 'Unit 3, Chapter 24', { x: 800, y: 250, size: 28, fill: COL.dim, anchor: 'middle' });+ T(g, 'Four Ways to Multiply', { x: 800, y: 360, size: 88, weight: 600, anchor: 'middle' });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);+ const r = text(scene, 'one product, worked out four different ways', 800, 460, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });+ const lg = G(scene, { o: 0 });+ const P_ = mm(lg, { A: A0, B: B0, at: [560, 600], size: 36, cw: 56, sizes: false, t0: 0 });+ put(P_.W, { o: 0 });+ show(lg, m('sub') + 1, .5);+ P_.show('entry', [0, 0], m('move')); P_.show('cols', 1, m('move') + 1.2); P_.show('rows', 1, m('move') + 2.4); P_.show('outer', 0, m('move') + 3.6); P_.show(null, null, m('move') + 4.8);+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);+ }],++ ['pair', 'One pair', (m) => {+ const p = panel(0);+ title(p, 'One pair, four ways');+ const P_ = mm(p, { A: A0, B: B0, at: [90, 280], size: 46, cw: 70, rh: 68, hideC: true, t0: m('A') - .3 });+ put(P_.L.b.g, { o: 0 }); show(P_.L.b.g, m('B'), .5);+ P_.flash('a', 'all', m('A') + .4); P_.flash('b', 'all', m('B') + .4);+ P_.reveal('all', m('ab'));+ const ws = waysList(p, 860, 260, [m('w1'), m('w2'), m('w3'), m('w4')], { size: 32 });+ P_.show('entry', [0, 0], m('w1') + .2); P_.show('cols', 0, m('w2') + .2);+ text(p, 'ways 1 and 2: chapter 23', 860, 500, m('last'), { size: 24, fill: COL.dim, weight: 600 });+ P_.show('rows', 0, m('w3') + .2); P_.show('outer', 0, m('w4') + .2);+ P_.flash('a', { row: 0 }, m('w1') + 2); P_.flash('b', { col: 0 }, m('w1') + 3.5);+ P_.flash('a', { col: 0 }, m('w4') + 1.5); P_.flash('b', { row: 0 }, m('w4') + 2.5);+ [0, 1].forEach(k => tw(ws[k], { o: .45 }, m('w3'), .4));+ tw(ws[2], { o: .45 }, m('w4'), .4);+ }],++ ['entries', 'Way 1: entries', (m) => {+ const p = panel(0);+ title(p, 'Way 1: entries, a row times a column');+ const P_ = mm(p, { A: A0, B: B0, at: [90, 280], size: 46, cw: 70, rh: 68, hideC: true, t0: .1, wsize: 36 });+ [['e11', [0, 0]], ['e12', [0, 1]], ['e21', [1, 0]], ['e22', [1, 1]]].forEach(([k, c], i) => {+ const long = i < 2;+ P_.show('entry', c, m(k), { times: [m(k) + 1.5, m(k) + (long ? 5 : 4.6), m(k) + (long ? 6.4 : 5.4)] });+ P_.reveal({ cell: c }, m(k) + (long ? 6.4 : 5.4));+ });+ P_.flash('a', { row: 0 }, m('e11') + 2); P_.flash('b', { col: 0 }, m('e11') + 3.5);+ P_.flash('c', 'all', m('count') + 3);+ P_.show(null, null, m('count'));+ const cg = G(p, { o: 0 });+ M(cg, ['4 entries × 2 products = 8 multiplications'], { x: 90, y: 690, size: 36, anchor: 'start' });+ show(cg, m('count') + .3, .5);+ P_.flash('c', 'all', m('count') + .3);+ text(p, 'handy when you need just one number', 90, 780, m('handy'), { size: 30, fill: COL.dim, weight: 600 });+ P_.show('entry', [1, 0], m('handy') + .3);+ }],++ ['columns', 'Way 2: columns', (m) => {+ const p = panel(0);+ title(p, 'Way 2: A times each column of B');+ const P_ = mm(p, { A: A0, B: B0, at: AT, tintA: 'cols', hideC: true, t0: .1 });+ const g = colPic(p, P_, 0);+ P_.show('cols', 0, m('c1'), { times: [m('c1') + 1.5, m('c1') + 5, m('c1') + 6.3] });+ P_.reveal({ col: 0 }, m('c1') + 6.3);+ pulse(g.axDot, m('land1') + .3); thick(g.combo[0], m('land1') + 1, 4); thick(g.combo[1], m('land1') + 2, 4);+ P_.linkCol(1, m('c2'));+ P_.show('cols', 1, m('c2'), { times: [m('c2') + 1.8, m('c2') + 5.4, m('c2') + 7.4] });+ P_.reveal({ col: 1 }, m('c2') + 7.4);+ pulse(g.axDot, m('land2') + .3); P_.flash('c', { col: 1 }, m('land2') + 1.2);+ P_.flash('a', { col: 0 }, m('c2') + 4); P_.flash('a', { col: 1 }, m('c2') + 7);+ P_.flash('a', { col: 0 }, m('mix') + .5); P_.flash('a', { col: 1 }, m('mix') + 1.5); P_.flash('c', 'all', m('mix') + 2.5);+ text(p, 'handy to see what A does: it moves each column of B', 70, 740, m('handy'), { size: 28, fill: COL.dim, weight: 600 });+ P_.linkCol(0, m('handy') + 2.5);+ }],++ ['q1', 'Quick check', () => {+ const p = panel(0);+ title(p, 'Quick check');+ S.P = mm(p, { A: [[1, 3], [2, 1]], B: [[2, 0], [1, 1]], at: [90, 280], size: 46, cw: 70, rh: 68, hideC: true });+ }, { ask: done => quiz({ x: 40, y: 480, w: 800, cls: 'side' }, [{+ id: 'c-two', prompt: ['Use way 1 for one number, way 2 for a whole column.'],+ build: blanks([+ { parts: ['entry (2, 1) of AB = ', { box: '5' }], why: 'Row 2 of A times column 1 of B: 2·2 + 1·1 = 5.', hint: 'Row 2 of A is (2, 1); column 1 of B is (2, 1).',+ fx: () => fxp(q => { if (q > 0) S.P.uncover({ cell: [1, 0] }); }, 0, .1) },+ { parts: ['column 2 of AB = (', { box: '3' }, ', ', { box: '1' }, ')'], why: '0·(1, 2) + 1·(3, 1) = (3, 1).', hint: 'Column 2 of B is (0, 1): none of column 1 of A, one of column 2.',+ fx: () => fxp(q => { if (q > 0) S.P.uncover({ col: 1 }); }, 0, .1) },+ ]),+ }], done) }],++ ['rows', 'Way 3: rows', (m) => {+ const p = panel(0);+ title(p, 'Way 3: each row of A times B');+ const P_ = mm(p, { A: A0, B: B0, at: AT, tintB: 'rows', hideC: true, t0: .1 });+ const g = rowPic(p, P_, 0);+ put(g.parts.cols, { o: 0 }); put(g.parts.x, { o: 0 });+ show(g.parts.cols, m('pic1'), .5); show(g.parts.x, m('pic1') + 2, .5);+ P_.flash('a', { row: 0 }, m('turn')); P_.flash('b', 'all', m('turn') + 1.2);+ P_.show('rows', 0, m('r1'), { times: [m('r1') + 1.5, m('m1'), m('s1')] });+ P_.flash('b', { row: 0 }, m('r1') + 2.5); P_.flash('b', { row: 1 }, m('r1') + 4.2);+ P_.reveal({ row: 0 }, m('s1') + .3);+ P_.flash('b', { row: 0 }, m('m1') + .5); P_.flash('b', { row: 1 }, m('m1') + 3);+ thick(g.cols[0], m('pic1') + 3); thick(g.cols[1], m('pic1') + 4.6); pulse(g.axDot, m('pic1') + 7.5);+ P_.linkCol(1, m('r2'));+ P_.show('rows', 1, m('r2'), { times: [m('r2') + 1.2, m('s2'), m('s2') + 2.4] });+ P_.reveal({ row: 1 }, m('s2') + 2.4);+ pulse(g.axDot, m('s2') + 2.6);+ P_.flash('b', { row: 0 }, m('mix') + .6); P_.flash('b', { row: 1 }, m('mix') + 1.4); P_.flash('c', 'all', m('mix') + 2.3);+ }],++ ['rows2', 'Elimination is the row way', (m) => {+ const p = panel(0);+ title(p, 'The row way is elimination');+ const P_ = mm(p, { A: [[1, 0], [-3, 1]], B: [[1, 2], [3, 4]], names: ['E', 'A', 'EA'], at: AT, tintB: 'rows', hideC: true, t0: m('sys') - .3 });+ const g = rowPic(p, P_, 0, m('sys') - .3);+ text(p, 'chapter 21: numbers on the left mix the rows', 70, 180, m('E'), { size: 26, fill: COL.dim, weight: 600 });+ P_.flash('a', 'all', m('sys') + .3); P_.flash('b', 'all', m('sys') + 3);+ P_.show('rows', 0, m('r1'), { times: [m('r1') + 1.5, m('r1') + 2.5, m('r1') + 3.6] });+ P_.reveal({ row: 0 }, m('r1') + 3.6);+ P_.linkCol(1, m('r2'));+ P_.show('rows', 1, m('r2'), { times: [m('r2') + 1.6, m('s2'), m('s2') + 3] });+ P_.reveal({ row: 1 }, m('s2') + 3);+ pulse(g.axDot, m('s2') + 3.2);+ P_.flash('b', { row: 0 }, m('r2') + 2.5); P_.flash('b', { row: 1 }, m('r2') + 4.5);+ P_.flash('a', { row: 1 }, m('step') + 1.5); P_.flash('c', { row: 1 }, m('step') + 3); P_.flash('a', 'all', m('handy') + 1);+ const st = G(p, { o: 0 });+ M(st, ['row 2'], { x: 70, y: 740, size: 34, fill: CORAL, anchor: 'start' }); M(st, ['− 3 ×'], { x: 180, y: 740, size: 34, anchor: 'start' }); M(st, ['row 1'], { x: 290, y: 740, size: 34, fill: BLUE, anchor: 'start' });+ show(st, m('step'), .5);+ text(p, 'elimination mixes rows: use the row way', 70, 800, m('handy'), { size: 28, fill: COL.dim, weight: 600 });+ }],++ ['q2', 'Your turn', () => {+ const p = panel(0);+ title(p, 'Your turn');+ S.P = mm(p, { A: [[2, 1], [0, 0]], B: B0, at: AT, tintB: 'rows' });+ S.g = rowPic(p, S.P, 1);+ target(S.g.P, [5, -2], p, .3);+ S.P.show('rows', 1, .4);+ }, { ask: done => quiz(CARD, [{+ id: 'c-row', prompt: ['Change row 2 of A (drag the ring x, or its numbers) until row 2 of AB lands on the target.'],+ build: mmTask(S.P, (v, C) => C[1][0] === 5 && C[1][1] === -2, 'Row 2 of A = (3, 1): 3·(1, −1) + 1·(2, 1) = (5, −2).',+ (v, C) => `Row 2 of AB is (${num(Math.round(C[1][0] * 10) / 10)}, ${num(Math.round(C[1][1] * 10) / 10)}): ${num(Math.round(v.a10))} of the blue row plus ${num(Math.round(v.a11))} of the coral row.`,+ () => S.P.set({ a10: 3, a11: 1 }), { only: ['a10', 'a11'] }),+ }], done) }],++ ['outer', 'Way 4: columns times rows', (m) => {+ const p = panel(0);+ title(p, 'Way 4: a column times a row');+ const one = G(p, {});+ const Q = mm(one, { A: [[2], [1]], B: [[1, -1]], at: [90, 270], tintA: 'cols', tintB: 'rows', t0: m('cr') - .3, hideC: true });+ Q.flash('a', 'all', m('cr') + 1); Q.flash('b', 'all', m('cr') + 2.5);+ Q.inner(m('sz') + 2);+ Q.outer(m('sz') + 4.5);+ [[0, 0], [0, 1], [1, 0], [1, 1]].forEach((c, k) => Q.reveal({ cell: c }, m('each') + 1.2 + k * 2.2));+ Q.flash('c', { row: 0 }, m('look') + .5); Q.flash('c', { row: 1 }, m('look') + 1.7);+ say(one, ['every row a multiple of (1, −1)'], 90, 520, m('look') + 3, { size: 32 });+ Q.flash('c', { row: 0 }, m('look') + 5.5); Q.flash('c', { row: 1 }, m('look') + 6.5); Q.flash('b', 'all', m('look') + 7.5);+ hide(one, m('pair'), .5);+ const two = G(p, { o: 0 }); show(two, m('pair') + .3, .5);+ const P_ = mm(two, { A: A0, B: B0, at: AT, tintA: 'cols', tintB: 'rows', hideC: true, t0: 0 });+ P_.show('outer', 0, m('p1'), { times: [m('p1'), m('p1') + 3] });+ P_.show('outer', 1, m('p2'), { times: [m('p2'), m('p2') + 5] });+ P_.flash('a', { col: 0 }, m('p1') + .5); P_.flash('b', { row: 0 }, m('p1') + 1.5); P_.flash('a', { col: 1 }, m('p2') + .5); P_.flash('b', { row: 1 }, m('p2') + 2.5);+ P_.show('sum', null, m('sum'), { times: [m('sum'), m('sum') + 1.2] });+ [[0, 0], [0, 1], [1, 0], [1, 1]].forEach((c, k) => P_.reveal({ cell: c }, m('sum') + 2.5 + k * 2.4));+ P_.flash('c', 'all', m('same'));+ text(two, 'AB = (column 1)(row 1) + (column 2)(row 2)', 860, 300, m('sum') + .5, { size: 30, weight: 600 });+ }],++ ['outer2', 'Pieces again', (m) => {+ const p = panel(0);+ title(p, 'Pieces, with bigger numbers');+ const P_ = mm(p, { A: [[1, 2], [3, 4]], B: [[5, 6], [7, 8]], at: AT, tintA: 'cols', tintB: 'rows', hideC: true, t0: .1 });+ P_.flash('a', 'all', 2); P_.flash('b', 'all', 4.5);+ P_.show('outer', 0, m('p1'), { times: [m('p1'), m('p1') + 4.5] });+ P_.flash('a', { col: 0 }, m('p1') + 1); P_.flash('b', { row: 0 }, m('p1') + 3);+ P_.show('outer', 1, m('p2'), { times: [m('p2'), m('p2') + 4.5] });+ P_.flash('a', { col: 1 }, m('p2') + 1); P_.flash('b', { row: 1 }, m('p2') + 3);+ P_.show('sum', null, m('sum'), { times: [m('sum'), m('sum') + 1.5] });+ P_.reveal('all', m('sum') + 2.5);+ P_.flash('c', 'all', m('same'));+ text(p, 'chapter 23, entry by entry: [19 22; 43 50]', 70, 760, m('same') + .3, { size: 28, fill: COL.dim, weight: 600 });+ }],++ ['why', 'Why they agree', (m) => {+ const p = panel(0);+ title(p, 'The same eight products');+ const x0 = 340, cw = 420, y0 = 330, rh = 120, sz = 48;+ const tg = G(p, { o: 0 }); show(tg, m('table'), .5);+ path(tg, `M${x0 + 20} ${y0 - 70}H${x0}V${y0 + rh + 40}H${x0 + 20}M${x0 + 2 * cw - 20} ${y0 - 70}H${x0 + 2 * cw}V${y0 + rh + 40}H${x0 + 2 * cw - 20}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });+ T(tg, 'AB', { x: x0 + cw, y: y0 - 90, size: 30, fill: COL.dim, font: MATH, anchor: 'middle' });+ const terms = [[0, 0], [0, 1], [1, 0], [1, 1]].map(([i, j]) => {+ const cx = x0 + cw * (j + .5), y = y0 + rh * i;+ const t1 = M(tg, [`${fac(A0[i][0])}·${fac(B0[0][j])}`], { x: cx - 18, y, size: sz, fill: GREEN, anchor: 'end' });+ M(tg, ['+'], { x: cx, y, size: sz, anchor: 'middle' });+ const t2 = M(tg, [`${fac(A0[i][1])}·${fac(B0[1][j])}`], { x: cx + 18, y, size: sz, fill: VIOLET, anchor: 'start' });+ return { t1, t2, cx, y };+ });+ const eight = text(p, '8 products', 1340, 330, m('eight'), { size: 34, weight: 600 });+ const box = (x, y, w, h, t0, t1, color = COL.chalk) => { const r = mk('rect', { x, y, width: w, height: h, rx: 16, fill: color, 'fill-opacity': .1, stroke: color, 'stroke-width': 3 }, p); put(r, { o: 0 }); show(r, t0, .3); hide(r, t1, .3); };+ terms.forEach((t, k) => [t.t1, t.t2].forEach(e => pulse(e, m('eight') + .3 + k * .5)));+ terms.forEach((t, k) => pulse(t.t1, m('table') + 2 + k * .9));+ terms.forEach(t => pulse(t.t1, m('g') + 3));+ terms.forEach((t, k) => [t.t1, t.t2].forEach(e => pulse(e, m('same') + 2 + k * .4)));+ box(x0 + 10, y0 - 50, cw - 20, 70, m('e'), m('c'));+ box(x0 + 10, y0 - 54, cw - 20, rh + 80, m('c'), m('r'));+ box(x0 + 10, y0 - 50, 2 * cw - 20, 70, m('r'), m('g'));+ const lab = (s, t0, t1) => { const e = text(p, s, x0, y0 + rh + 130, t0, { size: 30, weight: 600 }); hide(e, t1, .3); };+ lab('way 1: one entry', m('e'), m('c')); lab('way 2: one column', m('c'), m('r')); lab('way 3: one row', m('r'), m('g'));+ lab('way 4: all the green products = piece 1', m('g'), m('v')); const lv = text(p, '… all the violet products = piece 2', x0, y0 + rh + 130, m('v'), { size: 30, weight: 600 });+ terms.forEach(t => { pulse(t.t1, m('g') + .4); pulse(t.t2, m('v') + .4); });+ terms.forEach(t => { tw(t.t2, { o: .3 }, m('g'), .3); tw(t.t2, { o: 1 }, m('v'), .3); tw(t.t1, { o: .3 }, m('v'), .3); tw(t.t1, { o: 1 }, m('same'), .3); });+ text(p, 'only the order of adding changes', x0, y0 + rh + 190, m('same') + .5, { size: 30, fill: COL.dim, weight: 600 });+ }],++ ['q3', 'Quick check', () => {+ const p = panel(0);+ title(p, 'Quick check');+ S.P = mm(p, { A: [[1, 2], [0, 1]], B: [[3, 1], [1, 2]], at: [90, 250], tintA: 'cols', tintB: 'rows', hideC: true });+ }, { ask: done => quiz({ x: 40, y: 400, w: 860, cls: 'side' }, [{+ id: 'c-pieces', prompt: ['AB as two pieces: column 1 of A times row 1 of B, plus column 2 times row 2.'],+ build: blanks([+ { parts: ['piece 1 = [', { box: '3' }, ' ', { box: '1' }, '; ', { box: '0' }, ' ', { box: '0' }, ']'], why: '(1, 0) times (3, 1): rows (3, 1) and (0, 0).', hint: 'Column 1 of A is (1, 0); row 1 of B is (3, 1).' },+ { parts: ['piece 2 = [', { box: '2' }, ' ', { box: '4' }, '; ', { box: '1' }, ' ', { box: '2' }, ']'], why: '(2, 1) times (1, 2): rows (2, 4) and (1, 2).', hint: 'Column 2 of A is (2, 1); row 2 of B is (1, 2).' },+ { parts: ['AB = [', { box: '5' }, ' ', { box: '5' }, '; ', { box: '1' }, ' ', { box: '2' }, ']'], why: 'The pieces added; the same as chapter 23’s quick check.', hint: 'Add the pieces number by number.',+ fx: () => fxp(q => { if (q > 0) S.P.uncover('all'); }, 0, .1) },+ ]),+ }], done) }],++ ['handy', 'Which way when', (m) => {+ const p = panel(0);+ title(p, 'Which way, when?');+ [['one', '1 entries', 'you need one number of AB'], ['two', '2 columns', 'to see what A does to vectors (the picture)'],+ ['three', '3 rows', 'elimination: rows are mixed'], ['four', '4 pieces', 'splitting AB into simple pieces (later in the course)']].forEach(([k, a, b], i) => {+ text(p, a, 90, 240 + i * 120, m(k), { size: 38, weight: 600 });+ text(p, b, 420, 240 + i * 120, m(k) + .4, { size: 32, fill: COL.dim, weight: 600 });+ });+ const P_ = mm(p, { A: A0, B: B0, at: [1000, 760], size: 30, cw: 46, rh: 44, sizes: false, t0: m('one') });+ put(P_.W, { o: 0 });+ P_.show('entry', [0, 0], m('one')); P_.show('cols', 0, m('two')); P_.show('rows', 0, m('three')); P_.show('outer', 0, m('four') + .5); P_.show('outer', 1, m('four') + 3.5); P_.show(null, null, m('four') + 6.5);+ P_.flash('c', 'all', m('four') + 7);+ }],++ ['wrap', 'Summary', (m) => {+ const p = panel(0);+ [['Entries: entry (i, j) = row i of A times column j of B.', 'w1'], ['Columns: column j of AB = A times column j of B, a mix of A’s columns.', 'w2'],+ ['Rows: row i of AB = row i of A times B, a mix of B’s rows.', 'w3'], ['Pieces: AB = (column 1)(row 1) + (column 2)(row 2) + …', '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, ROWQ.map((q, k) => ({+ id: `p-row${k + 1}`, prompt: ['Work out AB by rows: each row of A mixes the rows of B. ', ...pairEl(q.A, q.B)],+ build: blanks(rowRows(q)),+ })), done, 'Chapter practice · set 1 of 4') }],+ ['final2', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, PIECEQ.map((q, k) => ({+ id: `p-piece${k + 1}`, prompt: q.prompt, build: blanks(q.rows),+ })), done, 'Chapter practice · set 2 of 4') }],+ ['final3', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{+ id: 'p-way', prompt: ['Which way is each working?'],+ build: grid(WAYQ, [['e', 'Entries', COL.chalk, 'E'], ['c', 'Columns', GREEN, 'C'], ['r', 'Rows', BLUE, 'R'], ['p', 'Pieces', COL.rat, 'P']], { multi: false, text: true }),+ }, {+ id: 'p-count', prompt: ['A is 3 × 2 and B is 2 × 4.'],+ build: blanks([+ { parts: ['AB is the sum of ', { box: '2' }, ' pieces (column times row)'], why: 'One piece for each column of A (and row of B): 2.', hint: 'Column k of A goes with row k of B. How many columns has A?' },+ { parts: ['each piece is ', { box: '3' }, ' × ', { box: '4' }], why: 'A 3 × 1 column times a 1 × 4 row is 3 × 4, the size of AB.', hint: 'A column of A has 3 numbers, a row of B has 4.' },+ { parts: ['AB has ', { box: '12' }, ' entries, each a sum of ', { box: '2' }, ' products'], why: '3 × 4 = 12 entries; each is a row of A (2 numbers) times a column of B.', hint: 'AB is 3 × 4. A row of A has 2 numbers.' },+ ]),+ }], done, 'Chapter practice · set 3 of 4') }],+ ['final4', 'Chapter practice', () => {+ const p = panel(0);+ title(p, 'Hit the targets with rows');+ S.P = mm(p, { A: HANDS[0].A, B: HANDS[0].B, at: AT, tintB: 'rows' });+ S.g = rowPic(p, S.P, 0); S.tg = G(p, {});+ }, { ask: done => quiz(CARD, HANDS.map((h, k) => ({+ id: `p-hand${k + 1}`, prompt: [h.prompt],+ build: (body, api) => {+ const { A, B } = h;+ S.P.set({ a00: A[0][0], a01: A[0][1], a10: A[1][0], a11: A[1][1], b00: B[0][0], b01: B[0][1], b10: B[1][0], b11: B[1][1] });+ S.tg.replaceChildren();+ if (h.tgt) { target(S.g.P, h.tgt, S.tg, 0); put(S.tg.lastChild, { o: 1 }); }+ const only = h.tgt ? [`a${h.row}0`, `a${h.row}1`] : ['b00', 'b01', 'b10', 'b11'];+ S.P.show('rows', h.row, 0);+ const test = h.tgt ? (v, C) => C[h.row][0] === h.tgt[0] && C[h.row][1] === h.tgt[1] : (v, C) => C[0][0] === 1 && C[0][1] === 2 && C[1][0] === 3 && C[1][1] === 1;+ const hint = h.tgt ? (v, C) => `Row ${h.row + 1} of AB is (${num(Math.round(C[h.row][0] * 10) / 10)}, ${num(Math.round(C[h.row][1] * 10) / 10)}). Which mix of B’s rows gives (${num(h.tgt[0])}, ${num(h.tgt[1])})?`+ : (v, C) => `AB is [${num(C[0][0])} ${num(C[0][1])}; ${num(C[1][0])} ${num(C[1][1])}]. With A = I, AB is just B.`;+ return mmTask(S.P, test, h.why, hint, () => S.P.set(h.ans), { only })(body, api);+ },+ })), done, 'Chapter practice · set 4 of 4') }],+ ['play', 'Playground', (m, D) => {+ const p = panel(0);+ title(p, 'Playground');+ S.P = mm(p, { A: A0, B: B0, at: AT, tintB: 'rows' });+ rowPic(p, S.P, 0);+ const hint = text(p, 'try: equal rows in B · a row of zeros in A · A = the identity', 70, 170, m('go'), { size: 24, fill: COL.dim });+ hide(hint, Math.min(m('go') + 9, D - .7), .6);+ }, { ask: playAsk(() => S.P, { pos: { ...CARD, y: 470 }, tip: 'The row way, live: the arrows are the rows of B, the ring is a row of A. Change anything, 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/ch25/audio/en/assoc.mp3 b/site/linear-algebra/ch25/audio/en/assoc.mp3new file mode 100644index 0000000..b98f9d3Binary files /dev/null and b/site/linear-algebra/ch25/audio/en/assoc.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/dist.mp3 b/site/linear-algebra/ch25/audio/en/dist.mp3new file mode 100644index 0000000..ac02ff8Binary files /dev/null and b/site/linear-algebra/ch25/audio/en/dist.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/final1.mp3 b/site/linear-algebra/ch25/audio/en/final1.mp3new file mode 100644index 0000000..737f2ebBinary files /dev/null and b/site/linear-algebra/ch25/audio/en/final1.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/final2.mp3 b/site/linear-algebra/ch25/audio/en/final2.mp3new file mode 100644index 0000000..142b312Binary files /dev/null and b/site/linear-algebra/ch25/audio/en/final2.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/final3.mp3 b/site/linear-algebra/ch25/audio/en/final3.mp3new file mode 100644index 0000000..3727061Binary files /dev/null and b/site/linear-algebra/ch25/audio/en/final3.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/final4.mp3 b/site/linear-algebra/ch25/audio/en/final4.mp3new file mode 100644index 0000000..8df4344Binary files /dev/null and b/site/linear-algebra/ch25/audio/en/final4.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/finish.mp3 b/site/linear-algebra/ch25/audio/en/finish.mp3new file mode 100644index 0000000..245aaa9Binary files /dev/null and b/site/linear-algebra/ch25/audio/en/finish.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/identity.mp3 b/site/linear-algebra/ch25/audio/en/identity.mp3new file mode 100644index 0000000..bcb5371Binary files /dev/null and b/site/linear-algebra/ch25/audio/en/identity.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/intro.mp3 b/site/linear-algebra/ch25/audio/en/intro.mp3new file mode 100644index 0000000..68db62aBinary files /dev/null and b/site/linear-algebra/ch25/audio/en/intro.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/motion.mp3 b/site/linear-algebra/ch25/audio/en/motion.mp3new file mode 100644index 0000000..fb73a1bBinary files /dev/null and b/site/linear-algebra/ch25/audio/en/motion.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/order.mp3 b/site/linear-algebra/ch25/audio/en/order.mp3new file mode 100644index 0000000..a38435eBinary files /dev/null and b/site/linear-algebra/ch25/audio/en/order.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/play.mp3 b/site/linear-algebra/ch25/audio/en/play.mp3new file mode 100644index 0000000..7e29569Binary files /dev/null and b/site/linear-algebra/ch25/audio/en/play.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/powers.mp3 b/site/linear-algebra/ch25/audio/en/powers.mp3new file mode 100644index 0000000..5935312Binary files /dev/null and b/site/linear-algebra/ch25/audio/en/powers.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/q1.mp3 b/site/linear-algebra/ch25/audio/en/q1.mp3new file mode 100644index 0000000..a27ba08Binary files /dev/null and b/site/linear-algebra/ch25/audio/en/q1.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/q2.mp3 b/site/linear-algebra/ch25/audio/en/q2.mp3new file mode 100644index 0000000..60812eeBinary files /dev/null and b/site/linear-algebra/ch25/audio/en/q2.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/q3.mp3 b/site/linear-algebra/ch25/audio/en/q3.mp3new file mode 100644index 0000000..b7634ceBinary files /dev/null and b/site/linear-algebra/ch25/audio/en/q3.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/some.mp3 b/site/linear-algebra/ch25/audio/en/some.mp3new file mode 100644index 0000000..72f821bBinary files /dev/null and b/site/linear-algebra/ch25/audio/en/some.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/timings.js b/site/linear-algebra/ch25/audio/en/timings.jsnew file mode 100644index 0000000..1e0f4b4--- /dev/null+++ b/site/linear-algebra/ch25/audio/en/timings.js@@ -0,0 +1,695 @@+window.TIMINGS = {+ "intro": {+ "dur": 13.704,+ "marks": {+ "sub": 4.271,+ "move": 8.411+ },+ "cues": [+ [+ 0.091,+ "Chapter twenty-five."+ ],+ [+ 1.914,+ "Rules for matrix arithmetic."+ ],+ [+ 4.271,+ "Most rules from ordinary numbers still work for matrices."+ ],+ [+ 8.411,+ "But one famous rule breaks: A times B is usually not B times A."+ ]+ ]+ },+ "order": {+ "dur": 47.664,+ "marks": {+ "A": 2.161,+ "B": 4.935,+ "ab": 10.247,+ "abr": 20.104,+ "ba": 25.404,+ "bar": 33.997,+ "diff": 38.815+ },+ "cues": [+ [+ 0.104,+ "Let's start with the rule that breaks."+ ],+ [+ 2.161,+ "A is one, two, three, four."+ ],+ [+ 4.935,+ "B is zero, one, one, zero: chapter twenty-two's swap."+ ],+ [+ 10.247,+ "A times B."+ ],+ [+ 11.432,+ "By columns: column one of B, zero, one, takes column two of A."+ ],+ [+ 17.773,+ "Column two of B takes column one of A."+ ],+ [+ 20.104,+ "So A B is A with its columns swapped: two, one, four, three."+ ],+ [+ 25.404,+ "Now B times A."+ ],+ [+ 26.94,+ "By rows: row one of B, zero, one, takes row two of A."+ ],+ [+ 31.667,+ "Row two of B takes row one of A."+ ],+ [+ 33.997,+ "So B A is A with its rows swapped: three, four, one, two."+ ],+ [+ 38.815,+ "A B is not B A."+ ],+ [+ 40.964,+ "With numbers, two times three equals three times two."+ ],+ [+ 45.039,+ "With matrices, the order matters."+ ]+ ]+ },+ "motion": {+ "dur": 57.48,+ "marks": {+ "x": 5.716,+ "first": 8.672,+ "ex": 13.737,+ "b": 20.651,+ "a": 25.039,+ "c1": 28.802,+ "c2": 35.286,+ "ab": 42.07,+ "rule": 52.422+ },+ "cues": [+ [+ 0.104,+ "To see why, think of a matrix as a motion of the plane, as in chapter ten."+ ],+ [+ 5.716,+ "A B times x is A times B x."+ ],+ [+ 8.672,+ "B stands next to x, so B acts first."+ ],+ [+ 11.849,+ "Then A acts on what B made."+ ],+ [+ 13.737,+ "Let B be a shear, one, one, zero, one, and A a quarter turn, zero, minus one, one, zero."+ ],+ [+ 20.651,+ "First B: the plane shears, and the flag leans over."+ ],+ [+ 25.039,+ "Then A: the whole sheared plane turns a quarter turn."+ ],+ [+ 28.802,+ "Follow the point one, zero."+ ],+ [+ 30.859,+ "The shear leaves it where it is."+ ],+ [+ 32.552,+ "The turn carries it up to zero, one."+ ],+ [+ 35.286,+ "And zero, one: the shear moves it to one, one, and the turn carries that to minus one, one."+ ],+ [+ 42.07,+ "So A B has columns zero, one and minus one, one."+ ],+ [+ 46.55,+ "Work it out by entries, and you get the same: zero, minus one, one, one."+ ],+ [+ 52.422,+ "A B means: first B, then A."+ ],+ [+ 55.898,+ "Read right to left."+ ]+ ]+ },+ "two": {+ "dur": 37.896,+ "marks": {+ "left": 3.75,+ "right": 8.06,+ "go": 11.979,+ "mid": 13.359,+ "end": 19.974,+ "nums": 24.557,+ "rule": 31.602+ },+ "cues": [+ [+ 0.104,+ "Now do the two motions in the other order, side by side."+ ],+ [+ 3.75,+ "On the left, A B: first the shear, then the turn."+ ],+ [+ 8.06,+ "On the right, B A: first the turn, then the shear."+ ],+ [+ 11.979,+ "Watch both at once."+ ],+ [+ 13.359,+ "After the first step the pictures already differ: one plane has leaned, the other has turned."+ ],+ [+ 19.974,+ "After both steps they still differ."+ ],+ [+ 22.539,+ "The flags point different ways."+ ],+ [+ 24.557,+ "A B is zero, minus one, one, one."+ ],+ [+ 27.891,+ "B A is one, minus one, one, zero."+ ],+ [+ 31.602,+ "A B is not B A: putting on socks then shoes is not shoes then socks."+ ]+ ]+ },+ "q1": {+ "dur": 3.408,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.094,+ "Work out A B and B A."+ ]+ ]+ },+ "some": {+ "dur": 32.664,+ "marks": {+ "eye": 2.865,+ "same": 6.393,+ "stretch": 11.172,+ "turns": 21.224,+ "but": 28.164+ },+ "cues": [+ [+ 0.104,+ "Sometimes the order happens not to matter."+ ],+ [+ 2.865,+ "The identity: A times I and I times A are both A."+ ],+ [+ 6.393,+ "A matrix with itself: A times A is A times A, of course."+ ],+ [+ 11.172,+ "Two stretches along the axes: two, zero, zero, three times four, zero, zero, five is eight, zero, zero, fifteen, in either order."+ ],+ [+ 21.224,+ "And two turns: turning by one angle and then another is the same as the other way round."+ ],+ [+ 28.164,+ "But these are special."+ ],+ [+ 29.544,+ "Unless you know, never swap the order of a product."+ ]+ ]+ },+ "identity": {+ "dur": 33.0,+ "marks": {+ "A": 2.044,+ "I": 4.57,+ "c1": 6.823,+ "c2": 14.714,+ "ai": 17.708,+ "ia": 19.193,+ "pic": 27.448+ },+ "cues": [+ [+ 0.104,+ "A closer look at the identity."+ ],+ [+ 2.044,+ "Take A equals two, one, one, three, times I, one, zero, zero, one."+ ],+ [+ 6.823,+ "By columns: column one of I is one, zero."+ ],+ [+ 10.052,+ "One of column one of A, plus none of column two: just column one of A."+ ],+ [+ 14.714,+ "Column two of I picks out column two of A."+ ],+ [+ 17.708,+ "So A I is A."+ ],+ [+ 19.193,+ "On the left, by rows: row one of I, one, zero, picks row one of A, and row two picks row two."+ ],+ [+ 26.237,+ "I A is A too."+ ],+ [+ 27.448,+ "As a motion, I moves nothing."+ ],+ [+ 29.714,+ "Doing nothing before or after A changes nothing."+ ]+ ]+ },+ "assoc": {+ "dur": 47.16,+ "marks": {+ "three": 2.109,+ "left": 6.146,+ "ab": 9.831,+ "abc": 12.565,+ "right": 15.469,+ "bc": 19.023,+ "abc2": 21.536,+ "rule": 25.143,+ "why": 35.156,+ "e": 40.846+ },+ "cues": [+ [+ 0.117,+ "Here is a rule that does hold."+ ],+ [+ 2.109,+ "Take three matrices, A, B and C."+ ],+ [+ 6.146,+ "We can multiply A B first, and then times C."+ ],+ [+ 9.831,+ "A B is two, one, zero, one."+ ],+ [+ 12.565,+ "Times C: three, one, one, one."+ ],+ [+ 15.469,+ "Or B C first, and then A times that."+ ],+ [+ 19.023,+ "B C is two, zero, one, one."+ ],+ [+ 21.536,+ "A times B C: three, one, one, one."+ ],+ [+ 24.18,+ "The same."+ ],+ [+ 25.143,+ "A B, then C, equals A, then B C."+ ],+ [+ 29.688,+ "Where you put the brackets doesn't matter, as long as the order stays A, B, C."+ ],+ [+ 35.156,+ "As motions, both mean: first C, then B, then A."+ ],+ [+ 40.846,+ "We used this in chapter twenty-one: E three two times E two one A could be done in either grouping."+ ]+ ]+ },+ "dist": {+ "dur": 48.216,+ "marks": {+ "add": 2.865,+ "bc": 7.37,+ "lhs": 17.096,+ "ab": 21.224,+ "ac": 25.443,+ "sum": 28.359,+ "rule": 33.047,+ "why": 37.357,+ "keep": 42.383+ },+ "cues": [+ [+ 0.104,+ "One more rule: multiplying a sum."+ ],+ [+ 2.865,+ "To add two matrices of the same size, add them number by number."+ ],+ [+ 7.37,+ "B plus C: one plus zero is one, zero plus one is one, two plus one is three, one plus zero is one."+ ],+ [+ 17.096,+ "A times B plus C is seven, three, three, one."+ ],+ [+ 21.224,+ "Now separately: A B is five, two, two, one."+ ],+ [+ 25.443,+ "A C is two, one, one, zero."+ ],+ [+ 28.359,+ "Add them: seven, three, three, one."+ ],+ [+ 32.096,+ "The same."+ ],+ [+ 33.047,+ "A times B plus C equals A B plus A C."+ ],+ [+ 37.357,+ "Column by column, A times a sum of two vectors is the sum of A times each one."+ ],+ [+ 42.383,+ "Keep A on the left in every term: A B plus A C, never B A."+ ]+ ]+ },+ "q2": {+ "dur": 7.272,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.107,+ "Check the rule A times B plus C equals A B plus A C on these numbers."+ ]+ ]+ },+ "powers": {+ "dur": 51.408,+ "marks": {+ "sq": 1.068,+ "s": 4.557,+ "s2": 7.474,+ "s3": 14.323,+ "t": 19.023,+ "t2": 21.094,+ "warn": 27.096,+ "t3": 37.031,+ "t4": 39.974,+ "order": 43.984+ },+ "cues": [+ [+ 0.091,+ "Powers."+ ],+ [+ 1.068,+ "A squared means A times A: do the motion twice."+ ],+ [+ 4.557,+ "The shear, one, one, zero, one."+ ],+ [+ 7.474,+ "Shear twice: S squared is one, two, zero, one."+ ],+ [+ 12.07,+ "The flag leans twice as far."+ ],+ [+ 14.323,+ "Three times: S cubed is one, three, zero, one."+ ],+ [+ 19.023,+ "Now the quarter turn T."+ ],+ [+ 21.094,+ "T squared is a half turn: minus one, zero, zero, minus one."+ ],+ [+ 27.096,+ "Careful: that's not each number squared."+ ],+ [+ 30.0,+ "Squaring each number of T would give zero, one, one, zero, a flip, not a turn."+ ],+ [+ 37.031,+ "T cubed is three quarter turns."+ ],+ [+ 39.974,+ "And T to the fourth is a full turn: back to the identity."+ ],+ [+ 43.984,+ "Powers of the same matrix can go in any order: A squared times A is A times A squared."+ ],+ [+ 50.247,+ "Both are A cubed."+ ]+ ]+ },+ "q3": {+ "dur": 8.04,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Your turn."+ ],+ [+ 1.029,+ "A is a quarter turn."+ ],+ [+ 2.435,+ "Change B until A B equals B A, so both pictures land the same way."+ ]+ ]+ },+ "wrap": {+ "dur": 27.024,+ "marks": {+ "w1": 1.042,+ "w2": 6.719,+ "w3": 12.826,+ "w4": 18.177,+ "end": 24.961+ },+ "cues": [+ [+ 0.104,+ "Let's sum up."+ ],+ [+ 1.042,+ "Usually A B is not B A."+ ],+ [+ 3.815,+ "A B means first B, then A."+ ],+ [+ 6.719,+ "Brackets can move: A B, then C, equals A, then B C."+ ],+ [+ 12.826,+ "Sums spread out: A times B plus C equals A B plus A C."+ ],+ [+ 18.177,+ "A I equals I A equals A, and A squared is A times A: the motion done twice."+ ],+ [+ 24.961,+ "Now try the chapter practice."+ ]+ ]+ },+ "final1": {+ "dur": 2.64,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Chapter practice."+ ],+ [+ 1.484,+ "Both orders."+ ]+ ]+ },+ "final2": {+ "dur": 4.416,+ "marks": {},+ "cues": [+ [+ 0.104,+ "True or false: which rules hold for every matrix?"+ ]+ ]+ },+ "final3": {+ "dur": 1.872,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Powers and brackets."+ ]+ ]+ },+ "final4": {+ "dur": 3.576,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Last set."+ ],+ [+ 1.198,+ "Make A B equal B A."+ ]+ ]+ },+ "play": {+ "dur": 10.584,+ "marks": {+ "go": 3.919+ },+ "cues": [+ [+ 0.117,+ "Playground."+ ],+ [+ 1.081,+ "Nothing here is marked right or wrong."+ ],+ [+ 3.919,+ "Change A or B, and compare the two motions: first B then A, and first A then B."+ ]+ ]+ },+ "finish": {+ "dur": 9.936,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Well done."+ ],+ [+ 1.146,+ "That's the end of chapter twenty-five, rules for matrix arithmetic."+ ],+ [+ 5.703,+ "Next: the inverse, the matrix that undoes a motion."+ ]+ ]+ }+};diff --git a/site/linear-algebra/ch25/audio/en/two.mp3 b/site/linear-algebra/ch25/audio/en/two.mp3new file mode 100644index 0000000..95de59aBinary files /dev/null and b/site/linear-algebra/ch25/audio/en/two.mp3 differdiff --git a/site/linear-algebra/ch25/audio/en/wrap.mp3 b/site/linear-algebra/ch25/audio/en/wrap.mp3new file mode 100644index 0000000..a980c07Binary files /dev/null and b/site/linear-algebra/ch25/audio/en/wrap.mp3 differdiff --git a/site/linear-algebra/ch25/index.html b/site/linear-algebra/ch25/index.htmlnew file mode 100644index 0000000..9bd862d--- /dev/null+++ b/site/linear-algebra/ch25/index.html@@ -0,0 +1,403 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>Rules for Matrix Arithmetic</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/grid2.js"></script>+<script src="../lib/mm.js"></script>+<script src="../lib/play.js"></script>+<script src="audio/en/timings.js"></script>+<script>+'use strict';+const CHAPTER = { number: 25, title: 'Rules for Matrix Arithmetic', minutes: 10, language: 'en', next: '../ch26/' };++/* ---------- chapter drawing helpers ---------- */+const SHEAR = [[1, 1], [0, 1]], TURN = [[0, -1], [1, 0]]; // the shear and the quarter turn+const mul = (A, B) => A.map(r => B[0].map((_, j) => r.reduce((t, a, k) => t + a * B[k][j], 0)));+const rot = deg => { const a = deg * Math.PI / 180, k = n => Math.round(n * 1e9) / 1e9; return [[k(Math.cos(a)), k(-Math.sin(a))], [k(Math.sin(a)), k(Math.cos(a))]]; };+const shear = q => [[1, q], [0, 1]];+const gv = M_ => ({ a00: M_[0][0], a01: M_[0][1], a10: M_[1][0], a11: M_[1][1] });+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 });+// A plane carried by a matrix, with the flag, no numbers (grid2 read-only: the chapter sets it).+const motion = (p, cx, cy, u, r = 4, t0 = .1) => grid2(p, { A: [[1, 0], [0, 1]], mat: null, shape: true, units: false, plane: { cx, cy, u, x0: -r, x1: r, y0: -r, y1: r }, t0 });+// Run "first M1(q), then M2(q)" on a grid: f1, f2 give the matrix of each motion part way (q from 0 to 1).+const steps = (g, f1, f2, at, dur = 2.2) => {+ prog(q => g.set(gv(f1(q))), at, dur, io);+ prog(q => g.set(gv(mul(f2(q), f1(1)))), at + dur + .3, dur, io);+};+// A matrix shown small with a name in front: "S² = [..]".+const named = (p, name, rows, x, y, t0, { size = 34, fill = () => COL.chalk } = {}) => {+ const g = G(p, { o: 0 });+ const w = M(g, [name, ' ='], { x, y: y + size * .36, size, anchor: 'start' });+ mmSmall(g, rows, x + (w._w || 60) + 14, y, { size, fill });+ show(g, t0, .4);+ return g;+};+// A soft band on entry (i, j) of small matrices drawn by mmSmall (size 34) at x positions, for a moment.+const cellBands = (p, mats, i, j, ymid, t0, size = 34) => mats.forEach(([rows, x]) => {+ const w0 = Math.max(...rows.flat().map(v => num(v).length)), c = size * (.55 * w0 + .75), rh = size * 1.22, n = rows.length;+ const r = mk('rect', { x: x + 10 + c * j + 2, y: ymid - n * rh / 2 + i * rh + 2, width: c - 4, height: rh - 4, rx: 8, fill: COL.chalk, 'fill-opacity': .18, stroke: COL.chalk, 'stroke-opacity': .5 }, p);+ put(r, { o: 0 }); show(r, t0, .25); hide(r, t0 + 1.7, .3);+});+const mmS = (p, A, B, at, names, o = {}) => mm(p, { A, B, at, names, size: 34, cw: 50, rh: 52, sizes: false, ...o });+// Two products side by side, A B and B A, each with the plane it makes; the second follows the first.+const commute = (p, A, B, { t0 = .1 } = {}) => {+ const P_ = mmS(p, A, B, [60, 230], ['A', 'B', 'AB'], { t0 });+ const Q = mmS(p, B, A, [860, 230], ['B', 'A', 'BA'], { t0 });+ put(P_.W, { o: 0 }); put(Q.W, { o: 0 });+ const gL = motion(p, 300, 620, 30, 4, t0), gR = motion(p, 1180, 620, 30, 4, t0);+ text(p, 'AB: first B, then A', 300, 455, t0, { size: 24, fill: COL.dim, weight: 600, anchor: 'middle' });+ text(p, 'BA: first A, then B', 1180, 455, t0, { size: 24, fill: COL.dim, weight: 600, anchor: 'middle' });+ const sync = v => {+ const sw = {}; ['00', '01', '10', '11'].forEach(k => { sw[`a${k}`] = v[`b${k}`]; sw[`b${k}`] = v[`a${k}`]; });+ Q.set(sw); gL.set(gv(P_.C())); gR.set(gv(Q.C()));+ };+ P_.onChange(sync); sync(P_.v);+ return { P: P_, Q, gL, gR };+};+const same = (C, D_) => C.every((r, i) => r.every((v, j) => Math.abs(v - D_[i][j]) < 1e-9));+const pairEl = (A, B) => ['A = ', mmEl(A), ' B = ', mmEl(B)];+const boxes = rows => rows.flatMap((r, i) => [...(i ? ['; '] : []), ...r.flatMap((v, j) => [...(j ? [' '] : []), { box: String(v) }])]);++/* ---------- practice data (every product worked twice: by columns and by entries) ---------- */+const ORDQ = [+ { A: [[1, 1], [0, 1]], B: [[1, 0], [1, 1]] }, { A: [[2, 0], [0, 1]], B: [[0, 1], [1, 0]] }, { A: [[1, 2], [3, 4]], B: [[1, 0], [0, 1]] },+].map(q => ({ ...q, AB: mul(q.A, q.B), BA: mul(q.B, q.A) }));+const RULEQ = [+ ['AB = BA for every A and B', false, 'The swap and the shear-and-turn both broke it.'],+ ['(AB)C = A(BC)', true, 'Brackets can move: both mean first C, then B, then A.'],+ ['A(B + C) = AB + AC', true, 'Column by column, A times a sum is the sum of A times each.'],+ ['(A + B)C = AC + BC', true, 'The same rule with C on the right of every term.'],+ ['A(B + C) = BA + CA', false, 'The order changed: it should be AB + AC.'],+ ['AI = IA = A', true, 'The identity moves nothing, before or after.'],+ ['A²A = AA²', true, 'Both are A three times: A³.'],+ ['(AB)² = A²B² for every A and B', false, '(AB)² = ABAB; turning the middle BA into AB needs AB = BA.'],+].map(([s, ok, why]) => ({ parts: [s], ans: [ok ? 't' : 'f'], why }));+const HANDS = [+ { A: TURN, B: SHEAR, prompt: 'A is a quarter turn. Change B until AB = BA: both planes end the same way.', why: 'Any B of the form [a −b; b a] works (a turn and a stretch), for example I, or the turn itself.' },+ { A: [[2, 0], [0, 1]], B: SHEAR, prompt: 'A stretches sideways. Change B until AB = BA.', why: 'B must not mix x and y: its corner numbers must be 0, as in [a 0; 0 d].' },+ { A: SHEAR, B: [[1, 0], [1, 1]], prompt: 'A is the shear. Change B until AB = BA.', why: 'B must be [a b; 0 a]: another shear (times a number), or the identity.' },+];++/* ---------- beats ---------- */+const BEATS = [+ ['intro', 'Rules for matrix arithmetic', (m, D) => {+ const g = G(scene, { o: 0, y: 24 });+ T(g, 'Unit 3, Chapter 25', { x: 800, y: 250, size: 28, fill: COL.dim, anchor: 'middle' });+ T(g, 'Rules for Matrix Arithmetic', { x: 800, y: 360, size: 84, weight: 600, anchor: 'middle' });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);+ const r = text(scene, 'what still works, and the one rule that breaks', 800, 460, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });+ const lg = G(scene, { o: 0 }); show(lg, m('move'), .5);+ const say2 = say(lg, ['AB ≠ BA'], 800, 650, m('move') + .3, { size: 64, anchor: 'middle' });+ pulse(say2, m('move') + 1.5);+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);+ }],++ ['order', 'AB and BA', (m) => {+ const p = panel(0);+ title(p, 'A B and B A');+ const A = [[1, 2], [3, 4]], B = [[0, 1], [1, 0]];+ const P_ = mm(p, { A, B, at: [90, 280], hideC: true, tintA: 'cols', t0: m('A') - .3 });+ put(P_.L.b.g, { o: 0 }); show(P_.L.b.g, m('B'), .5);+ put(P_.L.c.g, { o: 0 }); show(P_.L.c.g, m('ab'), .5);+ P_.flash('a', 'all', m('A') + .3); P_.flash('b', 'all', m('B') + .5);+ P_.show('cols', 0, m('ab') + .5); P_.show('cols', 1, m('ab') + 4.5);+ P_.reveal('all', m('abr'));+ const Q = mm(p, { A: B, B: A, names: ['B', 'A', 'BA'], at: [860, 280], hideC: true, tintB: 'rows', work: [860, 560], t0: m('ba') - .3 });+ put(Q.g, { o: 0 }); show(Q.g, m('ba'), .5);+ Q.show('rows', 0, m('ba') + .5); Q.show('rows', 1, m('ba') + 4.5);+ Q.reveal('all', m('bar'));+ P_.show(null, null, m('diff')); Q.show(null, null, m('diff'));+ P_.flash('c', 'all', m('diff')); Q.flash('c', 'all', m('diff'));+ say(p, ['AB ≠ BA'], 800, 720, m('diff') + .4, { size: 56, fill: COL.bad, anchor: 'middle' });+ text(p, '2 × 3 = 3 × 2, but with matrices the order matters', 800, 790, m('diff') + 3, { size: 28, fill: COL.dim, weight: 600, anchor: 'middle' });+ }],++ ['motion', 'First B, then A', (m, D) => {+ const p = panel(0);+ title(p, 'A B x = A (B x): first B, then A');+ const P_ = mm(p, { A: TURN, B: SHEAR, at: [70, 280], hideC: true, t0: m('ex') - .3 });+ put(P_.W, { o: 0 });+ put(P_.g, { o: 0 }); show(P_.g, m('ex'), .5);+ const na = text(p, 'A: quarter turn', P_.L.a.x + P_.L.a.W / 2, 450, m('ex') + 4, { size: 26, fill: COL.dim, weight: 600, anchor: 'middle' });+ const nb = text(p, 'B: shear', P_.L.b.x + P_.L.b.W / 2, 450, m('ex') + 2, { size: 26, fill: COL.dim, weight: 600, anchor: 'middle' });+ [nb, na].forEach(e => hide(e, m('ab') - .4, .3));+ const sx = say(p, ['AB x = A (B x)'], 70, 200, m('x'), { size: 36 });+ hide(sx, m('ex') - .3, .3);+ [text(p, 'B acts first', 340, 250, m('first') + .4, { size: 26, fill: COL.dim, weight: 600 }), text(p, 'then A', 175, 250, m('first') + 3, { size: 26, fill: COL.dim, weight: 600 })].forEach(e => hide(e, m('ex') - .3, .3));+ const g = motion(p, 1150, 450, 56, 5);+ P_.flash('b', 'all', m('b'));+ prog(q => g.set(gv(shear(q))), m('b') + .4, 2.4, io);+ P_.flash('a', 'all', m('a'));+ prog(q => g.set(gv(mul(rot(90 * q), SHEAR))), m('a') + .4, 2.4, io);+ // follow (1, 0) and (0, 1): they are the green and violet arrows; replay the two steps with them lit+ const replay = (t0) => { prog(q => g.set(gv(shear(q))), t0, 1.4, io); prog(q => g.set(gv(mul(rot(90 * q), SHEAR))), t0 + 1.8, 1.6, io); };+ prog(q => g.set(gv([[1, 0], [0, 1]])), m('c1'), .4, io);+ replay(m('c1') + .5);+ tw(g.cols[0], { 'a_stroke-width': 10 }, m('c1') + .2, .3); tw(g.cols[0], { 'a_stroke-width': 5 }, m('c2') - .2, .4);+ prog(q => g.set(gv([[1, 0], [0, 1]])), m('c2'), .4, io);+ replay(m('c2') + .5);+ tw(g.cols[1], { 'a_stroke-width': 10 }, m('c2') + .2, .3); tw(g.cols[1], { 'a_stroke-width': 5 }, m('ab'), .4);+ P_.show('cols', 0, m('ab')); P_.reveal({ col: 0 }, m('ab') + .3); P_.reveal({ col: 1 }, m('ab') + 1.5);+ P_.show('entry', [0, 1], m('ab') + 4); P_.show('entry', [1, 0], m('ab') + 6.5); P_.show('entry', [1, 1], m('ab') + 8.5);+ prog(q => g.set(gv([[1, 0], [0, 1]])), m('rule') + .8, .4, io);+ replay(m('rule') + 1.4);+ const rl = G(p, { o: 0 }); show(rl, m('rule'), .5);+ M(rl, ['AB = first B, then A (read right to left)'], { x: 70, y: 820, size: 32, anchor: 'start' });+ P_.show(null, null, m('rule'));+ }],++ ['two', 'Two orders', (m) => {+ const p = panel(0);+ title(p, 'Shear then turn, turn then shear');+ const gL = motion(p, 420, 420, 40, 4), gR = motion(p, 1180, 420, 40, 4);+ text(p, 'AB: first the shear B, then the turn A', 420, 210, m('left'), { size: 26, weight: 600, anchor: 'middle' });+ text(p, 'BA: first the turn A, then the shear B', 1180, 210, m('right'), { size: 26, weight: 600, anchor: 'middle' });+ steps(gL, shear, q => rot(90 * q), m('go') + .3);+ steps(gR, q => rot(90 * q), shear, m('go') + .3);+ [gL, gR].forEach(g => prog(q => g.set(gv([[1, 0], [0, 1]])), m('end') + 1, .4, io));+ steps(gL, shear, q => rot(90 * q), m('end') + 1.6, 1.4); steps(gR, q => rot(90 * q), shear, m('end') + 1.6, 1.4);+ const L = mmS(p, TURN, SHEAR, [180, 700], ['A', 'B', 'AB'], { hideC: true, t0: m('nums') - .4 });+ const R = mmS(p, SHEAR, TURN, [940, 700], ['B', 'A', 'BA'], { hideC: true, t0: m('nums') - .4 });+ put(L.W, { o: 0 }); put(R.W, { o: 0 });+ L.reveal('all', m('nums') + .3); R.reveal('all', m('nums') + 2.6);+ say(p, ['≠'], 800, 760, m('rule'), { size: 64, fill: COL.bad, anchor: 'middle' });+ text(p, 'socks, then shoes ≠ shoes, then socks', 800, 860, m('rule') + 2.5, { size: 26, fill: COL.dim, weight: 600, anchor: 'middle' });+ }],++ ['q1', 'Quick check', () => {+ const p = panel(0);+ title(p, 'Quick check');+ const A = [[1, 0], [0, 2]], B = [[0, 1], [1, 0]];+ S.P = mmS(p, A, B, [90, 260], ['A', 'B', 'AB'], { hideC: true });+ S.Q = mmS(p, B, A, [860, 260], ['B', 'A', 'BA'], { hideC: true });+ }, { ask: done => quiz({ x: 40, y: 470, w: 860, cls: 'side' }, [{+ id: 'c-order', prompt: ['B swaps. Work out both orders, row by row.'],+ build: blanks([+ { parts: ['AB = [', ...boxes([[0, 1], [2, 0]]), ']'], why: 'B on the right swaps the columns of A: [0 1; 2 0].', hint: 'By columns: column 1 of B, (0, 1), takes column 2 of A.',+ fx: () => fxp(q => { if (q > 0) S.P.uncover('all'); }, 0, .1) },+ { parts: ['BA = [', ...boxes([[0, 2], [1, 0]]), ']'], why: 'B on the left swaps the rows of A: [0 2; 1 0]. Not the same as AB.', hint: 'By rows: row 1 of B, (0, 1), takes row 2 of A.',+ fx: () => fxp(q => { if (q > 0) S.Q.uncover('all'); }, 0, .1) },+ ]),+ }], done) }],++ ['some', 'When the order does not matter', (m) => {+ const p = panel(0);+ title(p, 'Sometimes AB = BA');+ say(p, ['A I = I A = A'], 90, 240, m('eye'), { size: 40 });+ say(p, ['A A = A A'], 90, 340, m('same'), { size: 40 });+ const st = G(p, { o: 0 }); show(st, m('stretch'), .5);+ let x = 90;+ [[[2, 0], [0, 3]], ['·'], [[4, 0], [0, 5]], ['='], [[8, 0], [0, 15]], ['='], [[4, 0], [0, 5]], ['·'], [[2, 0], [0, 3]]].forEach((it, k) => {+ const g0 = G(st, { o: 0 }); show(g0, m('stretch') + [0, 0, 0, 4, 4, 7, 7, 7, 7][k], .4);+ if (typeof it[0] === 'string') { const w = M(g0, it, { x, y: 452, size: 36, anchor: 'start' }); x += (w._w || 20) + 14; }+ else x += mmSmall(g0, it, x, 440, { size: 34 }) + 14;+ });+ say(p, ['two stretches along the axes'], 90, 540, m('stretch') + 1, { size: 28, fill: COL.dim });+ say(p, ['two turns: turn by 30°, then 60° = 60°, then 30°'], 90, 630, m('turns'), { size: 34 });+ const g = motion(p, 1300, 450, 32, 4, m('turns'));+ put(g.stage, { o: 0 }); show(g.stage, m('turns'), .4);+ prog(q => g.set(gv(rot(30 * q))), m('turns') + .6, 1.2, io); prog(q => g.set(gv(rot(30 + 60 * q))), m('turns') + 2.2, 1.6, io);+ text(p, 'special cases: never swap the order unless you know', 90, 760, m('but'), { size: 32, fill: COL.bad, weight: 600 });+ }],++ ['identity', 'The identity', (m) => {+ const p = panel(0);+ title(p, 'The identity: A I = I A = A');+ const top = G(p, {});+ const P_ = mm(top, { A: [[2, 1], [1, 3]], B: [[1, 0], [0, 1]], names: ['A', 'I', 'AI'], at: [90, 260], tintA: 'cols', hideC: true, t0: m('A') - .3 });+ put(P_.L.b.g, { o: 0 }); show(P_.L.b.g, m('I'), .5);+ P_.show('cols', 0, m('c1'), { times: [m('c1') + 1.5, m('c1') + 3.5, m('c1') + 5] }); P_.reveal({ col: 0 }, m('c1') + 5);+ P_.show('cols', 1, m('c2')); P_.reveal({ col: 1 }, m('c2') + 1.5);+ P_.show(null, null, m('ai')); P_.flash('c', 'all', m('ai')); P_.flash('a', 'all', m('ai') + .3);+ hide(top, m('ia'), .4);+ const bot = G(p, { o: 0 }); show(bot, m('ia') + .3, .4);+ const Q = mm(bot, { A: [[1, 0], [0, 1]], B: [[2, 1], [1, 3]], names: ['I', 'A', 'IA'], at: [90, 260], tintB: 'rows', t0: 0 });+ Q.show('rows', 0, m('ia') + .5); Q.show('rows', 1, m('ia') + 4);+ const g = motion(p, 1200, 450, 44, 4, m('pic'));+ put(g.stage, { o: 0 }); show(g.stage, m('pic'), .4);+ text(p, 'I moves nothing', 1200, 220, m('pic') + .3, { size: 28, weight: 600, anchor: 'middle' });+ pulse(g.cols[0], m('pic') + 1); pulse(g.cols[1], m('pic') + 1.4);+ }],++ ['assoc', 'Brackets can move', (m) => {+ const p = panel(0);+ title(p, '(A B) C = A (B C)');+ const A = [[1, 1], [0, 1]], B = [[2, 0], [0, 1]], C = [[1, 0], [1, 1]];+ const o = { hideC: true };+ const m1 = mmS(p, A, B, [70, 260], ['A', 'B', 'AB'], { ...o, t0: m('left') - .3 });+ const m2 = mmS(p, mul(A, B), C, [760, 260], ['AB', 'C', '(AB)C'], { ...o, t0: m('ab') + .8 });+ const m3 = mmS(p, B, C, [70, 560], ['B', 'C', 'BC'], { ...o, t0: m('right') - .3 });+ const m4 = mmS(p, A, mul(B, C), [760, 560], ['A', 'BC', 'A(BC)'], { ...o, t0: m('bc') + .8 });+ [m1, m2, m3, m4].forEach(q => put(q.W, { o: 0 }));+ [[m1, 'left'], [m2, 'ab'], [m3, 'right'], [m4, 'bc']].forEach(([q, k]) => { put(q.g, { o: 0 }); show(q.g, m(k) - .2 + (k === 'ab' || k === 'bc' ? 1 : 0), .5); });+ text(p, 'A, B, C', 1440, 200, m('three'), { size: 30, weight: 600, anchor: 'end' });+ m1.reveal('all', m('ab')); m2.reveal('all', m('abc'));+ m3.reveal('all', m('bc')); m4.reveal('all', m('abc2'));+ m2.flash('c', 'all', m('rule')); m4.flash('c', 'all', m('rule') + .2);+ m1.flash('a', 'all', m('rule') + 3); m1.flash('b', 'all', m('rule') + 3.6); m2.flash('b', 'all', m('rule') + 4.2);+ m4.flash('a', 'all', m('rule') + 5.5); m3.flash('a', 'all', m('rule') + 6.1); m3.flash('b', 'all', m('rule') + 6.7);+ m2.flash('a', 'all', m('why') + .5); m4.flash('b', 'all', m('why') + 2);+ text(p, 'brackets can move; the order A, B, C stays', 70, 810, m('rule') + .5, { size: 30, weight: 600 });+ text(p, 'as motions: first C, then B, then A', 70, 860, m('why'), { size: 26, fill: COL.dim, weight: 600 });+ text(p, 'chapter 21: E₃₂ (E₂₁ A) = (E₃₂ E₂₁) A', 900, 860, m('e'), { size: 26, fill: COL.dim, weight: 600 });+ }],++ ['dist', 'Multiplying a sum', (m) => {+ const p = panel(0);+ title(p, 'A (B + C) = A B + A C');+ const A = [[1, 2], [0, 1]], B = [[1, 0], [2, 1]], C = [[0, 1], [1, 0]], BC = [[1, 1], [3, 1]];+ const ad = G(p, { o: 0 }); show(ad, m('add'), .5);+ let x = 70;+ const BX = [];+ [['B + C ='], B, ['+'], C, ['='], BC].forEach((it, k) => {+ if (typeof it[0] === 'string') { const w = M(ad, it, { x, y: 272, size: 34, anchor: 'start' }); x += (w._w || 20) + 12; }+ else { BX.push(x); const g0 = G(ad, {}); x += mmSmall(g0, it, x, 260, { size: 34 }) + 12; if (k === 5) { put(g0, { o: 0 }); show(g0, m('bc'), .4); } }+ });+ const L = mmS(p, A, BC, [760, 260], ['A', 'B + C', 'A(B + C)'], { hideC: true, t0: m('lhs') - .3 });+ put(L.W, { o: 0 }); put(L.g, { o: 0 }); show(L.g, m('lhs') - .2, .5); L.reveal('all', m('lhs') + 1);+ const P1 = mmS(p, A, B, [70, 560], ['A', 'B', 'AB'], { hideC: true, t0: m('ab') - .3 });+ const P2 = mmS(p, A, C, [620, 560], ['A', 'C', 'AC'], { hideC: true, t0: m('ac') - .3 });+ [P1, P2].forEach(q => put(q.W, { o: 0 }));+ put(P1.g, { o: 0 }); show(P1.g, m('ab') - .2, .5); P1.reveal('all', m('ab') + 1);+ put(P2.g, { o: 0 }); show(P2.g, m('ac') - .2, .5); P2.reveal('all', m('ac') + 1);+ named(p, 'AB + AC', [[7, 3], [3, 1]], 1170, 584, m('sum'), { fill: () => COL.task });+ // B + C read entry by entry: the same place lit in all three+ [[0, 0], [0, 1], [1, 0], [1, 1]].forEach(([i, j], k) => cellBands(p, [[B, BX[0]], [C, BX[1]], [BC, BX[2]]], i, j, 260, m('bc') + 1.3 + k * 2.1));+ L.flash('c', 'all', m('sum') + 2.4);+ text(p, 'column by column: A(b + c) = Ab + Ac', 70, 790, m('why'), { size: 28, fill: COL.dim, weight: 600 });+ text(p, 'A stays on the left: AB + AC, never BA', 70, 850, m('keep'), { size: 28, weight: 600 });+ }],++ ['q2', 'Quick check', () => {+ const p = panel(0);+ title(p, 'Quick check');+ say(p, ['A = '], 90, 250, .3, { size: 34 }); mmSmall(G(p, {}), [[2, 0], [1, 1]], 170, 238, { size: 34 });+ say(p, ['B = '], 420, 250, .3, { size: 34 }); mmSmall(G(p, {}), [[1, 1], [0, 1]], 500, 238, { size: 34 });+ say(p, ['C = '], 750, 250, .3, { size: 34 }); mmSmall(G(p, {}), [[0, 1], [1, 0]], 830, 238, { size: 34 });+ }, { ask: done => quiz({ x: 40, y: 320, w: 1000, cls: 'side' }, [{+ id: 'c-dist', prompt: ['Both sides of A(B + C) = AB + AC.'],+ build: blanks([+ { parts: ['B + C = [', ...boxes([[1, 2], [1, 1]]), ']'], why: 'Number by number: 1 + 0, 1 + 1, 0 + 1, 1 + 0.', hint: 'Add the numbers in the same places.' },+ { parts: ['A(B + C) = [', ...boxes([[2, 4], [2, 3]]), ']'], why: 'Row 1 (2, 0) and row 2 (1, 1) of A times the columns (1, 1) and (2, 1).', hint: 'Use B + C from the line above. Entry (i, j): row i of A times column j.' },+ { parts: ['AB = [', ...boxes([[2, 2], [1, 2]]), ']'], why: 'Rows (2, 0) and (1, 1) of A times the columns of B.', hint: 'Entry (i, j): row i of A times column j of B.' },+ { parts: ['AC = [', ...boxes([[0, 2], [1, 1]]), ']'], why: 'AB + AC = [2 4; 2 3]: the same as A(B + C).', hint: 'C swaps: AC is A with its columns swapped.' },+ ]),+ }], done) }],++ ['powers', 'Powers', (m) => {+ const p = panel(0);+ title(p, 'Powers: A² = A A, the motion twice');+ const g = motion(p, 1150, 460, 50, 5);+ named(p, 'S', SHEAR, 90, 260, m('s'));+ prog(q => g.set(gv(shear(q))), m('s') + .3, 1.6, io);+ named(p, 'S²', [[1, 2], [0, 1]], 90, 380, m('s2'));+ prog(q => g.set(gv(shear(1 + q))), m('s2') + .3, 1.6, io);+ named(p, 'S³', [[1, 3], [0, 1]], 90, 500, m('s3'));+ prog(q => g.set(gv(shear(2 + q))), m('s3') + .3, 1.6, io);+ prog(q => g.set(gv(shear(3 * (1 - q)))), m('t') - .2, .8, io);+ named(p, 'T', TURN, 460, 260, m('t'));+ prog(q => g.set(gv(rot(90 * q))), m('t') + .8, 1.6, io);+ named(p, 'T²', [[-1, 0], [0, -1]], 460, 380, m('t2'));+ prog(q => g.set(gv(rot(90 + 90 * q))), m('t2') + .3, 1.6, io);+ const wn = named(p, 'not', [[0, 1], [1, 0]], 90, 640, m('warn'), { fill: () => COL.bad });+ prog(q => g.set(gv([[-1 + q, q], [q, -1 + q]])), m('warn') + 3.5, 1.4, io);+ prog(q => g.set(gv([[-q, 1 - q], [1 - q, -q]])), m('warn') + 6.5, 1.4, io);+ text(p, 'each number squared: a flip, not a turn', 90, 730, m('warn') + 2, { size: 26, fill: COL.bad, weight: 600 });+ hide(wn, m('order'), .3);+ named(p, 'T³', [[0, 1], [-1, 0]], 460, 500, m('t3'));+ prog(q => g.set(gv(rot(180 + 90 * q))), m('t3') + .3, 1.6, io);+ named(p, 'T⁴', [[1, 0], [0, 1]], 760, 260, m('t4'));+ text(p, '= I', 760, 340, m('t4') + 1.5, { size: 28, fill: COL.dim, weight: 600 });+ prog(q => g.set(gv(rot(270 + 90 * q))), m('t4') + .3, 1.6, io);+ text(p, 'A² A = A A² = A³', 90, 820, m('order'), { size: 34, weight: 600 });+ prog(q => g.set(gv(rot(180 * q))), m('order') + 1, 1.6, io); prog(q => g.set(gv(rot(180 + 90 * q))), m('order') + 2.9, 1.2, io);+ }],++ ['q3', 'Your turn', () => {+ const p = panel(0);+ title(p, 'Your turn');+ const t = commute(p, TURN, SHEAR);+ S.P = t.P; S.Q = t.Q;+ }, { ask: done => quiz({ x: 460, y: 470, w: 560, cls: 'side' }, [{+ id: 'c-commute', prompt: ['Change B until AB = BA.'],+ build: mmTask(S.P, (v, C) => same(C, S.Q.C()), 'AB = BA. For a quarter turn A, B must be [a −b; b a]: a turn with a stretch (I and A itself work too).',+ (v, C) => `AB = [${C.flat().map(num).join(' ')}] but BA = [${S.Q.C().flat().map(num).join(' ')}]. Try B with equal diagonal numbers and opposite corners.`,+ () => S.P.set({ b00: 1, b01: 0, b10: 0, b11: 1 }), { only: ['b00', 'b01', 'b10', 'b11'] }),+ }], done) }],++ ['wrap', 'Summary', (m) => {+ const p = panel(0);+ [['Usually AB ≠ BA. AB means: first B, then A.', 'w1'], ['Brackets can move: (AB)C = A(BC).', 'w2'],+ ['Sums spread out: A(B + C) = AB + AC.', 'w3'], ['AI = IA = A; A² = AA: the motion done twice.', '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, ORDQ.map((q, k) => ({+ id: `p-ord${k + 1}`, prompt: ['Both orders. ', ...pairEl(q.A, q.B)],+ build: blanks([+ { parts: ['AB = [', ...boxes(q.AB), ']'], why: `AB = [${q.AB.map(r => r.map(num).join(' ')).join('; ')}].`, hint: 'Entry (i, j): row i of A times column j of B.' },+ { parts: ['BA = [', ...boxes(q.BA), ']'], why: `BA = [${q.BA.map(r => r.map(num).join(' ')).join('; ')}]${same(q.AB, q.BA) ? ': the same, because B is the identity.' : ': not AB.'}`, hint: 'Now B is on the left: row i of B times column j of A.' },+ ]),+ })), done, 'Chapter practice · set 1 of 4') }],+ ['final2', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{+ id: 'p-rules', prompt: ['True for every A, B, C of the same size?'],+ build: grid(RULEQ, [['t', 'True', COL.good, 'T'], ['f', 'False', COL.bad, 'F']], { multi: false, text: true }),+ }], done, 'Chapter practice · set 2 of 4') }],+ ['final3', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{+ id: 'p-pow', prompt: ['Powers. S = ', mmEl(SHEAR), ' T = ', mmEl(TURN), ' D = ', mmEl([[2, 0], [0, 3]])],+ build: blanks([+ { parts: ['S⁴ = [', ...boxes([[1, 4], [0, 1]]), ']'], why: 'Each shear adds one more lean: [1 4; 0 1].', hint: 'S² = [1 2; 0 1], S³ = [1 3; 0 1].' },+ { parts: ['T² = [', ...boxes([[-1, 0], [0, -1]]), ']'], why: 'Two quarter turns: a half turn.', hint: 'T times T: row times column.' },+ { parts: ['T⁸ = [', ...boxes([[1, 0], [0, 1]]), ']'], why: 'T⁴ = I, so T⁸ = I · I = I.', hint: 'Four quarter turns are a full turn.' },+ { parts: ['D³ = [', ...boxes([[8, 0], [0, 27]]), ']'], why: 'A stretch three times: 2·2·2 and 3·3·3.', hint: 'D² = [4 0; 0 9]. One more D.' },+ ]),+ }, {+ id: 'p-assoc', prompt: ['Brackets. A = ', mmEl([[1, 0], [1, 1]]), ' B = ', mmEl([[2, 1], [0, 1]]), ' C = ', mmEl(SHEAR)],+ build: blanks([+ { parts: ['BC = [', ...boxes([[2, 3], [0, 1]]), ']'], why: 'Row 1 (2, 1) times columns (1, 0), (1, 1): 2 and 3.', hint: 'Entry (i, j): row i of B times column j of C.' },+ { parts: ['A(BC) = [', ...boxes([[2, 3], [2, 4]]), ']'], why: 'A adds row 1 to row 2: (2, 3) and (2, 4). (AB)C gives the same.', hint: 'Row 2 of A is (1, 1): row 1 + row 2 of BC.' },+ ]),+ }], done, 'Chapter practice · set 3 of 4') }],+ ['final4', 'Chapter practice', () => {+ const p = panel(0);+ title(p, 'Make AB = BA');+ const t = commute(p, HANDS[0].A, HANDS[0].B);+ S.P = t.P; S.Q = t.Q;+ }, { ask: done => quiz({ x: 460, y: 470, w: 560, cls: 'side' }, HANDS.map((h, k) => ({+ id: `p-hand${k + 1}`, prompt: [h.prompt],+ build: (body, api) => {+ S.P.set({ ...Object.fromEntries(Object.entries(gv(h.A)).map(([kk, v]) => [kk, v])), b00: h.B[0][0], b01: h.B[0][1], b10: h.B[1][0], b11: h.B[1][1] });+ return mmTask(S.P, (v, C) => same(C, S.Q.C()), h.why,+ (v, C) => `AB = [${C.flat().map(num).join(' ')}] but BA = [${S.Q.C().flat().map(num).join(' ')}].`,+ () => S.P.set({ b00: 1, b01: 0, b10: 0, b11: 1 }), { only: ['b00', 'b01', 'b10', 'b11'] })(body, api);+ },+ })), done, 'Chapter practice · set 4 of 4') }],+ ['play', 'Playground', (m, D) => {+ const p = panel(0);+ title(p, 'Playground');+ const t = commute(p, TURN, SHEAR);+ S.P = t.P; S.Q = t.Q;+ const hint = text(p, 'try: A = B · A = I · two stretches · two turns', 60, 170, m('go'), { size: 24, fill: COL.dim });+ hide(hint, Math.min(m('go') + 9, D - .7), .6);+ }, { ask: playAsk(() => S.P, { pos: { x: 460, y: 470, w: 560, cls: 'side' }, tip: 'Change any number of A or B; the right side follows. Compare the planes, or draw on the board.' }) }],+ ['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/mm.js b/site/linear-algebra/lib/mm.jsnew file mode 100644index 0000000..a1b2442--- /dev/null+++ b/site/linear-algebra/lib/mm.js@@ -0,0 +1,410 @@+// Matrix times matrix: A B = AB on one line, every number of A and B scrubbable, the product computed live, and the+// working under it in the way the beat explains: column by column (A times each column of B), entry by entry (row i of+// A times column j of B, multiplied number by number and added), row by row (each row of A mixes the rows of B), and as+// a sum of column-times-row pieces. The sizes stand under each matrix ("2 × 3"); when the inner sizes differ the product+// is refused in red. A grid2 picture can be linked: its x is one column of B, its Ax the same column of AB.+//+// const P = mm(p, { A: [[2, 1], [1, 3]], B: [[1, 2], [1, -1]], at: [70, 300] });+// P.show('cols', 0, at, { times }) // column 1 of B and of AB lit; under them 1·[2;1] + 1·[1;3] = [2;1] + [1;3] = [3;4]+// P.show('entry', [1, 0], at, { times }) // row 2 of A, column 1 of B, entry (2, 1) of AB lit; 1·1 + 3·1 = 1 + 3 = 4+// P.show('rows', 0, at) · P.show('outer', 1, at) · P.show('sum', null, at) · P.show(null, null, at)+// P.to({ b01: 3 }, at, dur) // beat clock: numbers (and sizes mA nA nB pB) move, the product follows+// P.reveal({ col: 0 }, at) // with hideC: true the product shows ? until revealed ('all', {col}, {row}, {cell: [i, j]})+// P.link(g, { col: 0 }) // a grid2 made with x: A and column `col` of B drive it, its drags drive them+// P.live(true, { only: ['b01', 'b11'], sizes: false }) // hands on; mmTask is the question type; playAsk works+//+// Keys: a<i><j>, b<i><j> (rows and columns from 0), the sizes mA × nA and nB × pB (1 … 3). Loads after engine.js.+const MM_ROW = [COL.whole, COL.nat, COL.int], MM_COL = [COL.irr, COL.real, COL.rat];++// exact numbers at rest, one decimal while they move+const mmParts = v => { const r = Math.round(v); return [num(Math.abs(v - r) < 1e-9 ? r : Math.round(v * 10) / 10)]; };+const mmKey = ps => ps.join('');+// a factor in a product: negatives in brackets, as chapter 9 writes them+const mmFac = v => v < -1e-9 ? ['(', ...mmParts(v), ')'] : mmParts(v);+// a sum of numbers as it is read: 6 − 2 + 0+const mmSum = vs => vs.flatMap((v, k) => k === 0 ? mmParts(v) : [v < -1e-9 ? ' − ' : ' + ', ...mmParts(Math.abs(v))]);++// A small matrix in brackets inside a group, its middle at ymid; fill(i, j) colours each number. Returns the width.+function mmSmall(g, rows, x, ymid, { size = 30, fill = () => COL.chalk, cw = null, rhk = 1.22 } = {}) {+ const n = rows.length, m = rows[0].length, rh = size * rhk;+ const w0 = Math.max(...rows.flat().map(v => mmKey(mmParts(v)).length));+ const c = cw || size * (.55 * w0 + .75), W = m * c + 20;+ const top = ymid - n * rh / 2 - 2, bot = ymid + n * rh / 2 + 2;+ path(g, `M${x + 9} ${top}H${x}V${bot}H${x + 9}M${x + W - 9} ${top}H${x + W}V${bot}H${x + W - 9}`, { stroke: COL.chalk, 'stroke-width': 2.5, fill: 'none' });+ rows.forEach((r, i) => r.forEach((v, j) => M(g, mmParts(v), { x: x + 10 + c * (j + .5), y: ymid - n * rh / 2 + (i + .5) * rh + size * .36, size, fill: fill(i, j), anchor: 'middle' })));+ return W;+}++// The same as an HTML element, for prompts and grids.+function mmEl(rows, { size = 26, fill = () => 'currentColor' } = {}) {+ const n = rows.length, m = rows[0].length, cw = size * 1.7, rh = size * 1.3, w = cw * m + 16, hh = rh * n + size * .3;+ const svg = mk('svg', { class: 'm', viewBox: `0 0 ${w} ${hh}`, width: w, height: hh });+ svg.style.verticalAlign = 'middle';+ path(svg, `M12 2H3V${hh - 2}H12M${w - 12} 2H${w - 3}V${hh - 2}H${w - 12}`, { stroke: 'currentColor', 'stroke-width': 2.5, fill: 'none' });+ rows.forEach((r, i) => r.forEach((v, j) => T(svg, num(v), { x: 8 + cw * (j + .5), y: rh * (i + .5) + size * .5, size, fill: fill(i, j), font: MATH, anchor: 'middle' })));+ return svg;+}++function mm(p, { A, B, at: [x0, y0] = [70, 300], size = 40, cw = 62, cwC = null, rh = 60, gap = 44, names = ['A', 'B', 'AB'],+ tintA = null, tintB = null, hideC = false, fillC = COL.task, t0 = .1, work: wpos = null, wsize = 30, sizes = true, o = 0, range = 9 } = {}) {+ const svg = $('stage'), K3 = [0, 1, 2];+ const s = { mA: A.length, nA: A[0].length, nB: B.length, pB: B[0].length };+ K3.forEach(i => K3.forEach(j => { s[`a${i}${j}`] = A[i]?.[j] ?? 0; s[`b${i}${j}`] = B[i]?.[j] ?? 0; }));+ let plan = { ...s };+ const known = K3.map(() => K3.map(() => !hideC));+ const g = G(p, { o });+ show(g, t0 + .2);+ const cwc = cwC || cw * 1.2;+ const D = () => ({ mA: Math.round(s.mA), nA: Math.round(s.nA), nB: Math.round(s.nB), pB: Math.round(s.pB) });+ const prod = () => {+ const { mA, nA, nB, pB } = D();+ if (nA !== nB) return null;+ return [...Array(mA).keys()].map(i => [...Array(pB).keys()].map(j => [...Array(nA).keys()].reduce((t, k) => t + s[`a${i}${k}`] * s[`b${k}${j}`], 0)));+ };+ const tint = (t, i, j) => t === 'cols' ? MM_COL[j] : t === 'rows' ? MM_ROW[i] : COL.chalk;+ const hitOf = which => (i, j) => which === 'all' || which.col === j || which.row === i || (!!which.cell && which.cell[0] === i && which.cell[1] === j);++ /* ---------- hands on: each box takes its own drag and keys (boxes are rebuilt when a size changes) ---------- */+ const cells = []; // every scrubbable box: { k, box }+ let live = false, allowed = null, sizesLive = false;+ const can = k => live && (k.length === 2 ? sizesLive : (!allowed || allowed.has(k)));+ const step = (k, v) => edit({ [k]: k.length === 2 ? Math.round(v) : Math.max(-range, Math.min(range, Math.round(v))) });+ function wire(box, k) {+ box.setAttribute('aria-label', k);+ cells.push({ k, box });+ let drag = null;+ box.addEventListener('pointerdown', e => {+ if (!can(k)) return;+ e.preventDefault(); drag = { x: e.clientX, from: Math.round(s[k]) }; box.setPointerCapture(e.pointerId);+ if (k.length === 3) follow(k);+ });+ box.addEventListener('pointermove', e => { if (!drag) return; const kx = svg.getScreenCTM().a; step(k, drag.from + Math.round((e.clientX - drag.x) / kx / (k.length === 2 ? 40 : 24))); });+ const end = () => { drag = null; };+ box.addEventListener('pointerup', end); box.addEventListener('lostpointercapture', end);+ box.addEventListener('keydown', e => {+ if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); box.blur(); P.keys?.(e); return; }+ if (!can(k)) return;+ const dd = { ArrowUp: 1, ArrowRight: 1, ArrowDown: -1, ArrowLeft: -1 }[e.key];+ if (!dd) return;+ e.preventDefault(); e.stopPropagation();+ if (k.length === 3) follow(k);+ step(k, Math.round(s[k]) + dd);+ if (!box.isConnected) g.querySelector(`[aria-label="${k}"][tabindex]`)?.focus(); // a size change rebuilt the boxes+ });+ }+ function boxesLive() {+ cells.forEach(c => {+ const ok = can(c.k);+ c.box.style.cursor = ok ? 'ew-resize' : '';+ c.box.setAttribute('stroke', ok ? COL.faint : 'none');+ if (ok) c.box.setAttribute('tabindex', 0); else c.box.removeAttribute('tabindex');+ });+ }++ /* ---------- the three matrices (rebuilt when a size changes) ---------- */+ const body = G(g, {});+ let L = null, shape = '', innerOn = false, outerOn = false;+ function mat(key, rows, cols, x, c, tn, name) {+ const mg = G(body, {}), back = G(mg, {});+ const top = y0 - size * .95, bot = y0 + (rows - 1) * rh + size * .35, W = cols * c + 24;+ path(mg, `M${x + 13} ${top}H${x}V${bot}H${x + 13}M${x + W - 13} ${top}H${x + W}V${bot}H${x + W - 13}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });+ const cx = j => x + 12 + c * (j + .5), ry = i => y0 + i * rh;+ const cs = [...Array(rows).keys()].map(i => [...Array(cols).keys()].map(j => {+ const cg = G(mg, { x: cx(j), y: ry(i) });+ const glow = mk('rect', { x: -c / 2 + 3, y: -size * .9, width: c - 6, height: size * 1.2, rx: 10, fill: COL.chalk }, cg);+ put(glow, { o: 0 });+ const holder = G(cg, {});+ holder.style.pointerEvents = 'none';+ if (key !== 'c') wire(mk('rect', { x: -c / 2 + 3, y: -size * .92, width: c - 6, height: size * 1.24, rx: 9, fill: 'transparent', 'stroke-dasharray': '4 6' }, cg), `${key}${i}${j}`);+ return { k: `${key}${i}${j}`, glow, holder, txt: null, fill: key === 'c' ? fillC : tint(tn, i, j) };+ }));+ M(mg, [name], { x: x + W / 2, y: top - 16, size: 28, fill: COL.dim, anchor: 'middle' });+ return { g: mg, back, x, W, top, bot, cx, ry, c, cs, rows, cols };+ }+ // the size under a matrix: "2 × 3", each number scrubbable when sizes are live+ function sizeLab(m, kr, kc, rows, cols, yS) {+ const mid = m.x + m.W / 2, sg = G(body, {});+ const part = (k, v, dx) => {+ const t = T(sg, String(v), { x: mid + dx, y: yS, size: 28, fill: COL.dim, font: MATH, anchor: 'middle', weight: 600 });+ t.style.pointerEvents = 'none';+ if (k) wire(mk('rect', { x: mid + dx - 20, y: yS - 26, width: 40, height: 34, rx: 8, fill: 'transparent', 'stroke-dasharray': '4 5' }, sg), k);+ return t;+ };+ part(kr, rows, -30); part(kc, cols, 30);+ T(sg, '×', { x: mid, y: yS, size: 26, fill: COL.dim, font: MATH, anchor: 'middle' });+ return { g: sg, y: yS, xr: mid - 30, xc: mid + 30 };+ }+ function layout() {+ const d = D(), sh = [d.mA, d.nA, d.nB, d.pB].join();+ if (sh === shape) return;+ shape = sh;+ body.replaceChildren(); cells.length = 0;+ const a = mat('a', d.mA, d.nA, x0, cw, tintA, names[0]);+ const b = mat('b', d.nB, d.pB, a.x + a.W + gap, cw, tintB, names[1]);+ const eqx = b.x + b.W + 40, cx0 = eqx + 40;+ const midY = y0 + (Math.max(d.mA, d.nB) - 1) * rh / 2 + size * .3;+ const eq = M(body, ['='], { x: eqx, y: midY, size: size * 1.1, fill: COL.chalk, anchor: 'middle' });+ const ok = d.nA === d.nB;+ const c = ok ? mat('c', d.mA, d.pB, cx0, cwc, null, names[2]) : null;+ const yS = y0 + (Math.max(d.mA, d.nB) - 1) * rh + size * .35 + 42;+ const sa = sizeLab(a, 'mA', 'nA', d.mA, d.nA, yS), sb = sizeLab(b, 'nB', 'pB', d.nB, d.pB, yS);+ const sc = ok ? sizeLab(c, null, null, d.mA, d.pB, yS) : null;+ const sz = G(body, {});+ [sa, sb, sc].forEach(q => q && sz.append(q.g));+ if (!sizes) put(sz, { o: 0 });+ // the inner sizes joined under the matrices: they must match+ const yA = yS + 14, inner = G(sz, { o: innerOn || !ok ? 1 : 0 });+ path(inner, `M${sa.xc} ${yA}V${yA + 22}H${sb.xr}V${yA}`, { stroke: ok ? COL.good : COL.bad, 'stroke-width': 3, fill: 'none' });+ T(inner, ok ? 'must match' : `${d.nA} ≠ ${d.nB}`, { x: (sa.xc + sb.xr) / 2, y: yA + 52, size: 24, fill: ok ? COL.good : COL.bad, anchor: 'middle', weight: 600 });+ // the outer sizes give the size of the answer+ const outer = G(sz, { o: outerOn && ok ? 1 : 0 });+ if (ok) [sa.xr, sb.xc, sc.xr, sc.xc].forEach(x => mk('ellipse', { cx: x, cy: yS - 9, rx: 19, ry: 21, fill: 'none', stroke: COL.task, 'stroke-width': 2.5 }, outer));+ // the refusal where the product would be+ let no = null;+ if (!ok) {+ no = G(body, {});+ const top = y0 - size * .95, hh = Math.max(d.mA, d.nB) * rh + 10;+ mk('rect', { x: cx0, y: top, width: 330, height: hh, rx: 14, fill: COL.bad, 'fill-opacity': .1, stroke: COL.bad, 'stroke-width': 3, 'stroke-dasharray': '8 6' }, no);+ T(no, 'no product', { x: cx0 + 165, y: top + hh / 2 - 4, size: 34, fill: COL.bad, anchor: 'middle', weight: 700 });+ T(no, `a row of ${names[0]} has ${d.nA}, a column of ${names[1]} has ${d.nB}`, { x: cx0 + 165, y: top + hh / 2 + 32, size: 19, fill: COL.bad, anchor: 'middle', weight: 600 });+ }+ L = { a, b, c, eq, ok, sz, inner, outer, no, sa, sb, sc, right: ok ? c.x + c.W : cx0 + 330, bottom: yA + 66 };+ rebands();+ boxesLive();+ }++ /* ---------- lit rows, columns and entries ---------- */+ // Each show() lights its parts from its time until the next show(): a soft band behind the numbers.+ let lit = []; // [{ m: 'a' | 'b' | 'c', kind: 'row' | 'col' | 'cell', i, j, e }]+ const bandRect = (m, kind, i, j) => {+ if (!m || (kind !== 'col' && i >= m.rows) || (kind !== 'row' && j >= m.cols)) return null;+ const h0 = size * 1.24;+ let x, y, w, hh;+ if (kind === 'row') { x = m.x + 4; y = m.ry(i) - size * .95; w = m.W - 8; hh = h0; }+ else if (kind === 'col') { x = m.cx(j) - m.c / 2 + 2; y = m.top + 2; w = m.c - 4; hh = m.bot - m.top - 4; }+ else { x = m.cx(j) - m.c / 2 + 2; y = m.ry(i) - size * .95; w = m.c - 4; hh = h0; }+ return mk('rect', { x: x - 3, y, width: w + 6, height: hh, rx: 12, fill: COL.chalk, 'fill-opacity': .13, stroke: COL.chalk, 'stroke-opacity': .6, 'stroke-width': 2.5 }, m.back);+ };+ function rebands() { lit.forEach(b => { b.e = bandRect(L[b.m], b.kind, b.i, b.j); }); }+ const partsOf = (mode, idx) => mode === 'cols' ? [['b', 'col', 0, idx], ['c', 'col', 0, idx]]+ : mode === 'entry' ? [['a', 'row', idx[0], 0], ['b', 'col', 0, idx[1]], ['c', 'cell', idx[0], idx[1]]]+ : mode === 'rows' ? [['a', 'row', idx, 0], ['c', 'row', idx, 0]]+ : mode === 'outer' ? [['a', 'col', 0, idx], ['b', 'row', idx, 0]] : [];+ const setLit = (mode, idx) => {+ lit.forEach(b => b.e?.remove());+ lit = partsOf(mode, idx).map(([m, kind, i, j]) => ({ m, kind, i, j }));+ rebands();+ };++ /* ---------- the working ---------- */+ const W = G(g, {});+ let wMode = null, wIdx = null, wN = 99, wKey = '';+ const wx = () => wpos ? wpos[0] : x0, wy = () => wpos ? wpos[1] : L.bottom + 84;+ function drawWork() {+ const C = prod();+ if (wMode === null || !C) { if (wKey) { W.replaceChildren(); wKey = ''; } return; }+ const d = D(), n = d.nA;+ const Arow = r => [...Array(n).keys()].map(k => s[`a${r}${k}`]), Bcol = j => [...Array(n).keys()].map(k => s[`b${k}${j}`]);+ const Brow = k => [...Array(d.pB).keys()].map(j => s[`b${k}${j}`]), Acol = k => [...Array(d.mA).keys()].map(i => s[`a${i}${k}`]);+ const kk = [wMode, JSON.stringify(wIdx), wN, shape, ...K3.flatMap(i => K3.flatMap(j => [s[`a${i}${j}`], s[`b${i}${j}`]])).map(v => mmKey(mmParts(v)))].join('|');+ if (kk === wKey) return;+ wKey = kk;+ W.replaceChildren();+ const y = wy(), fs = wsize;+ let x = wx();+ const txt = (st, str, fill = COL.chalk) => { if (st > wN) return; const e = M(W, [].concat(str), { x, y: y + fs * .36, size: fs, fill, anchor: 'start' }); x += (e._w || 20) + 10; };+ const sm = (st, rows, fill) => { if (st > wN) return; x += mmSmall(W, rows, x, y, { size: fs, fill }) + 10; };+ const tall = Math.max(wMode === 'rows' ? 1 : d.mA, 1);+ const cap = str => T(W, str, { x: wx(), y: y - Math.max(48, tall * fs * .55 + 30), size: 24, fill: COL.dim, weight: 600 });+ const col = v => v.map(q => [q]);+ const [nA, nB, nC] = names;+ if (wMode === 'cols') {+ const j = wIdx, xs = Bcol(j);+ cap(`column ${j + 1} of ${nC} = ${nA} times column ${j + 1} of ${nB}`);+ xs.forEach((v, k) => { if (k) txt(1, '+'); txt(1, [...mmFac(v), '·']); sm(1, col(Acol(k)), () => tint(tintA, 0, k)); });+ txt(2, '=');+ xs.forEach((v, k) => { if (k) txt(2, '+'); sm(2, col(Acol(k).map(a => a * v)), () => tint(tintA, 0, k)); });+ txt(3, '='); sm(3, col(C.map(r => r[j])), () => fillC);+ } else if (wMode === 'entry') {+ const [i, j] = wIdx, a = Arow(i), b = Bcol(j);+ cap(`entry (${i + 1}, ${j + 1}) of ${nC} = row ${i + 1} of ${nA} times column ${j + 1} of ${nB}`);+ txt(1, a.flatMap((v, k) => [...(k ? [' + '] : []), ...mmFac(v), '·', ...mmFac(b[k])]));+ txt(2, ['=', ' ', ...mmSum(a.map((v, k) => v * b[k]))]);+ txt(3, '='); txt(3, mmParts(C[i][j]), fillC);+ } else if (wMode === 'rows') {+ const i = wIdx, a = Arow(i);+ cap(`row ${i + 1} of ${nC} = row ${i + 1} of ${nA} times ${nB}: a mix of the rows of ${nB}`);+ a.forEach((v, k) => { if (k) txt(1, '+'); txt(1, [...mmFac(v), '·']); sm(1, [Brow(k)], () => tint(tintB, k, 0)); });+ txt(2, '=');+ a.forEach((v, k) => { if (k) txt(2, '+'); sm(2, [Brow(k).map(b => b * v)], () => tint(tintB, k, 0)); });+ txt(3, '='); sm(3, [C[i]], () => fillC);+ } else if (wMode === 'outer') {+ const k = wIdx;+ cap(`column ${k + 1} of ${nA} times row ${k + 1} of ${nB}: a whole matrix`);+ sm(1, col(Acol(k)), () => tint(tintA, 0, k)); sm(1, [Brow(k)], () => tint(tintB, k, 0));+ txt(2, '='); sm(2, Acol(k).map(a => Brow(k).map(b => a * b)), () => COL.chalk);+ } else if (wMode === 'sum') {+ cap(`${nC} = (column 1)(row 1) + (column 2)(row 2)${n > 2 ? ' + (column 3)(row 3)' : ''}`);+ [...Array(n).keys()].forEach(k => { if (k) txt(1, '+'); sm(1, Acol(k).map(a => Brow(k).map(b => a * b)), () => COL.chalk); });+ txt(2, '='); sm(2, C, () => fillC);+ }+ }++ // Light the parts that the way uses and write its working, from `at` until the next show; times: [t1, t2, t3] brings+ // in the working's pieces one at a time (the terms, the products, the answer; for 'outer' and 'sum' two pieces).+ // The latest show by time wins, so seeking and playing give the same frame.+ let bandStamp = -1, workStamp = -1;+ function showWay(mode, idx, at, { times = null, dur = .35 } = {}) {+ const t1 = times ? times[0] : at;+ const ev = (t, f) => prog(q => { if (q > 0 && t >= workStamp) { workStamp = t; f(); } }, t, 0, lin);+ prog(q => { if (q > 0 && at >= bandStamp) { bandStamp = at; setLit(mode, idx); lit.forEach(b => b.e && put(b.e, { o: 0 })); } }, at, 0, lin);+ prog(q => { if (bandStamp === at) lit.forEach(b => b.e && put(b.e, { o: q })); }, at, dur, lin);+ ev(t1, () => { wMode = mode; wIdx = idx; wN = times ? 1 : 99; wKey = ''; drawWork(); });+ if (times) times.slice(1).forEach((t, k) => ev(t, () => { wN = k + 2; wKey = ''; drawWork(); }));+ }++ /* ---------- a linked grid2: A moves the plane, x is a column of B, Ax that column of AB ---------- */+ let pic = null, picCol = 0, quiet = false, picStamp = -1;+ // cols: x is column picCol of B (the plane's matrix is A). rows: x is row picCol of A (the plane's matrix has the rows+ // of B as its columns), Ax is that row of AB.+ const fits = () => { const d = D(); return d.nA === 2 && d.nB === 2 && (pic?.rows ? d.pB === 2 && picCol < d.mA : d.mA === 2 && picCol < d.pB); };+ function syncPic() {+ if (!pic || !fits()) return;+ quiet = true;+ const c = picCol;+ pic.g.set(pic.rows ? { a00: s.b00, a01: s.b10, a10: s.b01, a11: s.b11, x0: s[`a${c}0`], x1: s[`a${c}1`] }+ : { a00: s.a00, a01: s.a01, a10: s.a10, a11: s.a11, x0: s[`b0${c}`], x1: s[`b1${c}`] });+ quiet = false;+ if (pic.dots) {+ const C = prod(), d = D(), n = pic.rows ? d.mA : d.pB;+ pic.dots.forEach((dt, j) => {+ const on = j < n;+ dt.style.display = on ? '' : 'none';+ if (on) put(dt, pic.rows ? { x: pic.g.P.PX(C[j][0]), y: pic.g.P.PY(C[j][1]) } : { x: pic.g.P.PX(C[0][j]), y: pic.g.P.PY(C[1][j]) });+ });+ }+ }+ // a number the reader touches brings its column of B (or row of A) into the picture+ function follow(k) { if (pic && (pic.rows ? k[0] === 'a' : k[0] === 'b')) followCol(+(pic.rows ? k[1] : k[2])); }+ function followCol(j) { if (pic && j !== picCol) { picCol = j; syncPic(); } }++ /* ---------- numbers ---------- */+ const listeners = [];+ function draw() {+ layout();+ const C = prod();+ [L.a, L.b].forEach(m => m.cs.flat().forEach(cl => {+ const ps = mmParts(s[cl.k]), kk = mmKey(ps);+ if (kk === cl.txt) return;+ cl.txt = kk; cl.holder.replaceChildren();+ M(cl.holder, ps, { size, fill: cl.fill, anchor: 'middle' });+ }));+ if (L.c) L.c.cs.forEach((r, i) => r.forEach((cl, j) => {+ const ps = known[i][j] ? mmParts(C[i][j]) : ['?'], kk = mmKey(ps);+ if (kk === cl.txt) return;+ cl.txt = kk; cl.holder.replaceChildren();+ M(cl.holder, ps, { size, fill: known[i][j] ? cl.fill : COL.dim, anchor: 'middle' });+ }));+ drawWork();+ syncPic();+ listeners.forEach(f => f(s));+ }+ function edit(to) {+ let ch = false;+ for (const k in to) {+ const v = k.length === 2 ? Math.max(1, Math.min(3, to[k])) : to[k];+ if (s[k] !== v) { s[k] = v; ch = true; }+ }+ if (ch) draw();+ }++ draw();+ const api = {+ g, W, get L() { return L; }, get v() { return { ...s }; }, get plan() { return plan; },+ C: prod,+ set(vals) { edit(vals); },+ // Move numbers (and sizes) over dur seconds on the beat clock; the product, the working and the picture follow.+ // Sizes jump at the end of the move.+ to(next, at, dur = 1.4, ease = io) {+ const from = { ...plan };+ plan = { ...plan, ...next };+ const goal = { ...plan }, ks = Object.keys(next);+ prog(q => edit(Object.fromEntries(ks.map(k => [k, k.length === 2 ? (q < 1 ? from[k] : goal[k]) : from[k] + (goal[k] - from[k]) * q]))), at, dur, ease);+ return at + dur;+ },+ show: showWay,+ // the product's ? turn into numbers at `at`: 'all', { col: j }, { row: i } or { cell: [i, j] }+ reveal(which, at, { flash = true } = {}) {+ prog(q => { if (q > 0) api.uncover(which); }, at, 0, lin);+ if (flash) api.flash('c', which, at);+ },+ // the same at once (an answer shown inside a question)+ uncover(which) {+ const hit = hitOf(which);+ K3.forEach(i => K3.forEach(j => { if (hit(i, j)) known[i][j] = true; }));+ L.c?.cs.flat().forEach(cl => { cl.txt = null; });+ draw();+ },+ // a short glow behind numbers: m 'a' | 'b' | 'c', which as for reveal+ flash(m, which, at, { color = COL.chalk } = {}) {+ const hit = hitOf(which), env = t => t < .25 ? t / .25 : t < 1.1 ? 1 : t < 1.7 ? 1 - (t - 1.1) / .6 : 0;+ // the cells are looked up as the glow runs, so a flash still lands after a size change rebuilt them+ prog(q => L[m]?.cs.forEach((r, i) => r.forEach((cl, j) => {+ if (!hit(i, j)) return;+ cl.glow.setAttribute('fill', color);+ put(cl.glow, { o: .32 * env(q * 1.7) });+ })), at, 1.7, lin);+ },+ // the inner sizes joined ("must match"), and the outer sizes ringed (the size of the answer), from `at`+ inner(at, on = true) { prog(q => { if (q > 0) { innerOn = on; put(L.inner, { o: on || !L.ok ? 1 : 0 }); } }, at, 0, lin); },+ outer(at, on = true) { prog(q => { if (q > 0) { outerOn = on; put(L.outer, { o: on && L.ok ? 1 : 0 }); } }, at, 0, lin); },+ live(on, { only = null, sizes: sz = false } = {}) {+ live = on; allowed = on && only ? new Set(only) : null; sizesLive = on && sz;+ const bc = only?.find(k => k[0] === (pic?.rows ? 'a' : 'b'));+ if (bc) follow(bc);+ boxesLive();+ if (pic) {+ const what = [];+ const [ka, kx] = pic.rows ? ['b', 'a'] : ['a', 'b'];+ if (on && (!only || only.some(k => k[0] === ka))) what.push('cols');+ if (on && (!only || only.some(k => k[0] === kx))) what.push('x');+ pic.g.live(on && what.length > 0, what);+ }+ },+ onChange(f) { listeners.push(f); },+ // Link a grid2 (made with x) so that its matrix is A and its x is column `col` of B; with dots, every column of+ // AB is an amber dot labelled with its number. linkCol(j, at) moves x to another column on the beat clock.+ // With rows: true the plane shows the row way: its arrows are the rows of B, x is row `col` of A, Ax that row of AB.+ link(gr, { col = 0, dots = false, rows = false } = {}) {+ picCol = col;+ pic = { g: gr, dots: null, rows };+ if (dots) {+ pic.dotsG = G(gr.P.g, {});+ pic.dotsG.style.pointerEvents = 'none'; // never over a handle+ pic.dots = K3.map(j => { const d0 = G(pic.dotsG, {}); mk('circle', { r: 9, fill: COL.task, stroke: COL.board, 'stroke-width': 2.5 }, d0); T(d0, `${j + 1}`, { x: 15, y: 24, size: 20, fill: COL.task, weight: 700, anchor: 'middle' }); return d0; });+ }+ gr.onChange(v => {+ if (quiet || !live || !fits()) return;+ const c = picCol;+ edit(pic.rows ? { b00: v.a00, b10: v.a01, b01: v.a10, b11: v.a11, [`a${c}0`]: v.x0, [`a${c}1`]: v.x1 }+ : { a00: v.a00, a01: v.a01, a10: v.a10, a11: v.a11, [`b0${c}`]: v.x0, [`b1${c}`]: v.x1 });+ });+ syncPic();+ return pic;+ },+ linkCol(j, at) { prog(q => { if (q > 0 && at >= picStamp) { picStamp = at; picCol = j; syncPic(); } }, at, 0, lin); },+ get col() { return picCol; },+ };+ return api;+}++// A question on the numbers (and sizes) of A B: the reader scrubs the keys in only until test(v, AB) holds.+const mmTask = (P_, test, why, hint, reveal, { only = null, sizes = false } = {}) => (body, api) => {+ P_.live(true, { only, sizes });+ return {+ check: () => { const v = P_.v, C = P_.C(), ok = !!C && test(v, C); api.grade(ok, ok ? why : typeof hint === 'function' ? hint(v, C) : hint); },+ reveal: () => { reveal?.(); return why; },+ lock: () => P_.live(false),+ hint: [kbd('Tab'), ' to a number, ', kbd('↑'), kbd('↓'), ' to change it, or drag it sideways'],+ };+};