Skip to content

An AI skill that turns books into animated, narrated, interactive web experiences

feat(linear-algebra): chapters 20-22 and emat.js finish Unit 2

yzre1f5cabdc544
diff --git a/site/linear-algebra/ch20/audio/en/decide.mp3 b/site/linear-algebra/ch20/audio/en/decide.mp3
new file mode 100644
index 0000000..cbd8f2a
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/decide.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/final1.mp3 b/site/linear-algebra/ch20/audio/en/final1.mp3
new file mode 100644
index 0000000..6fde7ed
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/final2.mp3 b/site/linear-algebra/ch20/audio/en/final2.mp3
new file mode 100644
index 0000000..3ed99c6
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/final3.mp3 b/site/linear-algebra/ch20/audio/en/final3.mp3
new file mode 100644
index 0000000..a45b1e6
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/final4.mp3 b/site/linear-algebra/ch20/audio/en/final4.mp3
new file mode 100644
index 0000000..451d34d
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/finish.mp3 b/site/linear-algebra/ch20/audio/en/finish.mp3
new file mode 100644
index 0000000..9c35958
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/intro.mp3 b/site/linear-algebra/ch20/audio/en/intro.mp3
new file mode 100644
index 0000000..4b72248
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/many.mp3 b/site/linear-algebra/ch20/audio/en/many.mp3
new file mode 100644
index 0000000..019156e
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/many.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/none.mp3 b/site/linear-algebra/ch20/audio/en/none.mp3
new file mode 100644
index 0000000..1953e1a
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/none.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/planes.mp3 b/site/linear-algebra/ch20/audio/en/planes.mp3
new file mode 100644
index 0000000..d84cb36
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/planes.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/planes2.mp3 b/site/linear-algebra/ch20/audio/en/planes2.mp3
new file mode 100644
index 0000000..92278ea
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/planes2.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/play.mp3 b/site/linear-algebra/ch20/audio/en/play.mp3
new file mode 100644
index 0000000..6bee053
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/play.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/q1.mp3 b/site/linear-algebra/ch20/audio/en/q1.mp3
new file mode 100644
index 0000000..99aed66
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/q2.mp3 b/site/linear-algebra/ch20/audio/en/q2.mp3
new file mode 100644
index 0000000..aaa86d0
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/q3.mp3 b/site/linear-algebra/ch20/audio/en/q3.mp3
new file mode 100644
index 0000000..c085d00
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/swap.mp3 b/site/linear-algebra/ch20/audio/en/swap.mp3
new file mode 100644
index 0000000..a64ad69
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/swap.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/timings.js b/site/linear-algebra/ch20/audio/en/timings.js
new file mode 100644
index 0000000..86257b7
--- /dev/null
+++ b/site/linear-algebra/ch20/audio/en/timings.js
@@ -0,0 +1,820 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 11.952,
+ "marks": {
+ "sub": 3.333,
+ "move": 9.518
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter twenty."
+ ],
+ [
+ 1.328,
+ "When elimination breaks down."
+ ],
+ [
+ 3.333,
+ "Until now, elimination has worked every time."
+ ],
+ [
+ 6.901,
+ "In this chapter we see what can go wrong, and when a simple swap puts it right."
+ ]
+ ]
+ },
+ "zero": {
+ "dur": 53.952,
+ "marks": {
+ "eq": 2.552,
+ "meet": 8.06,
+ "piv": 9.935,
+ "div": 16.341,
+ "try": 21.706,
+ "l1": 23.789,
+ "l2": 28.815,
+ "l3": 35.169,
+ "stays": 41.289,
+ "none": 51.445
+ },
+ "cues": [
+ [
+ 0.117,
+ "Here is a system that starts badly."
+ ],
+ [
+ 2.552,
+ "Zero x plus two y equals four, and three x plus y equals five."
+ ],
+ [
+ 8.06,
+ "The lines meet at one, two."
+ ],
+ [
+ 9.935,
+ "Elimination looks at the pivot, the first number of row one."
+ ],
+ [
+ 13.945,
+ "Here the pivot spot holds a zero."
+ ],
+ [
+ 16.341,
+ "The multiplier would be three divided by zero."
+ ],
+ [
+ 19.388,
+ "But nobody can divide by zero."
+ ],
+ [
+ 21.706,
+ "Let's try some multipliers anyway."
+ ],
+ [
+ 23.789,
+ "Take away one times row one: three x minus y equals one."
+ ],
+ [
+ 28.815,
+ "Take away two times row one: three x minus three y equals minus three."
+ ],
+ [
+ 35.169,
+ "Take away minus one times row one: three x plus three y equals nine."
+ ],
+ [
+ 41.289,
+ "The line turns about the meeting point, but the three x never changes."
+ ],
+ [
+ 45.99,
+ "Row one has zero x, and any number times zero is still zero."
+ ],
+ [
+ 51.445,
+ "No multiplier can remove that three."
+ ]
+ ]
+ },
+ "swap": {
+ "dur": 47.712,
+ "marks": {
+ "order": 1.589,
+ "swap": 7.148,
+ "same": 8.646,
+ "piv": 19.414,
+ "zero": 21.341,
+ "y": 27.956,
+ "x": 32.669,
+ "temp": 39.492
+ },
+ "cues": [
+ [
+ 0.117,
+ "The way out is simple."
+ ],
+ [
+ 1.589,
+ "A system asks for both equations at once, so the order we write them in doesn't matter."
+ ],
+ [
+ 7.148,
+ "Swap the two rows."
+ ],
+ [
+ 8.646,
+ "Nothing in the picture moves: the same two lines, the same meeting point."
+ ],
+ [
+ 13.398,
+ "Only their names trade places."
+ ],
+ [
+ 15.547,
+ "The blue line is now three x plus y equals five."
+ ],
+ [
+ 19.414,
+ "Now the pivot is three."
+ ],
+ [
+ 21.341,
+ "And under it there is already a zero: no x to remove."
+ ],
+ [
+ 25.729,
+ "The table is already a triangle."
+ ],
+ [
+ 27.956,
+ "Back substitution: two y equals four, so y equals two."
+ ],
+ [
+ 32.669,
+ "Then three x plus two equals five, so three x equals three, and x equals one."
+ ],
+ [
+ 39.492,
+ "This is called a row exchange."
+ ],
+ [
+ 41.523,
+ "The zero in the pivot spot was only temporary trouble, because a row below had a number to put there."
+ ]
+ ]
+ },
+ "zero3": {
+ "dur": 65.16,
+ "marks": {
+ "eq": 3.607,
+ "c1": 15.781,
+ "s21": 18.789,
+ "s31": 24.245,
+ "zero": 30.065,
+ "below": 35.846,
+ "swap": 37.995,
+ "tri": 43.659,
+ "z": 49.05,
+ "y": 52.578,
+ "x": 56.901,
+ "pt": 61.979
+ },
+ "cues": [
+ [
+ 0.104,
+ "The same thing can happen in the middle of elimination."
+ ],
+ [
+ 3.607,
+ "Here are three equations: x plus two y plus z equals one, two x plus four y plus three z equals three, and three x plus seven y plus five z equals four."
+ ],
+ [
+ 15.781,
+ "Column one is fine: the pivot is one."
+ ],
+ [
+ 18.789,
+ "Row two minus two times row one gives zero, zero, one, and one."
+ ],
+ [
+ 24.245,
+ "Row three minus three times row one gives zero, one, two, and one."
+ ],
+ [
+ 30.065,
+ "Now look at column two."
+ ],
+ [
+ 31.576,
+ "The second pivot spot, in row two, holds a zero."
+ ],
+ [
+ 35.846,
+ "But row three has a one under it."
+ ],
+ [
+ 37.995,
+ "So swap rows two and three."
+ ],
+ [
+ 40.43,
+ "The planes don't move; only the order changes."
+ ],
+ [
+ 43.659,
+ "And look: the table is now a triangle, with pivots one, one and one."
+ ],
+ [
+ 49.05,
+ "Back substitution from the bottom: z equals one."
+ ],
+ [
+ 52.578,
+ "Then y plus two equals one, so y equals minus one."
+ ],
+ [
+ 56.901,
+ "And x minus two plus one equals one, so x equals two."
+ ],
+ [
+ 61.979,
+ "The three planes meet at two, minus one, one."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 5.376,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.081,
+ "The pivot spot holds a zero."
+ ],
+ [
+ 3.138,
+ "Swap the rows, then solve."
+ ]
+ ]
+ },
+ "none": {
+ "dur": 57.624,
+ "marks": {
+ "eq": 1.693,
+ "par": 6.719,
+ "l": 15.156,
+ "two": 21.185,
+ "go": 25.547,
+ "run": 27.448,
+ "gone": 32.878,
+ "row": 33.88,
+ "zero": 38.216,
+ "none": 46.289,
+ "perm": 48.997
+ },
+ "cues": [
+ [
+ 0.065,
+ "Now a different kind of trouble."
+ ],
+ [
+ 1.693,
+ "x plus two y equals one, and two x plus four y equals six."
+ ],
+ [
+ 6.719,
+ "You may know these lines from chapter three: the same tilt, different right sides."
+ ],
+ [
+ 11.615,
+ "They're parallel."
+ ],
+ [
+ 12.734,
+ "But let's see what elimination says."
+ ],
+ [
+ 15.156,
+ "The pivot is one, the number to remove is two, so the multiplier is two."
+ ],
+ [
+ 21.185,
+ "Two times row one is two x plus four y equals two."
+ ],
+ [
+ 25.547,
+ "Take it away from row two."
+ ],
+ [
+ 27.448,
+ "Watch the coral line."
+ ],
+ [
+ 28.906,
+ "There is no meeting point for it to turn about, so it slides away, and it's gone."
+ ],
+ [
+ 33.88,
+ "Row two is now zero x plus zero y equals four."
+ ],
+ [
+ 38.216,
+ "Zero times x plus zero times y is zero, whatever x and y are."
+ ],
+ [
+ 43.333,
+ "So the row says zero equals four."
+ ],
+ [
+ 46.289,
+ "That's impossible: no solution."
+ ],
+ [
+ 48.997,
+ "And no swap can help: there's no row below to swap with, and the second pivot spot holds a zero."
+ ],
+ [
+ 55.964,
+ "This is permanent trouble."
+ ]
+ ]
+ },
+ "many": {
+ "dur": 50.832,
+ "marks": {
+ "ten": 1.94,
+ "eq": 4.18,
+ "same": 8.997,
+ "l": 14.714,
+ "go": 17.096,
+ "still": 19.427,
+ "gone": 21.81,
+ "row": 22.878,
+ "zero": 27.083,
+ "say": 32.07,
+ "p1": 38.529,
+ "p2": 40.039,
+ "p3": 42.083,
+ "many": 46.224
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now change just one number."
+ ],
+ [
+ 1.94,
+ "The right side six becomes two."
+ ],
+ [
+ 4.18,
+ "x plus two y equals one, and two x plus four y equals two."
+ ],
+ [
+ 8.997,
+ "Now the second equation is twice the first: the same line, drawn twice."
+ ],
+ [
+ 14.714,
+ "The multiplier is two again."
+ ],
+ [
+ 17.096,
+ "Take two times row one away."
+ ],
+ [
+ 19.427,
+ "This time the line doesn't move at all, and then it's gone."
+ ],
+ [
+ 22.878,
+ "Row two is zero x plus zero y equals zero."
+ ],
+ [
+ 27.083,
+ "Zero equals zero."
+ ],
+ [
+ 28.932,
+ "That's always true, so it rules nothing out."
+ ],
+ [
+ 32.07,
+ "Row two has told us nothing new."
+ ],
+ [
+ 34.089,
+ "Only row one is left, and every point on its line solves it: one, zero; three, minus one; minus one, one; and endlessly many more."
+ ],
+ [
+ 46.224,
+ "Zero equals zero means endlessly many solutions."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 5.52,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.172,
+ "Eliminate in your head, and say what kind of answer each system has."
+ ]
+ ]
+ },
+ "planes": {
+ "dur": 51.36,
+ "marks": {
+ "eq": 3.737,
+ "c1": 13.034,
+ "c1b": 19.635,
+ "par": 25.404,
+ "c2": 34.596,
+ "go": 38.789,
+ "row": 41.016,
+ "none": 45.951
+ },
+ "cues": [
+ [
+ 0.091,
+ "In three dimensions the same two things can happen."
+ ],
+ [
+ 3.737,
+ "x plus y plus z equals two, x plus two y plus three z equals five, and two x plus three y plus four z equals nine."
+ ],
+ [
+ 13.034,
+ "Column one."
+ ],
+ [
+ 14.089,
+ "Row two minus one times row one gives zero, one, two, and three."
+ ],
+ [
+ 19.635,
+ "Row three minus two times row one gives zero, one, two, and five."
+ ],
+ [
+ 25.404,
+ "Now rows two and three have the same numbers on the left and different right sides."
+ ],
+ [
+ 30.859,
+ "Their planes are parallel, like a floor and a ceiling."
+ ],
+ [
+ 34.596,
+ "Column two: row three minus one times row two."
+ ],
+ [
+ 38.789,
+ "The yellow plane slides away, and row three becomes zero, zero, zero, and two."
+ ],
+ [
+ 45.951,
+ "Zero equals two."
+ ],
+ [
+ 47.435,
+ "No point lies on all three planes: no solution."
+ ]
+ ]
+ },
+ "planes2": {
+ "dur": 44.256,
+ "marks": {
+ "seven": 3.854,
+ "c1": 5.651,
+ "same": 14.388,
+ "go": 18.464,
+ "row": 20.612,
+ "zero": 25.508,
+ "line": 29.753,
+ "pts": 34.622,
+ "many": 42.031
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now change the last right side, nine, to seven."
+ ],
+ [
+ 3.854,
+ "The yellow plane slides."
+ ],
+ [
+ 5.651,
+ "Column one gives the same rows as before, except one right side: zero, one, two, three, and again zero, one, two, three."
+ ],
+ [
+ 14.388,
+ "Rows two and three are now the same equation, one plane."
+ ],
+ [
+ 18.464,
+ "Row three minus row two."
+ ],
+ [
+ 20.612,
+ "Row three becomes zero, zero, zero, and zero."
+ ],
+ [
+ 25.508,
+ "Zero equals zero: row three says nothing."
+ ],
+ [
+ 29.753,
+ "The three planes share a whole line, like the pages of a book on its spine."
+ ],
+ [
+ 34.622,
+ "Every point on that line solves all three: minus one, three, zero; zero, one, one; one, minus one, two."
+ ],
+ [
+ 42.031,
+ "Endlessly many solutions."
+ ]
+ ]
+ },
+ "why": {
+ "dur": 59.256,
+ "marks": {
+ "rows": 3.594,
+ "par": 9.87,
+ "cols": 17.878,
+ "line": 20.924,
+ "off": 30.924,
+ "move": 36.523,
+ "on": 38.138,
+ "rows2": 46.445,
+ "one": 47.839,
+ "sum": 49.779
+ },
+ "cues": [
+ [
+ 0.104,
+ "Elimination finds what the pictures showed us before."
+ ],
+ [
+ 3.594,
+ "Here is x plus two y equals one, and two x plus four y equals six again."
+ ],
+ [
+ 9.87,
+ "In chapter three we read it from the lines: the same tilt, different right sides, so parallel, and no solution."
+ ],
+ [
+ 17.878,
+ "In chapter fourteen we read it from the columns."
+ ],
+ [
+ 20.924,
+ "Column one is one, two."
+ ],
+ [
+ 22.708,
+ "Column two is two, four, which is twice column one."
+ ],
+ [
+ 26.823,
+ "Both lie on one line, and every mix of them stays on that line."
+ ],
+ [
+ 30.924,
+ "The target b is one, six."
+ ],
+ [
+ 33.789,
+ "It's off the line, so no mix reaches it."
+ ],
+ [
+ 36.523,
+ "Move b to one, two."
+ ],
+ [
+ 38.138,
+ "Now b is on the line: one of column one reaches it, so does half of column two, and endlessly many other mixes."
+ ],
+ [
+ 46.445,
+ "Back in the row picture, the two lines are one line."
+ ],
+ [
+ 49.779,
+ "Elimination says the same thing with numbers alone: a row of zeros on the left, then zero equals four, or zero equals zero."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 6.312,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.003,
+ "Drag the multiplier until row two has no x, and watch what is left."
+ ]
+ ]
+ },
+ "decide": {
+ "dur": 40.248,
+ "marks": {
+ "q": 3.516,
+ "below": 5.625,
+ "swap": 8.529,
+ "none": 14.01,
+ "row": 18.828,
+ "zero0": 25.326,
+ "zeroc": 32.266,
+ "end": 35.99
+ },
+ "cues": [
+ [
+ 0.104,
+ "So here's what to do when a pivot spot holds a zero."
+ ],
+ [
+ 3.516,
+ "Look below it, in the same column."
+ ],
+ [
+ 5.625,
+ "If some row below has a number that isn't zero, swap that row up."
+ ],
+ [
+ 10.052,
+ "That was temporary trouble, and elimination goes on."
+ ],
+ [
+ 14.01,
+ "If every number below is zero too, that column has no pivot."
+ ],
+ [
+ 18.828,
+ "Then, with as many equations as unknowns, elimination ends with a row of zeros on the left."
+ ],
+ [
+ 25.326,
+ "If its right side is zero too, zero equals zero: endlessly many solutions."
+ ],
+ [
+ 32.266,
+ "If its right side is any other number, no solution."
+ ],
+ [
+ 35.99,
+ "Either way, the system does not have exactly one answer."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 26.472,
+ "marks": {
+ "w1": 1.016,
+ "w2": 5.885,
+ "w3": 11.159,
+ "w4": 16.484,
+ "end": 24.323
+ },
+ "cues": [
+ [
+ 0.104,
+ "Let's sum up."
+ ],
+ [
+ 1.016,
+ "A zero in a pivot spot: swap with a row below that has a number there."
+ ],
+ [
+ 5.885,
+ "A swap moves no line and no plane."
+ ],
+ [
+ 8.516,
+ "It's the same equations in a new order."
+ ],
+ [
+ 11.159,
+ "If no row can be swapped up, elimination ends with a row of zeros on the left."
+ ],
+ [
+ 16.484,
+ "Zero equals zero means endlessly many solutions."
+ ],
+ [
+ 21.003,
+ "Zero equals any other number means none."
+ ],
+ [
+ 24.323,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 3.744,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.55,
+ "Swap the rows, then solve."
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 4.704,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Set two."
+ ],
+ [
+ 1.081,
+ "Eliminate, then say how many solutions."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 2.616,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Set three."
+ ],
+ [
+ 1.276,
+ "Find the missing number."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 6.384,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.198,
+ "Change the system with your own hands until elimination says what we ask."
+ ]
+ ]
+ },
+ "play": {
+ "dur": 10.56,
+ "marks": {
+ "go": 3.815
+ },
+ "cues": [
+ [
+ 0.104,
+ "Playground."
+ ],
+ [
+ 1.068,
+ "Nothing here is marked right or wrong."
+ ],
+ [
+ 3.815,
+ "Change any number, drag the multiplier, and make elimination break down in every way you can."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 10.632,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.12,
+ "That's the end of chapter twenty, When Elimination Breaks Down."
+ ],
+ [
+ 5.339,
+ "Next: chapter twenty-one, where each elimination step becomes a matrix."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch20/audio/en/why.mp3 b/site/linear-algebra/ch20/audio/en/why.mp3
new file mode 100644
index 0000000..50a8934
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/why.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/wrap.mp3 b/site/linear-algebra/ch20/audio/en/wrap.mp3
new file mode 100644
index 0000000..d789e39
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/zero.mp3 b/site/linear-algebra/ch20/audio/en/zero.mp3
new file mode 100644
index 0000000..99db22d
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/zero.mp3 differ
diff --git a/site/linear-algebra/ch20/audio/en/zero3.mp3 b/site/linear-algebra/ch20/audio/en/zero3.mp3
new file mode 100644
index 0000000..2cfbddf
Binary files /dev/null and b/site/linear-algebra/ch20/audio/en/zero3.mp3 differ
diff --git a/site/linear-algebra/ch20/index.html b/site/linear-algebra/ch20/index.html
new file mode 100644
index 0000000..4ef1241
--- /dev/null
+++ b/site/linear-algebra/ch20/index.html
@@ -0,0 +1,472 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>When Elimination Breaks Down</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="../lib/space3.js"></script>
+<script src="../lib/elim.js"></script>
+<script src="../lib/emat.js"></script>
+<script src="../lib/play.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 20, title: 'When Elimination Breaks Down', minutes: 11, language: 'en', next: '../ch21/' };
+
+/* ---------- chapter drawing helpers (chapter 16's for 2D, chapter 18's for 3D) ---------- */
+const BLUE = LS_ROW[0], CORAL = LS_ROW[1], YELLOW = S3_ROW[2];
+const CARD = { x: 40, y: 345, w: 720, cls: 'side' }; // under the two equations, beside the plane
+const LOW = { x: 40, y: 610, w: 720, cls: 'side' }; // under the equations and the table
+const MAT = [108, 450]; // [A | b] in 2D: its row bars line up with the equations'
+const TBL = [120, 240]; // [A | b] in 3D: rows at 240, 306, 372
+const CARD3 = { x: 40, y: 420, w: 720, cls: 'side' };
+const VIEW = { yaw: -40, pitch: 20 };
+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 okMark = (p, x, y, t0, size = 34) => text(p, '✓', x, y, t0, { size, fill: COL.good, weight: 700 });
+// One line of working, aligned on its = sign at xEq.
+const wl = (p, lhs, rhs, y, t0, { xEq = 380, size = 40, fill = COL.chalk } = {}) => {
+ const g = G(p, { o: 0 });
+ M(g, [].concat(lhs), { x: xEq - 22, y, size, fill, anchor: 'end' });
+ M(g, ['='], { x: xEq, y, size, fill, anchor: 'middle' });
+ M(g, [].concat(rhs), { x: xEq + 22, y, size, fill, anchor: 'start' });
+ show(g, t0);
+ return g;
+};
+const thick = (sys, i, t0) => { tw(sys.lines[i].l, { 'a_stroke-width': 10 }, t0, .35); tw(sys.lines[i].l, { 'a_stroke-width': 5 }, t0 + .9, .6); };
+// The coral line is dashed while it lies on the blue one, so both colours show (as in chapter 3).
+const dashSame = sys => sys.onChange((v, s) => {
+ const d = s.many && (v.a10 || v.a11) ? '14 12' : '';
+ if ((sys.lines[1].l.getAttribute('stroke-dasharray') || '') !== d) sys.lines[1].l.setAttribute('stroke-dasharray', d);
+});
+// Two equations top left, the plane on the right, [A | b] under the equations; no readout (elimination finds it).
+const two = (p, A, b, { t0 = .1, meet = true, table = true } = {}) => {
+ const sys = linsys(p, { A, b, eq: [90, 200], mat: null, sol: false, t0 });
+ if (!meet) put(sys.meetBox, { o: 0 });
+ dashSame(sys);
+ const el = table ? elim(p, sys, { at: MAT, t0 }) : null;
+ return { sys, el };
+};
+// The old line of row 2, dashed, through (sx, sy): a·x + b·y = c runs along (b, −a).
+const ghost = (sys, a, b, sx, sy, t0, color = CORAL) => {
+ const l = sys.P.line(sx, sy, sx + b, sy - a, color, t0, { dash: '10 10', w: 3, into: sys.stage });
+ tw(l, { o: .45 }, t0 + .6, .4);
+ return l;
+};
+// A dashed ring round the point that never moves.
+const pin = (sys, x, y, t0) => {
+ const g = G(sys.stage, { x: sys.P.PX(x), y: sys.P.PY(y), o: 0 });
+ mk('circle', { r: 20, fill: 'none', stroke: COL.chalk, 'stroke-width': 3.5, 'stroke-dasharray': '6 5' }, g);
+ show(g, t0, .4);
+ return g;
+};
+// A system in space on the right, [A | b] top left, the equations written once above the table (chapter 18).
+const three = (p, { A, b }, caption, { t0 = .1, view = VIEW } = {}) => {
+ const sys = lin3(p, { A, b, eq: [90, 190], mat: null, sol: false, space: { cx: 1185, size: 600, ...view }, t0 });
+ sys.E.style.display = 'none';
+ if (caption) say(p, [caption], 90, 160, t0 + .1, { size: 28, fill: COL.dim });
+ const el = elim(p, sys, { at: TBL, size: 44, cw: 84, rh: 66, t0, labelX: 530 });
+ return { sys, el, V: sys.space };
+};
+const triangle = (p, el, t0) => {
+ const e = path(p, `M${el.cx(0) - 40} ${el.ry(0) - 48}L${el.cx(2) + 42} ${el.ry(0) - 48}L${el.cx(2) + 42} ${el.ry(2) + 20}Z`, { fill: COL.chalk, stroke: COL.chalk, 'stroke-width': 2, 'fill-opacity': .1 }, { o: 0 });
+ show(e, t0, .6);
+ return e;
+};
+// A small system with no picture (title card, the flow in "decide"): the .v, .to, .set, .onChange elim uses.
+const bare = (A, b) => {
+ const v = {}, fs = [];
+ A.forEach((r, i) => { r.forEach((x, j) => { v[`a${i}${j}`] = x; }); v[`b${i}`] = b[i]; });
+ let plan = { ...v };
+ const set = to => { Object.assign(v, to); fs.forEach(f => f(v)); };
+ return { v, set, onChange: f => fs.push(f), solve: () => ({}), live() {},
+ to(next, at, dur = 1.2, ease = io) { const from = { ...plan }; plan = { ...plan, ...next }; const goal = { ...plan };
+ prog(q => set(Object.fromEntries(Object.keys(next).map(k => [k, from[k] + (goal[k] - from[k]) * q]))), at, dur, ease); } };
+};
+const keys2 = (A, b) => ({ a00: A[0][0], a01: A[0][1], a10: A[1][0], a11: A[1][1], b0: b[0], b1: b[1] });
+const fr = v => { const r = Math.round(v * 10) / 10; return Math.abs(v - Math.round(v)) < 1e-9 ? num(Math.round(v)) : Math.abs(v * 2 - Math.round(v * 2)) < 1e-9 ? num(Math.round(v * 2)) + '/2' : num(r); };
+// Under the table, live: what row 2 − ℓ × row 1 (ℓ = number to remove ÷ pivot) leaves, and what that row says.
+const verdict = (p, sys, el, t0) => {
+ const g = G(p, { o: 0 }), y = el.ry(2) + 50, out = G(g, {});
+ show(g, t0);
+ let key = '';
+ const drawV = v => {
+ const l = v.a00 ? v.a10 / v.a00 : NaN, r = [v.a10 - l * v.a00, v.a11 - l * v.a01, v.b1 - l * v.b0];
+ const k = [l, ...r].map(fr).join('|');
+ if (k === key) return;
+ key = k;
+ out.replaceChildren();
+ if (!v.a00) { T(out, 'pivot spot 0: swap first', { x: 90, y: y - 50, size: 28, fill: COL.bad, weight: 600 }); return; }
+ T(out, `row 2 − ${fr(l).replace('-', '−')} × row 1 gives:`, { x: 90, y: y - 50, size: 28, fill: COL.dim, weight: 600 });
+ r.forEach((x, j) => M(out, [fr(x).replace('-', '−')], { x: el.cx(j), y: y + 10, size: 40, fill: j === 2 ? COL.task : COL.chalk, anchor: 'middle' }));
+ const z = Math.abs(r[1]) < 1e-9;
+ const say_ = z ? (Math.abs(r[2]) < 1e-9 ? '0 = 0: endlessly many' : `0 = ${fr(r[2]).replace('-', '−')}: no solution`) : 'a pivot: one solution';
+ T(out, say_, { x: 470, y: y + 6, size: 30, fill: z ? (Math.abs(r[2]) < 1e-9 ? COL.good : COL.bad) : COL.chalk, weight: 600 });
+ };
+ sys.onChange(drawV); drawV(sys.v);
+ return g;
+};
+
+/* ---------- practice data (every answer worked twice: by the steps, and by putting the solution back) ---------- */
+const SWAPQ = [
+ { parts: ['0x + 2y = 6', ', ', 'x + y = 4', ': x = ', { box: '1' }, ', y = ', { box: '3' }], why: 'Swapped: x + y = 4, 2y = 6. So y = 3, and x + 3 = 4 gives x = 1.', hint: 'After the swap, the bottom row 2y = 6 has y alone.' },
+ { parts: ['0x − y = 2', ', ', '3x + y = 1', ': x = ', { box: '1' }, ', y = ', { box: '-2' }], why: '−y = 2 gives y = −2; then 3x − 2 = 1, 3x = 3, x = 1.', hint: '−y = 2 means y = −2. Put it into 3x + y = 1.' },
+ { parts: ['0x + 4y = −4', ', ', '2x + 3y = 1', ': x = ', { box: '2' }, ', y = ', { box: '-1' }], why: '4y = −4 gives y = −1; then 2x − 3 = 1, 2x = 4, x = 2.', hint: 'y = −4 ÷ 4. Then 3y is −3.' },
+ { parts: ['0x + 5y = 10', ', ', '−x + 2y = 6', ': x = ', { box: '-2' }, ', y = ', { box: '2' }], why: '5y = 10 gives y = 2; then −x + 4 = 6, −x = 2, x = −2.', hint: 'y = 2. Then −x + 4 = 6: what is −x?' },
+];
+const KIND = [['one', 'one solution', COL.chalk, '1'], ['none', 'no solution', COL.bad, '2'], ['many', 'endlessly many', COL.good, '3']];
+const KINDQ = [
+ { parts: [$m('x + 2y = 4, 3x + 6y = 12')], ans: ['many'], why: 'Row 2 − 3 × row 1: 0 = 12 − 12 = 0. The same line.' },
+ { parts: [$m('x + 2y = 4, 3x + 6y = 10')], ans: ['none'], why: 'Row 2 − 3 × row 1: 0 = 10 − 12 = −2. Parallel lines.' },
+ { parts: [$m('2x − y = 1, 4x − 2y = 3')], ans: ['none'], why: 'Row 2 − 2 × row 1: 0 = 3 − 2 = 1.' },
+ { parts: [$m('2x − y = 1, 4x + y = 5')], ans: ['one'], why: 'Row 2 − 2 × row 1: 3y = 3, a pivot. y = 1, x = 1.' },
+ { parts: [$m('−x + 3y = 2, 2x − 6y = −4')], ans: ['many'], why: 'ℓ = 2 ÷ (−1) = −2: row 2 + 2 × row 1 is 0 = −4 + 4 = 0.' },
+ { parts: [$m('0x + 2y = 2, 3x + 0y = 6')], ans: ['one'], why: 'Swap the rows: 3x = 6 and 2y = 2. x = 2, y = 1.' },
+];
+const MISSQ = [
+ { parts: ['x + 3y = 2', ', ', '2x + 6y = ', { box: '4' }, ' gives 0 = 0'], why: '2 × row 1 is 2x + 6y = 4; the right side must be 4 too.', hint: 'Row 2 − 2 × row 1 leaves 0 = (your number) − 4.' },
+ { parts: ['3x − y = 5', ', ', '6x − 2y = ', { box: '10' }, ' gives 0 = 0'], why: '2 × row 1 is 6x − 2y = 10.', hint: 'Multiply all of row 1 by 2, the right side too.' },
+ { parts: ['x + y = 1', ', ', '4x + ', { box: '4' }, 'y = 7 gives no solution'], why: 'With 4y, row 2 − 4 × row 1 is 0 = 7 − 4 = 3.', hint: 'The x numbers are 1 and 4, so the multiplier is 4. Which y number does 4 × row 1 have?' },
+ { parts: ['2x + 5y = 1', ', ', { box: '4' }, 'x + 10y = 3 gives no solution'], why: 'Then ℓ = 2: 10 − 2·5 = 0 and 3 − 2·1 = 1, so 0 = 1.', hint: 'Row 2 has twice row 1’s y number. Make its x number twice row 1’s too.' },
+ { parts: ['x + y + z = 1', ', ', 'x + 2y + z = 3', ', ', '2x + 3y + 2z = ', { box: '4' }, ' gives 0 = 0'], why: 'Row 3 has the left side of row 1 + row 2; with 1 + 3 = 4 on the right, elimination ends in 0 = 0.', hint: 'Add rows 1 and 2: what do you get on the left? And on the right?' },
+];
+// Hands-on: change one number of the system until elimination says what is asked (the verdict line shows it live).
+const HANDS = [
+ { A: [[1, 2], [2, 4]], b: [3, 1], only: ['b1'], answer: { b1: 6 }, test: v => v.b1 === 6, prompt: 'Change only the coral right side until elimination gives 0 = 0.',
+ why: 'b = 6: row 2 − 2 × row 1 is 0 = 6 − 6 = 0. The two lines are one.', hint: v => `Now row 2 − 2 × row 1 gives 0 = ${num(v.b1 - 6)}. Its right side must become 0.` },
+ { A: [[1, -1], [2, 1]], b: [1, 5], only: ['a11'], answer: { a11: -2 }, test: v => v.a11 === -2, prompt: 'Change only the coral y number until elimination gives no solution.',
+ why: '−2y: row 2 − 2 × row 1 is 0x + 0y = 3, so 0 = 3. The lines are parallel.', hint: v => `Row 2 − 2 × row 1 leaves ${num(v.a11 + 2)}y: it is still a pivot. Make it 0.` },
+];
+
+/* ---------- beats ---------- */
+const BEATS = [
+ ['intro', 'When elimination breaks down', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 2, Chapter 20', { x: 800, y: 280, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'When Elimination Breaks Down', { x: 800, y: 390, size: 88, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'a zero where the pivot should be: sometimes a swap fixes it, sometimes nothing can', 800, 500, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });
+ const lg = G(scene, { o: 0 });
+ const s = bare([[0, 2], [3, 1]], [4, 5]), el = elim(lg, s, { at: [660, 640], size: 40, cw: 76, rh: 62, t0: 0 });
+ show(lg, m('sub') + 1.5, .5);
+ el.ring(0, 0, m('sub') + 3, { color: COL.bad });
+ elSwap(el, s, 0, 1, m('move') + .8, 1.4);
+ el.ring(0, 0, m('move') + 2.6, { color: COL.good });
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);
+ }],
+
+ ['zero', 'A zero in the pivot spot', (m) => {
+ const p = panel(0);
+ text(p, 'A zero in the pivot spot', 60, 110, .2, { size: 40, weight: 600 });
+ const A = [[0, 2], [3, 1]], b = [4, 5];
+ const { sys, el } = two(p, A, b, { t0: m('eq') - .3, meet: false });
+ show(sys.meetBox, m('meet'), .5); pulse(sys.meet, m('meet') + .3);
+ el.ring(0, 0, m('piv'), { color: COL.bad, label: 'pivot spot', below: false });
+ el.ring(1, 0, m('div'), { dash: true });
+ const d = say(p, ['ℓ = 3 ÷ 0 = ?'], 90, 680, m('div') + .4, { size: 38, fill: COL.bad });
+ hide(d, m('try') + .2, .3);
+ hide(text(p, 'no number times 0 makes 3', 90, 740, m('div') + 2.5, { size: 28, fill: COL.dim, weight: 600 }), m('try') + .2, .3);
+ ghost(sys, 3, 1, 1, 2, m('try'));
+ el.op(1, 0, 0, m('try') + .2);
+ el.mult(1, m('l1'), 1.4);
+ el.mult(2, m('l2'), 1.4);
+ el.mult(-1, m('l3'), 1.8);
+ [m('l1') + 1.4, m('l2') + 1.4, m('l3') + 1.8, m('stays') + .3].forEach(t => el.flash(1, t, 0));
+ pin(sys, 1, 2, m('stays'));
+ say(p, ['0 · ℓ = 0, so 3 − 0 = 3'], 90, 680, m('stays') + 3, { size: 36, fill: COL.chalk });
+ text(p, 'no multiplier removes the 3x', 90, 750, m('none'), { size: 32, fill: COL.bad, weight: 600 });
+ }],
+
+ ['swap', 'Swap the rows', (m) => {
+ const p = panel(0);
+ text(p, 'Swap the rows', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, el } = two(p, [[0, 2], [3, 1]], [4, 5]);
+ const rg = el.ring(0, 0, .4, { color: COL.bad });
+ const o = text(p, 'both at once: the order does not matter', 90, 640, m('order'), { size: 28, fill: COL.dim, weight: 600 });
+ hide(o, m('piv') - .3, .3);
+ hide(rg, m('swap') - .2, .3);
+ elSwap(el, sys, 0, 1, m('swap') + .3, 1.8, { label: [480, 490] });
+ pin(sys, 1, 2, m('same') + .2);
+ thick(sys, 0, m('same') + 4.5);
+ el.ring(0, 0, m('piv'));
+ el.ring(1, 0, m('zero'), { color: COL.good, dash: true });
+ text(p, 'already 0: a triangle', 90, 640, m('zero') + .6, { size: 28, fill: COL.good, weight: 600 });
+ wl(p, '2y', '4', 710, m('y'), { xEq: 200, size: 38 });
+ say(p, ['→'], 320, 710, m('y') + 2, { size: 38, fill: COL.dim });
+ wl(p, 'y', '2', 710, m('y') + 2, { xEq: 420, size: 38, fill: COL.task });
+ wl(p, '3x + 2', '5', 780, m('x'), { xEq: 200, size: 38 });
+ say(p, ['→'], 320, 780, m('x') + 2.4, { size: 38, fill: COL.dim });
+ wl(p, '3x', '3', 780, m('x') + 2.4, { xEq: 420, size: 38 });
+ say(p, ['→ x = 1'], 520, 780, m('x') + 4, { size: 38, fill: COL.task });
+ text(p, 'a row exchange: temporary trouble', 90, 850, m('temp'), { size: 30, fill: COL.good, weight: 600 });
+ el.flash(0, m('temp') + 3); el.flash(1, m('temp') + 5); pulse(sys.meet, m('temp') + 6.5);
+ }],
+
+ ['zero3', 'A zero in the middle', (m) => {
+ const p = panel(0);
+ text(p, 'A zero in the middle', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, el, V } = three(p, { A: [[1, 2, 1], [2, 4, 3], [3, 7, 5]], b: [1, 3, 4] }, 'x + 2y + z = 1, 2x + 4y + 3z = 3, 3x + 7y + 5z = 4', { t0: m('eq') - .3, view: { yaw: -30, pitch: 22 } });
+ V.sway(5, 13);
+ tw(sys.meet.e, { o: 0 }, 0, 0);
+ el.ring(0, 0, m('c1'));
+ el.step(1, 0, 2, m('s21'), 2.2, { lead: .5 });
+ el.step(2, 0, 3, m('s31'), 2.2, { lead: .5 });
+ hide(el.ring(1, 1, m('zero'), { color: COL.bad }), m('swap') + .2, .3);
+ hide(el.ring(2, 1, m('below'), { dash: true, color: COL.good }), m('swap') + .2, .3);
+ sys.planes[1].fade(.3, m('swap'), .4); sys.planes[2].fade(.3, m('swap'), .4);
+ elSwap(el, sys, 1, 2, m('swap') + .4, 1.8, { label: [530, 345] });
+ sys.planes[1].fade(1, m('swap') + 2.4, .5); sys.planes[2].fade(1, m('swap') + 2.4, .5);
+ triangle(p, el, m('tri'));
+ [0, 1, 2].forEach(i => el.ring(i, i, m('tri') + 1.6 + .5 * i));
+ V.turn({ yaw: 10, pitch: 26 }, m('s21'), 12);
+ say(p, ['z = 1'], 90, 500, m('z'), { size: 36, fill: COL.task });
+ say(p, ['y + 2 = 1 → y = −1'], 90, 565, m('y'), { size: 36, fill: COL.task });
+ say(p, ['x − 2 + 1 = 1 → x = 2'], 90, 630, m('x'), { size: 36, fill: COL.task });
+ show(sys.meet.e, m('pt'), .4); pulse(sys.meet.e, m('pt') + .4);
+ text(p, 'a swap fixed it: temporary trouble', 90, 710, m('pt') + 1.5, { size: 30, fill: COL.good, weight: 600 });
+ }],
+
+ ['q1', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const t = two(p, [[0, 3], [2, 1]], [6, 4], { meet: false, table: false });
+ S.sys = t.sys;
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-swap', prompt: ['The pivot spot holds 0. Swap the rows, then solve.'],
+ build: blanks([
+ { parts: ['after the swap, the pivots are ', { box: '2' }, ' and ', { box: '3' }], why: 'Swapped: 2x + y = 4 on top (pivot 2), 3y = 6 below (pivot 3).', hint: 'After the swap, 2x + y = 4 is row 1. The pivots are the first numbers on the diagonal.' },
+ { parts: ['y = ', { box: '2' }, ', x = ', { box: '1' }], why: '3y = 6 gives y = 2; then 2x + 2 = 4, so x = 1.', hint: '3y = 6. Then put y into 2x + y = 4.', fx: () => fx(S.sys.meetBox, { o: 1 }, .2, .5) },
+ ]),
+ }], done) }],
+
+ ['none', '0 = 4', (m) => {
+ const p = panel(0);
+ text(p, 'A row that says 0 = 4', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, el } = two(p, [[1, 2], [2, 4]], [1, 6], { t0: m('eq') - .3 });
+ text(p, 'same tilt, different right sides: parallel (chapter 3)', 90, 380, m('par') + .5, { size: 26, fill: COL.dim, weight: 600 });
+ thick(sys, 0, m('par') + 2); thick(sys, 1, m('par') + 3.5); thick(sys, 0, m('par') + 5.5); thick(sys, 1, m('par') + 5.5);
+ el.ring(0, 0, m('l')); el.ring(1, 0, m('l') + .6, { dash: true });
+ hide(say(p, ['ℓ = 2 ÷ 1 = 2'], 480, 650, m('l') + 1.2, { size: 34, fill: COL.chalk }), m('row') - .3, .3);
+ el.op(1, 0, 2, m('l') + 2.4);
+ hide(el.line([2, 4, 2], 2, m('two'), { label: '2 × row 1', color: BLUE }), m('row') - .3, .3);
+ sys.focus(1, m('go'));
+ el.mult(2, m('go') + .5, 4.2, { count: false });
+ sys.focus(null, m('gone') + .5);
+ el.flash(1, m('row'));
+ say(p, ['0x + 0y = 4'], 90, 660, m('row') + .3, { size: 40, fill: CORAL });
+ say(p, ['0 = 4'], 90, 730, m('zero') + 3, { size: 44, fill: COL.bad });
+ text(p, 'impossible: no solution', 260, 726, m('none'), { size: 32, fill: COL.bad, weight: 600 });
+ pulse(el.ring(1, 1, m('perm'), { color: COL.bad }), m('perm') + 3, 1.25);
+ el.flash(1, m('perm') + 5);
+ text(p, 'no pivot, no row below: permanent trouble', 90, 800, m('perm') + 1, { size: 28, fill: COL.bad, weight: 600 });
+ }],
+
+ ['many', '0 = 0', (m) => {
+ const p = panel(0);
+ text(p, 'A row that says 0 = 0', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, el } = two(p, [[1, 2], [2, 4]], [1, 6]);
+ el.to({ b1: 2 }, m('ten'), 1.6);
+ el.flash(1, m('ten'), 2);
+ text(p, 'twice row 1: the same line', 90, 380, m('same'), { size: 26, fill: COL.dim, weight: 600 });
+ el.ring(1, 0, m('l'), { dash: true });
+ el.op(1, 0, 2, m('l') + .6);
+ hide(el.line([2, 4, 2], 2, m('l') + 1, { label: '2 × row 1', color: BLUE }), m('row') - .3, .3);
+ el.mult(2, m('go') + .5, 3.2, { count: false });
+ el.flash(1, m('row'));
+ say(p, ['0x + 0y = 0'], 90, 660, m('row') + .3, { size: 40, fill: CORAL });
+ say(p, ['0 = 0'], 90, 730, m('zero'), { size: 44, fill: COL.good });
+ text(p, 'always true: it rules nothing out', 260, 726, m('zero') + 1.5, { size: 30, fill: COL.good, weight: 600 });
+ thick(sys, 0, m('say') + 1.5);
+ const pts = [[1, 0, 'p1', '1 + 0 = 1'], [3, -1, 'p2', '3 − 2 = 1'], [-1, 1, 'p3', '−1 + 2 = 1']];
+ pts.forEach(([x, y, k, chk], i) => {
+ sys.P.dot(x, y, COL.chalk, m(k), { label: `(${num(x)}, ${num(y)})`, dx: 14, dy: 30, into: sys.stage });
+ say(p, [chk], 90 + 225 * i, 800, m(k) + .2, { size: 32, fill: COL.chalk });
+ okMark(p, 90 + 225 * i + 170, 800, m(k) + .8, 30);
+ });
+ text(p, 'endlessly many solutions', 90, 860, m('many'), { size: 32, fill: COL.good, weight: 600 });
+ }],
+
+ ['q2', 'Quick check', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'c-kind', prompt: ['Eliminate x from row 2. What does the system have?'],
+ build: grid([
+ { parts: [$m('x + y = 2, 3x + 3y = 6')], ans: ['many'], why: 'Row 2 − 3 × row 1: 0 = 6 − 6 = 0.' },
+ { parts: [$m('x − y = 1, 2x − 2y = 5')], ans: ['none'], why: 'Row 2 − 2 × row 1: 0 = 5 − 2 = 3.' },
+ { parts: [$m('x + y = 2, 2x + 3y = 5')], ans: ['one'], why: 'Row 2 − 2 × row 1: y = 1, a pivot. Then x = 1.' },
+ { parts: [$m('2x + 4y = 2, x + 2y = 3')], ans: ['none'], why: 'ℓ = 1 ÷ 2: 2 − ½·4 = 0 and 3 − ½·2 = 2, so 0 = 2.' },
+ { parts: [$m('0x + y = 3, x + 0y = 2')], ans: ['one'], why: 'A swap: x = 2 on top, y = 3 below. Temporary trouble only.' },
+ ], KIND, { text: true }),
+ }], done, 'Quick check') }],
+
+ ['planes', 'Parallel planes', (m) => {
+ const p = panel(0);
+ text(p, 'Three planes, no point', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, el, V } = three(p, { A: [[1, 1, 1], [1, 2, 3], [2, 3, 4]], b: [2, 5, 9] }, 'x + y + z = 2, x + 2y + 3z = 5, 2x + 3y + 4z = 9', { t0: m('eq') - .3 });
+ V.sway(5, 13);
+ el.step(1, 0, 1, m('c1') + 1, 2, { lead: .5 });
+ el.step(2, 0, 2, m('c1b'), 2.2, { lead: .5 });
+ V.turn({ yaw: -10 }, m('c1'), 6);
+ el.flash(1, m('par'), null); el.flash(2, m('par') + .3, null);
+ sys.focus([1, 2], m('par') + .5);
+ V.turn({ yaw: 90, pitch: 2 }, m('par') + .5, 3); // look along x: the two planes y + 2z = 3 and 5 stand as parallel lines
+ text(p, 'same left sides: parallel planes', 90, 480, m('par') + 2.5, { size: 30, fill: YELLOW, weight: 600 });
+ el.op(2, 1, 1, m('c2'));
+ el.mult(1, m('go') + .3, 3.4, { count: false });
+ sys.focus(null, m('row'));
+ V.turn({ yaw: -30, pitch: 22 }, m('row'), 3);
+ el.flash(2, m('row') + .3);
+ say(p, ['0x + 0y + 0z = 2'], 90, 560, m('row') + .5, { size: 38, fill: YELLOW });
+ say(p, ['0 = 2'], 90, 630, m('none'), { size: 44, fill: COL.bad });
+ text(p, 'no solution', 260, 626, m('none') + .4, { size: 32, fill: COL.bad, weight: 600 });
+ }],
+
+ ['planes2', 'One line of solutions', (m) => {
+ const p = panel(0);
+ text(p, 'Three planes, one line', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, el, V } = three(p, { A: [[1, 1, 1], [1, 2, 3], [2, 3, 4]], b: [2, 5, 9] }, '');
+ V.sway(5, 13);
+ hide(say(p, ['x + y + z = 2, x + 2y + 3z = 5, 2x + 3y + 4z = 9'], 90, 160, .2, { size: 28, fill: COL.dim }), m('seven'), .5);
+ say(p, ['x + y + z = 2, x + 2y + 3z = 5, 2x + 3y + 4z = 7'], 90, 160, m('seven') + .3, { size: 28, fill: COL.dim });
+ el.to({ b2: 7 }, m('seven'), 1.6);
+ el.flash(2, m('seven'), 3);
+ el.step(1, 0, 1, m('c1'), 1.6, { lead: .4 });
+ el.step(2, 0, 2, m('c1') + 2.6, 1.8, { lead: .4 });
+ el.flash(1, m('same'), null); el.flash(2, m('same') + .3, null);
+ text(p, 'rows 2 and 3: the same plane', 90, 480, m('same') + .5, { size: 30, fill: YELLOW, weight: 600 });
+ el.op(2, 1, 1, m('go'));
+ el.mult(1, m('go') + .5, 2.2, { count: false });
+ el.flash(2, m('row'));
+ say(p, ['0 = 0'], 90, 560, m('zero'), { size: 44, fill: COL.good });
+ text(p, 'row 3 says nothing', 230, 556, m('zero') + .5, { size: 30, fill: COL.good, weight: 600 });
+ prog(q => sys.lines[0].e.setAttribute('stroke-width', 2.5 + 6 * Math.sin(Math.PI * q)), m('line'), 2, lin);
+ prog(q => sys.lines[0].e.setAttribute('stroke-width', 2.5 + 6 * Math.sin(Math.PI * q)), m('line') + 2.4, 2, lin);
+ const pts = [[-1, 3, 0], [0, 1, 1], [1, -1, 2]].map((q, i) => {
+ const pt = V.point(q, { label: `(${q.map(num).join(', ')})`, size: 24 });
+ put(pt.e, { o: 0 }); show(pt.e, m('pts') + 1.4 * i, .4);
+ return pt;
+ });
+ text(p, 'every point of the line: endlessly many', 90, 630, m('many'), { size: 30, fill: COL.good, weight: 600 });
+ }],
+
+ ['why', 'The pictures said so', (m) => {
+ const p = panel(0);
+ text(p, 'The pictures said so too', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys } = two(p, [[1, 2], [2, 4]], [1, 6], { t0: m('rows') - .3, table: false });
+ sys.labels(['col 1', 'col 2', 'b']);
+ text(p, 'chapter 3: same tilt, different right sides', 90, 420, m('par'), { size: 28, fill: COL.dim, weight: 600 });
+ thick(sys, 0, m('rows') + 1.5); thick(sys, 1, m('rows') + 3); thick(sys, 0, m('par') + 2); thick(sys, 1, m('par') + 2);
+ say(p, ['parallel: no solution'], 90, 475, m('par') + 3, { size: 34, fill: COL.bad });
+ sys.view('col', m('cols'));
+ text(p, 'chapter 14: the columns', 90, 560, m('cols'), { size: 28, fill: COL.dim, weight: 600 });
+ const ln = sys.P.line(-3, -6, 3, 6, COL.dim, m('line') + 1, { dash: '8 10', w: 3, into: sys.stage });
+ hide(ln, m('rows2'), .4);
+ // every mix c·col 1 + d·col 2 = (c + 2d)·col 1 stays on that line: a mix's tip walks along it
+ const mixDot = G(sys.stage, { o: 0 }); mk('circle', { r: 9, fill: COL.chalk, stroke: COL.board, 'stroke-width': 3 }, mixDot);
+ const mixT = T(mixDot, '', { x: 16, y: 6, size: 22, fill: COL.chalk, weight: 600 });
+ show(mixDot, m('line') + 4.5, .3); hide(mixDot, m('off') - .2, .3);
+ prog(q => { const k = Math.round((-2 + 4.5 * Math.sin(Math.PI * q)) * 2) / 2; put(mixDot, { x: sys.P.PX(k), y: sys.P.PY(2 * k) }); mixT.textContent = `a mix: (${num(k)}, ${num(2 * k)})`; }, m('line') + 4.5, Math.max(1, m('off') - m('line') - 4.8), lin);
+ say(p, ['col 2 = 2 · col 1: one line'], 90, 615, m('line') + 2, { size: 32, fill: COL.chalk });
+ [0, 1].forEach(j => { tw(sys.cols[j], { 'a_stroke-width': 9 }, m('line') + 1.6 * j, .35); tw(sys.cols[j], { 'a_stroke-width': 5 }, m('line') + 1.6 * j + .9, .5); });
+ const ring = G(sys.stage, { x: sys.P.PX(1), y: sys.P.PY(6), o: 0 });
+ mk('circle', { r: 22, fill: 'none', stroke: COL.bad, 'stroke-width': 3.5 }, ring);
+ show(ring, m('off'), .3); hide(ring, m('move'), .3); pulse(ring, m('off') + 2.5, 1.3);
+ say(p, ['b off the line: no mix reaches it'], 90, 670, m('off') + .6, { size: 30, fill: COL.bad });
+ sys.to({ b1: 2 }, m('move') + .3, 1.6);
+ say(p, ['b = 1 · col 1 = ½ · col 2 = …'], 90, 725, m('on'), { size: 32, fill: COL.good });
+ sys.view('row', m('rows2'));
+ thick(sys, 1, m('one') + .2);
+ text(p, 'elimination: a row of zeros, then 0 = 4 or 0 = 0', 90, 800, m('sum'), { size: 28, fill: COL.chalk, weight: 600 });
+ thick(sys, 0, m('sum') + 3); thick(sys, 1, m('sum') + 5);
+ }],
+
+ ['q3', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const t = two(p, [[1, 1], [3, 3]], [1, 9]);
+ S.sys = t.sys; S.el = t.el;
+ S.el.op(1, 0, 0, .3);
+ }, { ask: done => quiz(LOW, [{
+ id: 'c-run', prompt: ['Drag the multiplier until row 2 has no x.'],
+ build: elTask(S.el, v => v.a10 === 0, 'ℓ = 3: row 2 becomes 0x + 0y = 6, so 0 = 6. No solution: the lines were parallel, and the coral line ran away.',
+ (v, l) => `Row 2 still has ${num(v.a10)}x. The pivot is 1 and the number to remove is 3.`, () => S.el.set({ l: 3 })),
+ }], done) }],
+
+ ['decide', 'Temporary or permanent?', (m) => {
+ const p = panel(0);
+ text(p, 'Temporary or permanent?', 60, 110, .2, { size: 40, weight: 600 });
+ const step = (str, x, y, t0, fill = COL.chalk) => text(p, str, x, y, t0, { size: 32, fill, weight: 600 });
+ step('a 0 in the pivot spot', 90, 210, m('q') - .4);
+ step('look below it, in the same column:', 90, 270, m('q') + .4, COL.dim);
+ step('a number that is not 0?', 130, 350, m('below'));
+ step('→ swap that row up: temporary', 520, 350, m('swap'), COL.good);
+ step('every number below is 0?', 130, 450, m('none'));
+ step('→ no pivot in this column', 520, 450, m('none') + 1.5, COL.bad);
+ step('elimination ends with a row of zeros on the left:', 130, 540, m('row'));
+ step('0 = 0', 170, 620, m('zero0'), COL.good); step('endlessly many solutions', 330, 620, m('zero0') + .5, COL.good);
+ step('0 = 4', 170, 690, m('zeroc'), COL.bad); step('no solution', 330, 690, m('zeroc') + .5, COL.bad);
+ text(p, 'either way: not exactly one answer', 90, 790, m('end'), { size: 32, fill: COL.chalk, weight: 600 });
+ // the three cases as small tables on the right
+ const mini = (A, b, x, y, t0) => { const g = G(p, { o: 0 }); elim(g, bare(A, b), { at: [x, y], size: 32, cw: 56, rh: 48, t0: 0 }); show(g, t0, .5); return g; };
+ mini([[0, 2], [3, 1]], [4, 5], 1240, 340, m('below') + .4);
+ mini([[1, 2], [0, 0]], [1, 0], 1240, 600, m('zero0') + .3);
+ mini([[1, 2], [0, 0]], [1, 4], 1240, 760, m('zeroc') + .3);
+ }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['A 0 in a pivot spot: swap with a row below that has a number there.', 'w1'], ['A swap moves no line or plane: the same equations, a new order.', 'w2'],
+ ['No row to swap up: elimination ends in a row of zeros on the left.', 'w3'], ['0 = 0: endlessly many solutions. 0 = 4: none.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
+ mk('circle', { cx: 120, cy: -12, r: 26, fill: COL.chalk }, g);
+ T(g, String(i + 1), { x: 120, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 170, size: 34, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ });
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-swap', prompt: ['Each first equation has no x. Swap the rows, then solve.'],
+ build: blanks(SWAPQ),
+ }], done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-kind', prompt: ['Eliminate, then say how many solutions.'],
+ build: grid(KINDQ, KIND, { text: true }),
+ }], done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-miss', prompt: ['Find the missing number.'],
+ build: blanks(MISSQ),
+ }], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Break it on purpose', 60, 110, .2, { size: 40, weight: 600 });
+ const t = two(p, HANDS[0].A, HANDS[0].b);
+ S.sys = t.sys; S.el = t.el;
+ S.ver = verdict(p, t.sys, t.el, .3);
+ }, { ask: done => quiz({ x: 40, y: 672, w: 720, cls: 'side' }, [...HANDS.map((h, k) => ({
+ id: `p-break${k + 1}`, prompt: [h.prompt],
+ build: (body, api) => { put(S.ver, { o: 1 }); S.el.load(keys2(h.A, h.b)); return lsTask(S.sys, h.test, h.why, h.hint, () => S.sys.set(h.answer), { only: h.only })(body, api); },
+ })), {
+ id: 'p-break3', prompt: ['Drag the multiplier until row 2 has no x. What is left?'],
+ build: (body, api) => { put(S.ver, { o: 0 }); S.el.load(keys2([[3, 1], [6, 2]], [2, 4])); S.el.opNow(1, 0); return elTask(S.el, v => v.a10 === 0, 'ℓ = 2: row 2 becomes 0x + 0y = 0, so 0 = 0. The two lines were one: endlessly many solutions.',
+ (v, l) => `Row 2 still has ${num(v.a10)}x. The pivot is 3 and the number to remove is 6.`, () => S.el.set({ l: 2 }))(body, api); },
+ }], done, 'Chapter practice · set 4 of 4') }],
+ ['play', 'Playground', (m) => {
+ const p = panel(0);
+ text(p, 'Playground', 60, 110, .2, { size: 40, weight: 600 });
+ const t = two(p, [[1, 2], [2, 4]], [1, 6]);
+ S.sys = t.sys; S.el = t.el;
+ S.el.op(1, 0, 0, .3);
+ const hint = text(p, 'try: make 0 = 0; make 0 = 4; put a 0 in the pivot spot and drag the multiplier', 90, 380, m('go'), { size: 24, fill: COL.dim });
+ }, { ask: playAsk(() => S.el, { pos: { x: 40, y: 556, w: 720, cls: 'side' }, tip: 'Your system. Drag the multiplier, change any number, drag a line, or draw on the board. Nothing is marked.' }) }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/ch21/audio/en/both.mp3 b/site/linear-algebra/ch21/audio/en/both.mp3
new file mode 100644
index 0000000..ef6d18e
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/both.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/e32.mp3 b/site/linear-algebra/ch21/audio/en/e32.mp3
new file mode 100644
index 0000000..8ec9921
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/e32.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/ex2.mp3 b/site/linear-algebra/ch21/audio/en/ex2.mp3
new file mode 100644
index 0000000..e2eee05
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/ex2.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/final1.mp3 b/site/linear-algebra/ch21/audio/en/final1.mp3
new file mode 100644
index 0000000..f25e6b7
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/final2.mp3 b/site/linear-algebra/ch21/audio/en/final2.mp3
new file mode 100644
index 0000000..c0f9d37
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/final3.mp3 b/site/linear-algebra/ch21/audio/en/final3.mp3
new file mode 100644
index 0000000..67e6a71
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/final4.mp3 b/site/linear-algebra/ch21/audio/en/final4.mp3
new file mode 100644
index 0000000..d13a6af
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/finish.mp3 b/site/linear-algebra/ch21/audio/en/finish.mp3
new file mode 100644
index 0000000..5731b63
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/identity.mp3 b/site/linear-algebra/ch21/audio/en/identity.mp3
new file mode 100644
index 0000000..6f2be98
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/identity.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/intro.mp3 b/site/linear-algebra/ch21/audio/en/intro.mp3
new file mode 100644
index 0000000..d762d83
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/lec.mp3 b/site/linear-algebra/ch21/audio/en/lec.mp3
new file mode 100644
index 0000000..99695fd
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/lec.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/left.mp3 b/site/linear-algebra/ch21/audio/en/left.mp3
new file mode 100644
index 0000000..6bf6430
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/left.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/order.mp3 b/site/linear-algebra/ch21/audio/en/order.mp3
new file mode 100644
index 0000000..fc66cb0
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/order.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/play.mp3 b/site/linear-algebra/ch21/audio/en/play.mp3
new file mode 100644
index 0000000..bc940e4
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/play.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/q1.mp3 b/site/linear-algebra/ch21/audio/en/q1.mp3
new file mode 100644
index 0000000..384ebdf
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/q2.mp3 b/site/linear-algebra/ch21/audio/en/q2.mp3
new file mode 100644
index 0000000..34dbb6b
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/q3.mp3 b/site/linear-algebra/ch21/audio/en/q3.mp3
new file mode 100644
index 0000000..23d4e2b
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/q4.mp3 b/site/linear-algebra/ch21/audio/en/q4.mp3
new file mode 100644
index 0000000..0c11fcd
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/q4.mp3 differ
diff --git a/site/linear-algebra/ch21/audio/en/timings.js b/site/linear-algebra/ch21/audio/en/timings.js
new file mode 100644
index 0000000..5887478
--- /dev/null
+++ b/site/linear-algebra/ch21/audio/en/timings.js
@@ -0,0 +1,608 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 12.288,
+ "marks": {
+ "sub": 3.477,
+ "move": 8.646
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter twenty-one."
+ ],
+ [
+ 1.55,
+ "Elimination matrices."
+ ],
+ [
+ 3.477,
+ "Every step of elimination is one multiplication, by a matrix on the left."
+ ],
+ [
+ 8.646,
+ "Change one number of that matrix, and the step happens."
+ ]
+ ]
+ },
+ "left": {
+ "dur": 74.52,
+ "marks": {
+ "sys": 10.169,
+ "E": 19.583,
+ "row2": 22.539,
+ "w": 31.042,
+ "sum": 34.661,
+ "one": 40.391,
+ "w1": 41.862,
+ "turn": 47.122,
+ "m3": 52.917,
+ "w3": 55.065,
+ "flat": 65.234,
+ "step": 68.203
+ },
+ "cues": [
+ [
+ 0.104,
+ "In chapter nine, a matrix times a column of numbers took a mix of the matrix's columns."
+ ],
+ [
+ 6.198,
+ "Now the numbers go on the left of a matrix, and they mix its rows."
+ ],
+ [
+ 10.169,
+ "Here is chapter sixteen's system, x plus two y equals five, and three x plus four y equals eleven, as the table A, b."
+ ],
+ [
+ 19.583,
+ "On its left stands a new matrix, E."
+ ],
+ [
+ 22.539,
+ "Look at the second row of E: zero, one."
+ ],
+ [
+ 25.846,
+ "It says how much of each row of A, b goes into the second row of the answer."
+ ],
+ [
+ 31.042,
+ "Zero times row one, plus one times row two."
+ ],
+ [
+ 34.661,
+ "Add them, number by number: three, four, eleven."
+ ],
+ [
+ 38.724,
+ "That's just row two again."
+ ],
+ [
+ 40.391,
+ "Now make it one, one."
+ ],
+ [
+ 41.862,
+ "One times row one, plus one times row two: four, six, sixteen."
+ ],
+ [
+ 47.122,
+ "That's the two equations added, and in the picture the coral line turns about the meeting point."
+ ],
+ [
+ 52.917,
+ "Now make it minus three, one."
+ ],
+ [
+ 55.065,
+ "Minus three times row one is minus three, minus six, minus fifteen."
+ ],
+ [
+ 60.677,
+ "Add row two, and you get zero, minus two, minus four."
+ ],
+ [
+ 65.234,
+ "The x is gone, and the line lies flat."
+ ],
+ [
+ 68.203,
+ "That's exactly the step of chapter sixteen: row two minus three times row one."
+ ]
+ ]
+ },
+ "identity": {
+ "dur": 48.336,
+ "marks": {
+ "r1": 1.758,
+ "same": 7.096,
+ "eye": 9.753,
+ "ia": 20.299,
+ "three": 24.674,
+ "e": 28.477,
+ "spot": 33.581,
+ "rule": 39.609
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now the first row of E."
+ ],
+ [
+ 1.758,
+ "It's one, zero: one times row one, plus zero times row two."
+ ],
+ [
+ 7.096,
+ "That's row one itself, unchanged."
+ ],
+ [
+ 9.753,
+ "A matrix with ones down its diagonal and zeros everywhere else changes nothing: each row takes just itself."
+ ],
+ [
+ 18.021,
+ "It's called the identity matrix, I."
+ ],
+ [
+ 20.299,
+ "I times A is A, the way one times a number is that number."
+ ],
+ [
+ 24.674,
+ "The three by three identity has three ones."
+ ],
+ [
+ 28.477,
+ "So the matrix of our step is the identity with minus three in one spot: row two, column one."
+ ],
+ [
+ 35.625,
+ "That's the spot of the number it removes, so we call it E two one."
+ ],
+ [
+ 39.609,
+ "The rule: for row i minus ell times row j, put minus ell into row i, column j of the identity."
+ ]
+ ]
+ },
+ "ex2": {
+ "dur": 36.6,
+ "marks": {
+ "sys": 2.826,
+ "l": 8.151,
+ "e": 12.93,
+ "go": 19.01,
+ "w": 20.716,
+ "res": 26.745,
+ "flat": 29.102,
+ "pt": 33.958
+ },
+ "cues": [
+ [
+ 0.104,
+ "Another one, from chapter seventeen."
+ ],
+ [
+ 2.826,
+ "x plus two y equals three, and minus two x plus y equals four."
+ ],
+ [
+ 8.151,
+ "The multiplier is minus two divided by one, which is minus two."
+ ],
+ [
+ 12.93,
+ "So E two one gets minus minus two, which is plus two, in row two, column one."
+ ],
+ [
+ 19.01,
+ "Watch row two of the answer."
+ ],
+ [
+ 20.716,
+ "Two times row one is two, four, six."
+ ],
+ [
+ 23.568,
+ "Add row two, minus two, one, four, and you get zero, five, ten."
+ ],
+ [
+ 29.102,
+ "Five y equals ten: the x is gone, and y equals two."
+ ],
+ [
+ 33.958,
+ "The meeting point stays at minus one, two."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 5.112,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.107,
+ "Write E two one for this system, and work out the new row two."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 6.336,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 0.964,
+ "Drag the number in row two, column one of E until the coral line lies flat."
+ ]
+ ]
+ },
+ "lec": {
+ "dur": 55.8,
+ "marks": {
+ "sys": 2.721,
+ "e": 12.031,
+ "r1": 22.409,
+ "r2": 27.057,
+ "res": 40.482,
+ "r3": 43.88,
+ "turn": 50.677
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now the lecture's three equations."
+ ],
+ [
+ 2.721,
+ "x plus two y plus z equals two, three x plus eight y plus z equals twelve, and four y plus z equals two."
+ ],
+ [
+ 12.031,
+ "The first step was row two minus three times row one, so E two one is the three by three identity with minus three in row two, column one."
+ ],
+ [
+ 22.409,
+ "Row one of E is one, zero, zero: row one stays."
+ ],
+ [
+ 27.057,
+ "Row two is minus three, one, zero."
+ ],
+ [
+ 30.703,
+ "Minus three times row one is minus three, minus six, minus three, minus six."
+ ],
+ [
+ 37.487,
+ "Add row two, three, eight, one, twelve, and you get zero, two, minus two, six."
+ ],
+ [
+ 43.88,
+ "Row three is zero, zero, one: row three stays."
+ ],
+ [
+ 49.036,
+ "It had no x already."
+ ],
+ [
+ 50.677,
+ "In the picture, the coral plane has turned on its hinge, as in chapter eighteen."
+ ]
+ ]
+ },
+ "e32": {
+ "dur": 39.6,
+ "marks": {
+ "e": 4.661,
+ "base": 11.823,
+ "r3": 17.018,
+ "res": 30.43,
+ "u": 33.854,
+ "flat": 37.565
+ },
+ "cues": [
+ [
+ 0.104,
+ "The second step was row three minus two times row two."
+ ],
+ [
+ 4.661,
+ "Its matrix is E three two: the identity with minus two in row three, column two."
+ ],
+ [
+ 11.823,
+ "It multiplies what E two one left behind: the table after column one."
+ ],
+ [
+ 17.018,
+ "Row three of the answer is minus two times row two, plus row three."
+ ],
+ [
+ 22.396,
+ "Minus two times row two is zero, minus four, four, minus twelve."
+ ],
+ [
+ 27.734,
+ "Add zero, four, one, two, and you get zero, zero, five, minus ten."
+ ],
+ [
+ 33.854,
+ "That's U and c, the triangle from chapter eighteen."
+ ],
+ [
+ 37.565,
+ "And the yellow plane lies flat."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 3.696,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.12,
+ "Write the whole matrix for one step."
+ ]
+ ]
+ },
+ "both": {
+ "dur": 57.24,
+ "marks": {
+ "write": 2.461,
+ "read": 8.854,
+ "one": 13.294,
+ "r": 19.544,
+ "r12": 26.458,
+ "r3": 33.568,
+ "res": 47.331,
+ "ea": 49.792,
+ "go": 54.062
+ },
+ "cues": [
+ [
+ 0.104,
+ "Two steps, two matrices."
+ ],
+ [
+ 2.461,
+ "In symbols: E three two, times E two one times A, equals U."
+ ],
+ [
+ 8.854,
+ "Read it from the right."
+ ],
+ [
+ 10.104,
+ "E two one acts first, so it stands next to A."
+ ],
+ [
+ 13.294,
+ "We can also multiply the two matrices first, and get one matrix that does both steps."
+ ],
+ [
+ 19.544,
+ "Each row of E three two mixes the rows of E two one, the same way as before."
+ ],
+ [
+ 26.458,
+ "Rows one and two of E three two are rows of the identity, so they copy rows one and two of E two one."
+ ],
+ [
+ 33.568,
+ "Row three is minus two times row two, plus row three."
+ ],
+ [
+ 38.294,
+ "Minus two times minus three, one, zero is six, minus two, zero."
+ ],
+ [
+ 44.375,
+ "Add zero, zero, one, and you get six, minus two, one."
+ ],
+ [
+ 49.792,
+ "This one matrix E, times A, gives U at once."
+ ],
+ [
+ 54.062,
+ "Both planes turn together, each on its hinge."
+ ]
+ ]
+ },
+ "order": {
+ "dur": 33.528,
+ "marks": {
+ "r2": 5.247,
+ "r3": 11.51,
+ "diff": 20.417,
+ "why": 23.125
+ },
+ "cues": [
+ [
+ 0.091,
+ "What if we multiply the other way round, E two one times E three two?"
+ ],
+ [
+ 5.247,
+ "Row two is minus three times row one plus row two: minus three, one, zero."
+ ],
+ [
+ 11.51,
+ "Row three of E two one is zero, zero, one, so it copies row three of E three two: zero, minus two, one."
+ ],
+ [
+ 20.417,
+ "No six."
+ ],
+ [
+ 21.615,
+ "It's a different matrix."
+ ],
+ [
+ 23.125,
+ "E three two has to act on row two after row two has changed, so it must come second."
+ ],
+ [
+ 29.062,
+ "The order of the steps is the order of the product, read from right to left."
+ ]
+ ]
+ },
+ "q4": {
+ "dur": 8.424,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn, in three dimensions."
+ ],
+ [
+ 2.63,
+ "Drag the number in row three, column two of E until the yellow plane lies flat."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 30.48,
+ "marks": {
+ "w1": 1.042,
+ "w2": 6.862,
+ "w3": 11.172,
+ "w4": 19.505,
+ "end": 28.333
+ },
+ "cues": [
+ [
+ 0.104,
+ "Let's sum up."
+ ],
+ [
+ 1.042,
+ "Each row of E times A is a mix of the rows of A: row i of E gives the amounts."
+ ],
+ [
+ 6.862,
+ "The identity I changes nothing: I times A is A."
+ ],
+ [
+ 11.172,
+ "Row i minus ell times row j is the matrix E: the identity with minus ell in row i, column j."
+ ],
+ [
+ 19.505,
+ "Several steps multiply in order: E three two times E two one times A is U, and the first step stands next to A."
+ ],
+ [
+ 28.333,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 4.056,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.589,
+ "Find the matrix for each step."
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 3.576,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Set two."
+ ],
+ [
+ 1.081,
+ "Work out a row of E times A, b."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 3.72,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Set three."
+ ],
+ [
+ 1.25,
+ "Multiply elimination matrices."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 5.52,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.263,
+ "Change the numbers of E with your own hands until the step is done."
+ ]
+ ]
+ },
+ "play": {
+ "dur": 12.48,
+ "marks": {
+ "go": 3.633
+ },
+ "cues": [
+ [
+ 0.104,
+ "Playground."
+ ],
+ [
+ 1.081,
+ "Nothing here is marked right or wrong."
+ ],
+ [
+ 3.633,
+ "Change any number of E, or of A and b, drag a line, and watch each row of the answer mix the rows of A."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 10.32,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Well done."
+ ],
+ [
+ 1.055,
+ "That's the end of chapter twenty-one, Elimination Matrices."
+ ],
+ [
+ 5.182,
+ "Next: chapter twenty-two, where row exchanges become matrices too."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch21/audio/en/wrap.mp3 b/site/linear-algebra/ch21/audio/en/wrap.mp3
new file mode 100644
index 0000000..17d3857
Binary files /dev/null and b/site/linear-algebra/ch21/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch21/index.html b/site/linear-algebra/ch21/index.html
new file mode 100644
index 0000000..2ebbcf3
--- /dev/null
+++ b/site/linear-algebra/ch21/index.html
@@ -0,0 +1,375 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Elimination Matrices</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="../lib/space3.js"></script>
+<script src="../lib/elim.js"></script>
+<script src="../lib/emat.js"></script>
+<script src="../lib/play.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 21, title: 'Elimination Matrices', minutes: 11, language: 'en', next: '../ch22/' };
+
+/* ---------- chapter drawing helpers ---------- */
+const BLUE = LS_ROW[0], CORAL = LS_ROW[1], YELLOW = S3_ROW[2];
+const LEC = { A: [[1, 2, 1], [3, 8, 1], [0, 4, 1]], b: [2, 12, 2] }; // the lecture's system (OCW 18.06, lecture 2)
+const AFTER1 = { A: [[1, 2, 1], [0, 2, -2], [0, 4, 1]], b: [2, 6, 2] }; // after column 1
+const E21 = [[1, 0, 0], [-3, 1, 0], [0, 0, 1]], E32 = [[1, 0, 0], [0, 1, 0], [0, -2, 1]], EE = [[1, 0, 0], [-3, 1, 0], [6, -2, 1]];
+const AT2 = [70, 290], AT3 = [64, 262]; // where E · [A | b] = [EA | Eb] starts (2D, 3D)
+const CARD2 = { x: 40, y: 600, w: 760, cls: 'side' }, CARD3 = { x: 40, y: 640, w: 800, cls: 'side' };
+const say = (p, parts, x, y, t0, { size = 40, fill = COL.chalk, anchor = 'start' } = {}) => { const e = M(p, [].concat(parts), { x, y, size, fill, anchor, o: 0 }); show(e, t0); return e; };
+const text = (p, str, x, y, t0, { size = 30, fill = COL.chalk, anchor = 'start', weight = 500 } = {}) => { const e = T(p, str, { x, y, size, fill, anchor, weight, o: 0 }); show(e, t0); return e; };
+const thick = (sys, i, t0) => { tw(sys.lines[i].l, { 'a_stroke-width': 10 }, t0, .35); tw(sys.lines[i].l, { 'a_stroke-width': 5 }, t0 + .9, .6); };
+// 2D: the plane on the right (moved over a little to leave room for three matrices), no equations (the product is them).
+const two = (p, { A, b }, caption, { t0 = .1, E = null } = {}) => {
+ const sys = linsys(p, { A, b, eq: [90, 200], mat: null, sol: false, plane: { cx: 1215, u: 50 }, t0 });
+ sys.E.style.display = 'none';
+ if (caption) say(p, [caption], 70, 175, t0 + .1, { size: 28, fill: COL.dim });
+ const em = emat(p, sys, { A, b, E, at: AT2, size: 38, cw: 64, ecw: 56, rh: 62, gap: 66, t0 });
+ return { sys, em };
+};
+// 3D: the space on the right, smaller and further out, three 3 × 3 tables on the left.
+const three = (p, { A, b }, caption, { t0 = .1, E = null, view = { yaw: -40, pitch: 20 } } = {}) => {
+ const sys = lin3(p, { A, b, eq: [90, 190], mat: null, sol: false, space: { cx: 1262, size: 520, ...view }, t0 });
+ sys.E.style.display = 'none';
+ if (caption) say(p, [caption], 64, 160, t0 + .1, { size: 26, fill: COL.dim });
+ const em = emat(p, sys, { A, b, E, at: AT3, size: 32, cw: 52, ecw: 44, rh: 54, gap: 64, t0 });
+ return { sys, em, V: sys.space };
+};
+// A matrix times a matrix with no picture (E₃₂E₂₁): emat on a bare system, the b columns hidden.
+const bare = A => {
+ const v = {}, fs = [];
+ A.forEach((r, i) => { r.forEach((x, j) => { v[`a${i}${j}`] = x; }); v[`b${i}`] = 0; });
+ return { v, set(to) { Object.assign(v, to); fs.forEach(f => f(v)); }, onChange: f => fs.push(f), solve: () => ({}), live() {}, to() {} };
+};
+const mm = (p, Ebig, Bm, names, nameE, at, t0) => emat(p, bare(Bm), { A: Bm, b: [0, 0, 0], E: Ebig, at, size: 32, cw: 52, ecw: 44, rh: 54, gap: 64, t0, noB: true, names, name: nameE });
+// The old line of row 2 (dashed) and a ring round the point that never moves (chapter 16).
+const ghost = (sys, a, b, sx, sy, t0) => { const l = sys.P.line(sx, sy, sx + b, sy - a, CORAL, t0, { dash: '10 10', w: 3, into: sys.stage }); tw(l, { o: .45 }, t0 + .6, .4); return l; };
+const pin = (sys, x, y, t0) => { const g = G(sys.stage, { x: sys.P.PX(x), y: sys.P.PY(y), o: 0 }); mk('circle', { r: 20, fill: 'none', stroke: COL.chalk, 'stroke-width': 3.5, 'stroke-dasharray': '6 5' }, g); show(g, t0, .4); return g; };
+const hinge = (sys, n, t0, dur = 1.6) => prog(q => sys.lines[n].e.setAttribute('stroke-width', 2.5 + 5 * Math.sin(Math.PI * q)), t0, dur, lin);
+// A small matrix drawn as numbers in brackets (the identity, a product to compare).
+const matDraw = (p, rows, x, y, t0, { size = 34, cw = 50, rh = 46, name = '', ring = null } = {}) => {
+ const g = G(p, { o: 0 }), n = rows.length, w = rows[0].length * cw, top = y - size * .95, bot = y + (n - 1) * rh + size * .35;
+ path(g, `M${x + 12} ${top}H${x}V${bot}H${x + 12}M${x + w - 12} ${top}H${x + w}V${bot}H${x + w - 12}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });
+ rows.forEach((r, i) => r.forEach((v, j) => M(g, [num(v)], { x: x + cw * (j + .5), y: y + i * rh, size, fill: COL.chalk, anchor: 'middle' })));
+ if (name) M(g, [].concat(name), { x: x - 18, y: y + (n - 1) * rh / 2 + 10, size: size * 1.05, fill: COL.chalk, anchor: 'end' });
+ if (ring) mk('ellipse', { cx: x + cw * (ring[1] + .5), cy: y + ring[0] * rh - size * .32, rx: cw * .48, ry: size * .62, fill: 'none', stroke: COL.chalk, 'stroke-width': 3 }, g);
+ show(g, t0, .5);
+ return g;
+};
+const triangle = (p, el, t0) => {
+ const e = path(p, `M${el.cx(0) - 28} ${el.ry(0) - 40}L${el.cx(2) + 30} ${el.ry(0) - 40}L${el.cx(2) + 30} ${el.ry(2) + 16}Z`, { fill: COL.chalk, stroke: COL.chalk, 'stroke-width': 2, 'fill-opacity': .1 }, { o: 0 });
+ show(e, t0, .6);
+ return e;
+};
+const keysOf = ({ A, b }, E = null) => {
+ const o = {}, n = A.length;
+ A.forEach((r, i) => { r.forEach((x, j) => { o[`a${i}${j}`] = x; o[`e${i}${j}`] = E ? E[i][j] : +(i === j); }); o[`b${i}`] = b[i]; });
+ return o;
+};
+
+/* ---------- practice data (every answer worked twice: by the rule, and by multiplying out) ---------- */
+const STEPQ = [
+ { parts: ['2 × 2, row 2 − 5 × row 1: E₂₁ has ', { box: '-5' }, ' in row 2, column 1'], why: 'Minus the multiplier: −5. Row 2 of E is (−5, 1): −5 × row 1 + row 2.', hint: 'The entry is minus ℓ.' },
+ { parts: ['2 × 2, row 2 + 3 × row 1: E₂₁ has ', { box: '3' }, ' in row 2, column 1'], why: 'Adding 3 × row 1 is taking away −3 × row 1: ℓ = −3, so the entry is 3.', hint: 'Row 2 of E is (amount of row 1, amount of row 2).' },
+ { parts: ['3 × 3, row 3 − 4 × row 1: the entry ', { box: '-4' }, ' sits in row ', { box: '3' }, ', column ', { box: '1' }], why: 'The row that changes (3), the row that is used (1), and −ℓ = −4.', hint: 'Row i − ℓ × row j puts −ℓ in row i, column j.' },
+ { parts: ['3 × 3, row 3 − ½ × row 2: E₃₂ has ', { box: '-1/2' }, ' in row 3, column 2'], why: '−ℓ = −½.', hint: 'Minus the multiplier, a fraction this time.' },
+ { parts: ['x + y = 2, 5x + 3y = 8: E₂₁ has ', { box: '-5' }, ' in row 2, column 1'], why: 'ℓ = 5 ÷ 1 = 5, so −5.', hint: 'First the multiplier: number to remove ÷ pivot.' },
+ { parts: ['2x + y = 1, −6x + y = 5: E₂₁ has ', { box: '3' }, ' in row 2, column 1'], why: 'ℓ = −6 ÷ 2 = −3, so −ℓ = 3: add 3 × row 1.', hint: 'ℓ = −6 ÷ 2. Then change its sign.' },
+];
+const ROWQ = [
+ { parts: ['E: (1, 0), (−2, 1); A | b: (1, 3 | 4), (2, 5 | 9): row 2 = (', { box: '0' }, ', ', { box: '-1' }, ' | ', { box: '1' }, ')'], why: '−2 × (1, 3 | 4) + (2, 5 | 9) = (−2 + 2, −6 + 5 | −8 + 9).', hint: 'Row 2 of E says: −2 of row 1, plus 1 of row 2.' },
+ { parts: ['E: (1, 0), (3, 1); A | b: (1, −1 | 2), (−3, 4 | 1): row 2 = (', { box: '0' }, ', ', { box: '1' }, ' | ', { box: '7' }, ')'], why: '3 × (1, −1 | 2) = (3, −3 | 6); add (−3, 4 | 1).', hint: '3 × row 1 is (3, −3 | 6).' },
+ { parts: ['E: (1, 0), (1, 1); A | b: (2, 1 | 3), (−2, 3 | 5): row 2 = (', { box: '0' }, ', ', { box: '4' }, ' | ', { box: '8' }, ')'], why: 'Row 1 + row 2: (2 − 2, 1 + 3 | 3 + 5).', hint: 'One of each row: add them.' },
+ { parts: ['row 3 of E: (−2, 0, 1); rows 1, 3 of A | b: (1, 1, 1 | 3), (2, 3, 4 | 9): row 3 = (', { box: '0' }, ', ', { box: '1' }, ', ', { box: '2' }, ' | ', { box: '3' }, ')'], why: '−2 × (1, 1, 1 | 3) + (2, 3, 4 | 9) = (0, 1, 2 | 3). Row 2 is not used (amount 0).', hint: 'Row 3 of E: −2 of row 1, none of row 2, 1 of row 3.' },
+ { parts: ['row 1 of E: (1, 0, 0); row 1 of A | b: (1, 1, 1 | 3): row 1 = (', { box: '1' }, ', ', { box: '1' }, ', ', { box: '1' }, ' | ', { box: '3' }, ')'], why: 'Row 1 of E is (1, 0, 0): row 1 itself.', hint: 'Which rows does (1, 0, 0) take?' },
+];
+const PRODQ = [
+ { parts: ['E₂₁ has −2 in row 2, column 1; E₃₂ has −3 in row 3, column 2: row 3 of E₃₂E₂₁ = (', { box: '6' }, ', ', { box: '-3' }, ', ', { box: '1' }, ')'], why: '−3 × (−2, 1, 0) + (0, 0, 1) = (6, −3, 1).', hint: 'Row 3 of E₃₂ is (0, −3, 1): −3 × row 2 of E₂₁, plus row 3 of E₂₁.' },
+ { parts: ['E₂₁: −1 in row 2, column 1; E₃₂: 4 in row 3, column 2: row 3 of E₃₂E₂₁ = (', { box: '-4' }, ', ', { box: '4' }, ', ', { box: '1' }, ')'], why: '4 × (−1, 1, 0) + (0, 0, 1) = (−4, 4, 1).', hint: 'Row 2 of E₂₁ is (−1, 1, 0).' },
+ { parts: ['the other order, E₂₁E₃₂ (−2 and −3 as in the first): row 3 = (', { box: '0' }, ', ', { box: '-3' }, ', ', { box: '1' }, ')'], why: 'Row 3 of E₂₁ is (0, 0, 1): it copies row 3 of E₃₂.', hint: 'Now E₂₁ is on the left: its rows mix the rows of E₃₂.' },
+ { parts: ['in E₃₂E₂₁A, the step done first is E', { box: '21' }], why: 'E₂₁ stands next to A: it acts first. Read right to left.', hint: 'Which matrix touches A?' },
+];
+// Hands-on in 3D: lecture A, then a system of our own through column 1 (two numbers at once) and column 2.
+const OWN = { A: [[1, 1, 1], [2, 3, 1], [-1, 1, 2]], b: [3, 6, 2] }, OWN1 = { A: [[1, 1, 1], [0, 1, -1], [0, 2, 3]], b: [3, 0, 5] };
+const HANDS = [
+ { sys: LEC, only: ['e10'], test: (v, pr) => Math.abs(pr.a10) < 1e-9, ans: { e10: -3 }, prompt: 'Make row 2 of the answer lose its x (the lecture’s first step).',
+ why: '−3 in row 2, column 1: row 2 − 3 × row 1 = (0, 2, −2 | 6).', hint: (v, pr) => `Row 2 still has ${num(Math.round(pr.a10 * 10) / 10)}x. ℓ = 3 ÷ 1; the entry is −ℓ.` },
+ { sys: OWN, only: ['e10', 'e20'], test: (v, pr) => Math.abs(pr.a10) < 1e-9 && Math.abs(pr.a20) < 1e-9, ans: { e10: -2, e20: 1 }, prompt: 'One E for both steps of column 1: clear the x from rows 2 and 3.',
+ why: '−2 and 1: row 2 − 2 × row 1 and row 3 + row 1. Rows 2 and 3 become (0, 1, −1 | 0) and (0, 2, 3 | 5).', hint: (v, pr) => `Rows 2 and 3 still have ${num(Math.round(pr.a10 * 10) / 10)}x and ${num(Math.round(pr.a20 * 10) / 10)}x. The pivot is 1.` },
+ { sys: OWN1, only: ['e21'], test: (v, pr) => Math.abs(pr.a21) < 1e-9, ans: { e21: -2 }, prompt: 'Column 2: make the yellow plane flat.',
+ why: '−2 in row 3, column 2: row 3 − 2 × row 2 = (0, 0, 5 | 5), so z = 1.', hint: (v, pr) => `Row 3 still has ${num(Math.round(pr.a21 * 10) / 10)}y. The pivot of row 2 is 1, the number to remove 2.` },
+];
+
+/* ---------- beats ---------- */
+const BEATS = [
+ ['intro', 'Elimination matrices', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 2, Chapter 21', { x: 800, y: 270, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Elimination Matrices', { x: 800, y: 380, size: 88, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'every step of elimination is a multiplication by a matrix on the left', 800, 480, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });
+ const lg = G(scene, { o: 0 });
+ const s = bare([[1, 2], [3, 4]]); s.v.b0 = 5; s.v.b1 = 11;
+ const em = emat(lg, s, { A: [[1, 2], [3, 4]], b: [5, 11], at: [380, 640], size: 36, cw: 62, ecw: 54, rh: 56, t0: 0 });
+ show(lg, m('sub') + 1.5, .5);
+ em.ringE(1, 0, m('move') + .2);
+ em.to({ e10: -3 }, m('move') + .8, 2.2);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);
+ }],
+
+ ['left', 'Numbers on the left', (m) => {
+ const p = panel(0);
+ text(p, 'Numbers on the left mix the rows', 60, 110, .2, { size: 40, weight: 600 });
+ const L = { A: [[1, 2], [3, 4]], b: [5, 11] };
+ const { sys, em } = two(p, L, 'x + 2y = 5, 3x + 4y = 11', { t0: m('sys') - .3 });
+ put(em.Eg, { o: 0 }); show(em.Eg, m('E'), .5);
+ put(em.eqSign, { o: 0 }); show(em.eqSign, m('row2'), .4);
+ put(em.Pt.g, { o: 0 }); show(em.Pt.g, m('row2'), .5);
+ em.focusE(1, m('row2')); em.Pt.focus(1, m('row2'));
+ em.flashE(1, m('row2') + .4);
+ em.work(1, 0, { times: [m('w'), m('w') + 1.8, m('sum')] });
+ em.Pt.flash(1, m('sum'));
+ // chapter 9 in one line, then the new idea, while the voice recalls them
+ const c9 = text(p, 'chapter 9: A times a column of numbers = a mix of the columns of A', 70, 480, .6, { size: 26, fill: COL.dim, weight: 600 });
+ const nw = text(p, 'now: numbers on the left of A = a mix of the rows of A', 70, 530, 4.6, { size: 28, fill: COL.chalk, weight: 600 });
+ [c9, nw].forEach(e => hide(e, m('sys') + 1, .4));
+ [0, 1].forEach(i => em.B.flash(i, m('sys') + 2 + 2.5 * i));
+ ghost(sys, 3, 4, 1, 2, m('one'));
+ em.ringE(1, 0, m('one'));
+ em.to({ e10: 1 }, m('one') + .3, 1.6);
+ em.Pt.flash(1, m('w1') + 1);
+ pin(sys, 1, 2, m('turn') + 1);
+ em.to({ e10: -3 }, m('m3') + .3, 2.4);
+ em.Pt.flash(1, m('w3') + 3);
+ thick(sys, 1, m('flat'));
+ const st = G(p, { o: 0 });
+ M(st, ['row 2'], { x: 70, y: 610, size: 34, fill: CORAL, anchor: 'start' }); M(st, ['− 3 ×'], { x: 180, y: 610, size: 34, fill: COL.chalk, anchor: 'start' }); M(st, ['row 1'], { x: 290, y: 610, size: 34, fill: BLUE, anchor: 'start' });
+ T(st, 'chapter 16’s step, as a multiplication', { x: 70, y: 660, size: 26, fill: COL.dim, weight: 600 });
+ show(st, m('step'), .5);
+ }],
+
+ ['identity', 'The identity', (m) => {
+ const p = panel(0);
+ text(p, 'The identity, and E₂₁', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, em } = two(p, { A: [[1, 2], [3, 4]], b: [5, 11] }, 'x + 2y = 5, 3x + 4y = 11', { E: [[1, 0], [-3, 1]] });
+ em.focusE(0, m('r1')); em.Pt.focus(0, m('r1'));
+ em.work(0, 0, { times: [m('r1') + 1.6, m('r1') + 3, m('same')] });
+ em.Pt.flash(0, m('same'));
+ em.work(null, m('eye')); em.focusE(null, m('eye')); em.Pt.focus(null, m('eye'));
+ [0, 1].forEach(i => { em.B.flash(i, m('eye') + 3 + 2 * i); em.Pt.flash(i, m('eye') + 3.6 + 2 * i); });
+ matDraw(p, [[1, 0], [0, 1]], 150, 470, m('eye') + .4, { name: 'I =' });
+ say(p, ['I A = A'], 340, 494, m('ia'), { size: 38 });
+ matDraw(p, [[1, 0, 0], [0, 1, 0], [0, 0, 1]], 560, 470, m('three'), { size: 30, cw: 44, rh: 40 });
+ em.ringE(1, 0, m('spot'));
+ em.flashE(1, m('e') + 1, 0);
+ em.setName('E₂₁');
+ const nm = G(p, { o: 0 }); show(nm, m('spot') + 1.2, .4);
+ T(nm, 'row 2, column 1: E₂₁', { x: 70, y: 650, size: 30, fill: COL.chalk, weight: 600 });
+ text(p, 'row i − ℓ × row j: −ℓ in row i, column j of I', 70, 730, m('rule'), { size: 32, fill: COL.chalk, weight: 600 });
+ em.flashE(1, m('rule') + 3, 0); em.Pt.flash(1, m('rule') + 5); em.flashE(1, m('rule') + 7, 0);
+ }],
+
+ ['ex2', 'A plus sign', (m) => {
+ const p = panel(0);
+ text(p, 'A negative multiplier', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, em } = two(p, { A: [[1, 2], [-2, 1]], b: [3, 4] }, 'x + 2y = 3, −2x + y = 4', { t0: m('sys') - .3 });
+ say(p, ['ℓ = −2 ÷ 1 = −2'], 70, 610, m('l'), { size: 34, fill: COL.chalk });
+ say(p, ['−ℓ = +2'], 380, 610, m('e'), { size: 34, fill: COL.chalk });
+ em.ringE(1, 0, m('e') + .3);
+ ghost(sys, -2, 1, -1, 2, m('go'));
+ em.work(1, 0, { times: [m('w'), m('w') + 3, m('res')] });
+ em.to({ e10: 2 }, m('go') + .3, 2);
+ em.Pt.flash(1, m('res'));
+ thick(sys, 1, m('flat'));
+ say(p, ['5y = 10, y = 2'], 70, 680, m('flat') + .5, { size: 34, fill: CORAL });
+ pin(sys, -1, 2, m('pt')); pulse(sys.meet, m('pt') + .3);
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ const t = two(p, { A: [[1, 1], [4, 2]], b: [3, 10] }, 'x + y = 3, 4x + 2y = 10');
+ S.em = t.em;
+ }, { ask: done => quiz({ x: 40, y: 518, w: 760, cls: 'side' }, [{
+ id: 'c-e21', prompt: ['Row 2 − 4 × row 1, as a matrix.'],
+ build: blanks([
+ { parts: ['E₂₁ has ', { box: '-4' }, ' in row 2, column 1'], why: 'ℓ = 4 ÷ 1 = 4: the entry is −4.', hint: 'Minus the multiplier.',
+ fx: () => fxp(q => S.em.set({ e10: -4 * q }), 0, 1.6) },
+ { parts: ['row 2 of EA | Eb: (', { box: '0' }, ', ', { box: '-2' }, ' | ', { box: '-2' }, ')'], why: '−4 × (1, 1 | 3) + (4, 2 | 10) = (0, −2 | −2).', hint: '−4 × row 1 is (−4, −4 | −12). Add row 2.' },
+ ]),
+ }], done) }],
+
+ ['q2', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const t = two(p, { A: [[2, 1], [6, 4]], b: [1, 2] }, '2x + y = 1, 6x + 4y = 2');
+ S.em = t.em;
+ t.em.work(1, .3);
+ }, { ask: done => quiz(CARD2, [{
+ id: 'c-flat', prompt: ['Change the number in row 2, column 1 of E until the coral line lies flat.'],
+ build: emTask(S.em, (v, pr) => Math.abs(pr.a10) < 1e-9, '−3: row 2 − 3 × row 1 = (0, 1 | −1), so y = −1 and x = 1.',
+ (v, pr) => `Row 2 of the answer still has ${num(Math.round(pr.a10 * 10) / 10)}x. ℓ = 6 ÷ 2; E’s number is −ℓ.`, () => S.em.set({ e10: -3 }), { only: ['e10'] }),
+ }], done) }],
+
+ ['lec', 'The lecture’s E₂₁', (m) => {
+ const p = panel(0);
+ text(p, 'Three equations: E₂₁', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, em, V } = three(p, LEC, 'x + 2y + z = 2, 3x + 8y + z = 12, 4y + z = 2', { t0: m('sys') - .3 });
+ em.ringE(1, 0, m('e'));
+ em.to({ e10: -3 }, m('e') + .6, 3.2);
+ em.setName('E₂₁');
+ V.turn({ yaw: -10 }, m('e') + .6, 6);
+ [0, 1, 2].forEach(i => em.B.flash(i, m('sys') + .8 + 2.8 * i));
+ em.focusE(0, m('r1')); em.work(0, 0, { times: [m('r1'), m('r1') + 1, m('r1') + 1.3, m('r1') + 2.5] }); em.Pt.flash(0, m('r1') + 2.6);
+ em.focusE(1, m('r2')); em.work(1, 0, { times: [m('r2') + 3, m('res') - 5.5, m('res') - 5.2, m('res')] }); em.Pt.flash(1, m('res') + .3);
+ em.focusE(2, m('r3')); em.work(2, 0, { times: [m('r3'), m('r3') + .8, m('r3') + 1.2, m('r3') + 2.5] }); em.Pt.flash(2, m('r3') + 2.6);
+ em.focusE(null, m('turn'));
+ hinge(sys, 0, m('turn') + .3, 2); hinge(sys, 0, m('turn') + 2.6, 2);
+ V.turn({ yaw: 20 }, m('turn'), 5);
+ }],
+
+ ['e32', 'The lecture’s E₃₂', (m, D) => {
+ const p = panel(0);
+ text(p, 'Step two: E₃₂', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, em, V } = three(p, AFTER1, 'after column 1: x + 2y + z = 2, 2y − 2z = 6, 4y + z = 2', { view: { yaw: -20, pitch: 20 } });
+ em.ringE(2, 1, m('e'));
+ em.to({ e21: -2 }, m('e') + .6, 3);
+ em.setName('E₃₂');
+ [0, 1, 2].forEach(i => em.B.flash(i, m('base') + .2 * i));
+ em.focusE(2, m('r3')); em.work(2, 0, { times: [m('r3') + .5, m('r3') + 4.5, m('res') - 4, m('res')] });
+ em.Pt.flash(2, m('res') + .3);
+ em.focusE(null, m('u'));
+ triangle(p, em.Pt, m('u'));
+ say(p, ['U'], em.Pt.cx(1), em.Pt.ry(2) + 64, m('u') + .4, { size: 34, fill: COL.chalk, anchor: 'middle' });
+ V.turn({ yaw: 0, pitch: 34 }, m('flat') - 1, Math.max(1, D - m('flat') + .6));
+ sys.focus(2, m('flat'));
+ }],
+
+ ['q3', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ const t = three(p, { A: [[1, 1, 1], [0, 1, 2], [2, 3, 4]], b: [2, 3, 8] }, 'x + y + z = 2, y + 2z = 3, 2x + 3y + 4z = 8');
+ S.em = t.em;
+ }, { ask: done => quiz({ x: 40, y: 440, w: 820, cls: 'side' }, [{
+ id: 'c-e31', prompt: ['Write E₃₁, the matrix for row 3 − 2 × row 1, one row at a time.'],
+ build: blanks([
+ { parts: ['rows 1, 2 of E₃₁: (', { box: '1' }, ' ', { box: '0' }, ' ', { box: '0' }, '), (', { box: '0' }, ' ', { box: '1' }, ' ', { box: '0' }, ')'],
+ why: 'Rows 1 and 2 do not change: they are rows of I.', hint: 'Rows 1 and 2 stay as they are. Which amounts copy a row?' },
+ { parts: ['row 3 of E₃₁: (', { box: '-2' }, ' ', { box: '0' }, ' ', { box: '1' }, ')'],
+ why: '−2 of row 1 plus 1 of row 3: row 3 − 2 × row 1 = (0, 1, 2 | 4).', hint: 'Row 3 − 2 × row 1: how much of row 1, of row 2, of row 3?',
+ fx: () => fxp(q => S.em.set({ e20: -2 * q }), 0, 1.8) },
+ ]),
+ }], done) }],
+
+ ['both', 'Both steps at once', (m, D) => {
+ const p = panel(0);
+ text(p, 'Both steps in one matrix', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = lin3(p, { A: LEC.A, b: LEC.b, eq: [90, 190], mat: null, sol: false, space: { cx: 1262, size: 520, yaw: -30, pitch: 22 } });
+ sys.E.style.display = 'none';
+ const V = sys.space;
+ V.sway(5, 13);
+ const sym = G(p, { o: 0 }); show(sym, m('write'), .4);
+ M(sym, ['E₃₂ (E₂₁ A) = U'], { x: 64, y: 175, size: 36, fill: COL.chalk, anchor: 'start' });
+ const first = G(p, { o: 0 }); show(first, m('read'), .4); hide(first, m('one'), .4);
+ path(first, 'M235 195 Q 250 225 290 222', { stroke: COL.dim, 'stroke-width': 2.5, fill: 'none' });
+ T(first, 'acts first', { x: 300, y: 228, size: 24, fill: COL.dim, weight: 600 });
+ const part1 = G(p, { o: 0 }); show(part1, m('one'), .5); hide(part1, m('ea') - .2, .4);
+ const e1 = mm(part1, E32, E21, ['E₂₁', '', 'E₃₂E₂₁', ''], 'E₃₂', AT3, 0);
+ e1.work(0, 0, { times: [m('r12'), m('r12') + .5, m('r12') + .8, m('r12') + 1.6] }); e1.work(1, 0, { times: [m('r12') + 3, m('r12') + 3.5, m('r12') + 3.8, m('r12') + 4.6] }); e1.work(2, 0, { times: [m('r3') + .5, m('r3') + 4, m('res') - 3.5, m('res')] });
+ e1.Pt.flash(0, m('r12') + .6); e1.Pt.flash(1, m('r12') + 2.8); e1.Pt.flash(2, m('res'));
+ const part2 = G(p, { o: 0 }); show(part2, m('ea'), .5);
+ const e2 = emat(part2, sys, { A: LEC.A, b: LEC.b, at: AT3, size: 32, cw: 52, ecw: 44, rh: 54, gap: 64, t0: 0 });
+ e2.to({ e10: -3, e20: 6, e21: -2 }, m('ea') + 1, Math.max(2, D - m('ea') - .8));
+ e2.setName('E₃₂E₂₁');
+ e2.work(2, m('ea') + .5);
+ V.turn({ yaw: 10, pitch: 28 }, m('ea'), Math.max(2, D - m('ea')));
+ hinge(sys, 0, m('go') - .5, 1.6); hinge(sys, 2, m('go') - .5, 1.6);
+ }],
+
+ ['order', 'Order matters', (m) => {
+ const p = panel(0);
+ text(p, 'The other order', 60, 110, .2, { size: 40, weight: 600 });
+ say(p, ['E₂₁ E₃₂ = ?'], 64, 175, .3, { size: 36, fill: COL.chalk });
+ const e1 = mm(p, [[1, 0, 0], [0, 1, 0], [0, 0, 1]], E32, ['E₃₂', '', 'E₂₁E₃₂', ''], 'E₂₁', AT3, .2);
+ e1.ringE(1, 0, m('r2'));
+ e1.to({ e10: -3 }, m('r2') + .2, 1.6);
+ e1.work(1, 0, { times: [m('r2') + 1, m('r2') + 2, m('r2') + 2.6, m('r2') + 4] }); e1.Pt.flash(1, m('r2') + 4.2);
+ e1.work(2, 0, { times: [m('r3') + .5, m('r3') + 1, m('r3') + 3, m('r3') + 5] }); e1.Pt.flash(2, m('r3') + 5.2);
+ matDraw(p, EE, 1220, 262, m('diff'), { size: 32, cw: 56, rh: 54, name: ['E₃₂E₂₁ ='], ring: [2, 0] });
+ pulse(say(p, ['≠'], 990, 330, m('diff') + .5, { size: 56, fill: COL.bad, anchor: 'middle' }), m('why') + 1, 1.3);
+ e1.flashE(1, m('why') + 3, 0); e1.Pt.flash(2, m('why') + 5.5); e1.Pt.flash(1, m('why') + 7.5);
+ text(p, 'the 6 is missing: a different matrix', 64, 700, m('diff') + .6, { size: 30, fill: COL.bad, weight: 600 });
+ text(p, 'the order of the steps = the order of the product, read right to left', 64, 780, m('why') + 3, { size: 28, fill: COL.chalk, weight: 600 });
+ }],
+
+ ['q4', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const t = three(p, { A: [[2, 1, 1], [0, -1, 1], [0, 3, 2]], b: [3, -3, 4] }, 'after column 1: 2x + y + z = 3, −y + z = −3, 3y + 2z = 4');
+ S.em = t.em;
+ t.em.work(2, .3);
+ }, { ask: done => quiz(CARD3, [{
+ id: 'c-flat3', prompt: ['Change the number in row 3, column 2 of E until the yellow plane lies flat.'],
+ build: emTask(S.em, (v, pr) => Math.abs(pr.a21) < 1e-9, '3: ℓ = 3 ÷ (−1) = −3, so −ℓ = 3. Row 3 + 3 × row 2 = (0, 0, 5 | −5), z = −1.',
+ (v, pr) => `Row 3 of the answer still has ${num(Math.round(pr.a21 * 10) / 10)}y. The pivot of row 2 is −1.`, () => S.em.set({ e21: 3 }), { only: ['e21'] }),
+ }], done) }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['Each row of EA mixes the rows of A: row i of E gives the amounts.', 'w1'], ['The identity I changes nothing: I A = A.', 'w2'],
+ ['Row i − ℓ × row j is E: the identity with −ℓ in row i, column j.', 'w3'], ['Steps multiply in order: E₃₂ E₂₁ A = U; the first step stands next to A.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
+ mk('circle', { cx: 120, cy: -12, r: 26, fill: COL.chalk }, g);
+ T(g, String(i + 1), { x: 120, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 170, size: 34, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ });
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-step', prompt: ['Find the number elimination puts into the identity.'],
+ build: blanks(STEPQ),
+ }], done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-row', prompt: ['Each row of the answer mixes the rows of A | b. Rows are written (numbers of A | right side).'],
+ build: blanks(ROWQ),
+ }], done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-prod', prompt: ['Multiply elimination matrices. Each row of the left matrix mixes the rows of the right one.'],
+ build: blanks(PRODQ),
+ }], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Do the steps with E', 60, 110, .2, { size: 40, weight: 600 });
+ const t = three(p, LEC, '');
+ S.em = t.em;
+ }, { ask: done => quiz(CARD3, HANDS.map((h, k) => ({
+ id: `p-hand${k + 1}`, prompt: [h.prompt],
+ build: (body, api) => { S.em.set(keysOf(h.sys)); S.em.work(+h.only[h.only.length - 1][1], 0); return emTask(S.em, h.test, h.why, h.hint, () => S.em.set(h.ans), { only: h.only })(body, api); },
+ })), done, 'Chapter practice · set 4 of 4') }],
+ ['play', 'Playground', (m) => {
+ const p = panel(0);
+ text(p, 'Playground', 60, 110, .2, { size: 40, weight: 600 });
+ const t = two(p, { A: [[1, 2], [3, 4]], b: [5, 11] }, '');
+ S.em = t.em;
+ t.em.work(1, .3);
+ const hint = text(p, 'try: make the coral line flat; make it stand up; put 0 on E’s diagonal', 70, 175, m('go'), { size: 24, fill: COL.dim });
+ hide(hint, m('go') + 9, .6);
+ }, { ask: playAsk(() => S.em, { pos: { x: 40, y: 586, w: 760, cls: 'side' }, tip: 'Your matrices. Change any number of E or of A | b, drag a line, or draw on the board. Nothing is marked.' }) }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/ch22/audio/en/final1.mp3 b/site/linear-algebra/ch22/audio/en/final1.mp3
new file mode 100644
index 0000000..d50a343
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/final2.mp3 b/site/linear-algebra/ch22/audio/en/final2.mp3
new file mode 100644
index 0000000..14ce7d4
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/final3.mp3 b/site/linear-algebra/ch22/audio/en/final3.mp3
new file mode 100644
index 0000000..8a9c5a4
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/final4.mp3 b/site/linear-algebra/ch22/audio/en/final4.mp3
new file mode 100644
index 0000000..0aba3be
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/finish.mp3 b/site/linear-algebra/ch22/audio/en/finish.mp3
new file mode 100644
index 0000000..851f1a5
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/intro.mp3 b/site/linear-algebra/ch22/audio/en/intro.mp3
new file mode 100644
index 0000000..9ec2d73
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/name.mp3 b/site/linear-algebra/ch22/audio/en/name.mp3
new file mode 100644
index 0000000..236b2c2
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/name.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/play.mp3 b/site/linear-algebra/ch22/audio/en/play.mp3
new file mode 100644
index 0000000..57d2353
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/play.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/q1.mp3 b/site/linear-algebra/ch22/audio/en/q1.mp3
new file mode 100644
index 0000000..daef4ca
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/q2.mp3 b/site/linear-algebra/ch22/audio/en/q2.mp3
new file mode 100644
index 0000000..ee42aff
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/q3.mp3 b/site/linear-algebra/ch22/audio/en/q3.mp3
new file mode 100644
index 0000000..b7c4cc5
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/recall.mp3 b/site/linear-algebra/ch22/audio/en/recall.mp3
new file mode 100644
index 0000000..72ba168
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/recall.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/right.mp3 b/site/linear-algebra/ch22/audio/en/right.mp3
new file mode 100644
index 0000000..ed5f53b
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/right.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/six.mp3 b/site/linear-algebra/ch22/audio/en/six.mp3
new file mode 100644
index 0000000..673f819
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/six.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/three.mp3 b/site/linear-algebra/ch22/audio/en/three.mp3
new file mode 100644
index 0000000..1c0b7ac
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/three.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/timings.js b/site/linear-algebra/ch22/audio/en/timings.js
new file mode 100644
index 0000000..67eea08
--- /dev/null
+++ b/site/linear-algebra/ch22/audio/en/timings.js
@@ -0,0 +1,537 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 12.984,
+ "marks": {
+ "sub": 3.971,
+ "move": 9.44
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter twenty-two."
+ ],
+ [
+ 1.641,
+ "Row exchanges as matrices."
+ ],
+ [
+ 3.971,
+ "In chapter twenty we swapped two rows."
+ ],
+ [
+ 6.927,
+ "Now that swap becomes a matrix, and we'll meet every way to put three rows in order."
+ ]
+ ]
+ },
+ "recall": {
+ "dur": 50.328,
+ "marks": {
+ "sys": 2.812,
+ "zero": 8.164,
+ "ask": 11.732,
+ "eye": 14.232,
+ "swap": 18.216,
+ "p": 21.432,
+ "r1": 26.51,
+ "r2": 33.75,
+ "same": 41.589,
+ "piv": 48.216
+ },
+ "cues": [
+ [
+ 0.091,
+ "Remember this system from chapter twenty."
+ ],
+ [
+ 2.812,
+ "Zero x plus two y equals four, and three x plus y equals five."
+ ],
+ [
+ 8.164,
+ "The pivot spot holds a zero, so we swapped the rows."
+ ],
+ [
+ 11.732,
+ "Which matrix on the left does that swap?"
+ ],
+ [
+ 14.232,
+ "Start from the identity."
+ ],
+ [
+ 15.742,
+ "It leaves every row where it is."
+ ],
+ [
+ 18.216,
+ "Now swap the rows of the identity itself."
+ ],
+ [
+ 21.432,
+ "This is P: zero, one on top, and one, zero below."
+ ],
+ [
+ 26.51,
+ "Row one of P is zero, one: none of row one, all of row two."
+ ],
+ [
+ 32.122,
+ "So row two goes on top."
+ ],
+ [
+ 33.75,
+ "Row two of P is one, zero: all of row one, none of row two."
+ ],
+ [
+ 39.57,
+ "So row one goes to the bottom."
+ ],
+ [
+ 41.589,
+ "The rows have traded places."
+ ],
+ [
+ 43.568,
+ "In the picture nothing moves; the two lines just trade colours."
+ ],
+ [
+ 48.216,
+ "And now the pivot is three."
+ ]
+ ]
+ },
+ "name": {
+ "dur": 26.112,
+ "marks": {
+ "name": 0.091,
+ "rows": 6.523,
+ "ones": 10.234,
+ "where": 14.792,
+ "name2": 21.341
+ },
+ "cues": [
+ [
+ 0.091,
+ "A matrix like this is called a permutation matrix."
+ ],
+ [
+ 4.062,
+ "A permutation is a change of order."
+ ],
+ [
+ 6.523,
+ "It's the identity with its rows in a new order."
+ ],
+ [
+ 10.234,
+ "Every row has exactly one 1, and so does every column."
+ ],
+ [
+ 14.792,
+ "The 1 in row one says which row goes on top."
+ ],
+ [
+ 17.878,
+ "Here it sits in column two, so row two goes on top."
+ ],
+ [
+ 21.341,
+ "We call this one P one two, because it swaps rows one and two."
+ ]
+ ]
+ },
+ "three": {
+ "dur": 41.328,
+ "marks": {
+ "sys": 2.305,
+ "p": 10.729,
+ "r1": 19.167,
+ "r2": 24.258,
+ "r3": 28.581,
+ "tri": 33.529,
+ "same": 35.534
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now three equations."
+ ],
+ [
+ 2.305,
+ "Here is chapter twenty's system after column one."
+ ],
+ [
+ 5.794,
+ "The second pivot spot holds a zero, but row three has a one below it."
+ ],
+ [
+ 10.729,
+ "To swap rows two and three, take the three by three identity and swap its rows two and three."
+ ],
+ [
+ 17.63,
+ "That's P two three."
+ ],
+ [
+ 19.167,
+ "Row one of P is one, zero, zero: row one stays on top."
+ ],
+ [
+ 24.258,
+ "Row two is zero, zero, one: it takes row three."
+ ],
+ [
+ 28.581,
+ "Row three is zero, one, zero: it takes row two."
+ ],
+ [
+ 33.529,
+ "Now the table is a triangle."
+ ],
+ [
+ 35.534,
+ "And the planes have not moved at all: the same three equations, in a new order."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 4.56,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.159,
+ "Build the matrix that swaps rows one and three."
+ ]
+ ]
+ },
+ "twice": {
+ "dur": 29.616,
+ "marks": {
+ "again": 2.135,
+ "r1": 4.701,
+ "back": 8.607,
+ "pp": 10.599,
+ "undo": 13.529,
+ "calc": 15.716,
+ "calc2": 22.695,
+ "eye": 27.669
+ },
+ "cues": [
+ [
+ 0.091,
+ "What happens if we swap twice?"
+ ],
+ [
+ 2.135,
+ "Multiply by P one two once more."
+ ],
+ [
+ 4.701,
+ "Row one of P takes row two, which is now the old row one."
+ ],
+ [
+ 8.607,
+ "Everything is back where it started."
+ ],
+ [
+ 10.599,
+ "So P times P is the identity: a swap undoes itself."
+ ],
+ [
+ 15.716,
+ "We can check it on P itself."
+ ],
+ [
+ 17.513,
+ "Row one of P, zero, one, takes row two of P, which is one, zero."
+ ],
+ [
+ 22.695,
+ "Row two of P, one, zero, takes row one of P, which is zero, one."
+ ],
+ [
+ 27.669,
+ "The answer is the identity."
+ ]
+ ]
+ },
+ "six": {
+ "dur": 37.32,
+ "marks": {
+ "top": 3.138,
+ "next": 5.534,
+ "last": 8.451,
+ "count": 10.677,
+ "i": 16.562,
+ "swaps": 18.815,
+ "cycles": 25.859,
+ "two": 34.023
+ },
+ "cues": [
+ [
+ 0.117,
+ "How many ways can three rows be put in order?"
+ ],
+ [
+ 3.138,
+ "Any of the three can go on top."
+ ],
+ [
+ 5.534,
+ "Then either of the two that are left goes second, and the last one fills the bottom."
+ ],
+ [
+ 10.677,
+ "Three times two times one: six orders, so six permutation matrices."
+ ],
+ [
+ 16.562,
+ "The identity keeps the order."
+ ],
+ [
+ 18.815,
+ "Three of them swap one pair: rows one and two, rows one and three, or rows two and three."
+ ],
+ [
+ 25.859,
+ "And two of them move every row: each row moves down one place and the bottom one comes to the top, or the other way round."
+ ],
+ [
+ 34.023,
+ "Each of those two is one swap after another."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 5.016,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 0.99,
+ "Change the numbers of P until the table is a triangle."
+ ]
+ ]
+ },
+ "right": {
+ "dur": 57.48,
+ "marks": {
+ "sys": 2.018,
+ "cols": 9.479,
+ "c1": 13.906,
+ "c2": 23.281,
+ "swap": 26.654,
+ "eq": 28.555,
+ "xy": 35.911,
+ "pt": 41.758,
+ "flip": 45.169,
+ "rows": 50.326
+ },
+ "cues": [
+ [
+ 0.104,
+ "So far P stood on the left."
+ ],
+ [
+ 2.018,
+ "Now put it on the right of A, with x plus two y equals five, and three x plus four y equals eleven."
+ ],
+ [
+ 9.479,
+ "On the right, P mixes the columns of A, not its rows."
+ ],
+ [
+ 13.906,
+ "Column one of P is zero, one: none of column one, all of column two."
+ ],
+ [
+ 20.117,
+ "So the new first column is A's second column."
+ ],
+ [
+ 23.281,
+ "And the new second column is A's first."
+ ],
+ [
+ 26.654,
+ "The columns trade places."
+ ],
+ [
+ 28.555,
+ "Now the equations read two x plus y equals five, and four x plus three y equals eleven."
+ ],
+ [
+ 35.911,
+ "The numbers in front of x and y have traded, so x and y trade roles."
+ ],
+ [
+ 41.758,
+ "The meeting point moves from one, two to two, one."
+ ],
+ [
+ 45.169,
+ "The whole picture flips over the diagonal, the line where x equals y."
+ ],
+ [
+ 50.326,
+ "So P on the left swaps rows and moves nothing."
+ ],
+ [
+ 53.75,
+ "P on the right swaps columns, and swaps the unknowns."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 6.432,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.068,
+ "Change the numbers of P, on the right of A, until the lines meet at the ring."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 30.312,
+ "marks": {
+ "w1": 1.003,
+ "w2": 6.836,
+ "w3": 12.07,
+ "w4": 18.581,
+ "end": 28.034
+ },
+ "cues": [
+ [
+ 0.104,
+ "Let's sum up."
+ ],
+ [
+ 1.003,
+ "A permutation matrix P is the identity with its rows in a new order."
+ ],
+ [
+ 6.836,
+ "P times A puts the rows of A in that order; the lines and planes do not move."
+ ],
+ [
+ 12.07,
+ "A times P reorders the columns instead: the unknowns trade places, and the picture flips."
+ ],
+ [
+ 18.581,
+ "A swap undoes itself, P times P is the identity, and three rows have six orders, so six permutation matrices."
+ ],
+ [
+ 28.034,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 2.856,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.576,
+ "Find where the ones go."
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 2.784,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Set two."
+ ],
+ [
+ 1.081,
+ "Reorder the rows with P."
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 2.544,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Set three."
+ ],
+ [
+ 1.198,
+ "True or false?"
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 4.848,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.224,
+ "Build each permutation matrix with your own hands."
+ ]
+ ]
+ },
+ "play": {
+ "dur": 10.632,
+ "marks": {
+ "go": 4.167
+ },
+ "cues": [
+ [
+ 0.104,
+ "Playground."
+ ],
+ [
+ 1.107,
+ "Nothing here is marked right or wrong."
+ ],
+ [
+ 4.167,
+ "Change the numbers of P, try every order you like, and watch the rows move while the planes stay."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 14.136,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.094,
+ "That's the end of chapter twenty-two, Row Exchanges as Matrices, and the end of unit two."
+ ],
+ [
+ 7.292,
+ "Next: unit three, where we multiply matrices by matrices, and learn how to undo them."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch22/audio/en/twice.mp3 b/site/linear-algebra/ch22/audio/en/twice.mp3
new file mode 100644
index 0000000..c1618af
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/twice.mp3 differ
diff --git a/site/linear-algebra/ch22/audio/en/wrap.mp3 b/site/linear-algebra/ch22/audio/en/wrap.mp3
new file mode 100644
index 0000000..07b362b
Binary files /dev/null and b/site/linear-algebra/ch22/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch22/index.html b/site/linear-algebra/ch22/index.html
new file mode 100644
index 0000000..d82d91c
--- /dev/null
+++ b/site/linear-algebra/ch22/index.html
@@ -0,0 +1,350 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Row Exchanges as Matrices</title>
+<link rel="stylesheet" href="../lib/engine.css">
+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
+</head>
+<body>
+<script src="../lib/engine.js"></script>
+<script src="../lib/math.js"></script>
+<script src="../lib/linsys.js"></script>
+<script src="../lib/space3.js"></script>
+<script src="../lib/elim.js"></script>
+<script src="../lib/emat.js"></script>
+<script src="../lib/play.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 22, title: 'Row Exchanges as Matrices', minutes: 10, language: 'en', next: '../ch23/' };
+
+/* ---------- chapter drawing helpers (chapter 21's) ---------- */
+const BLUE = LS_ROW[0], CORAL = LS_ROW[1], YELLOW = S3_ROW[2];
+const ZERO = { A: [[0, 2], [3, 1]], b: [4, 5] }; // chapter 20's system with a 0 in the pivot spot
+const AF = { A: [[1, 2, 1], [0, 0, 1], [0, 1, 2]], b: [1, 1, 1] }; // chapter 20's 3 × 3 after column 1
+const LEC = { A: [[1, 2, 1], [3, 8, 1], [0, 4, 1]], b: [2, 12, 2] };
+const AT2 = [70, 290], AT3 = [64, 262];
+const CARD2 = { x: 40, y: 586, w: 760, cls: 'side' }, CARD3 = { x: 40, y: 640, w: 820, cls: 'side' };
+const say = (p, parts, x, y, t0, { size = 40, fill = COL.chalk, anchor = 'start' } = {}) => { const e = M(p, [].concat(parts), { x, y, size, fill, anchor, o: 0 }); show(e, t0); return e; };
+const text = (p, str, x, y, t0, { size = 30, fill = COL.chalk, anchor = 'start', weight = 500 } = {}) => { const e = T(p, str, { x, y, size, fill, anchor, weight, o: 0 }); show(e, t0); return e; };
+const thick = (sys, i, t0) => { tw(sys.lines[i].l, { 'a_stroke-width': 10 }, t0, .35); tw(sys.lines[i].l, { 'a_stroke-width': 5 }, t0 + .9, .6); };
+const two = (p, { A, b }, caption, { t0 = .1, E = null, side = 'left' } = {}) => {
+ const sys = linsys(p, { A, b, eq: [90, 200], mat: null, sol: false, plane: { cx: 1215, u: 50 }, t0 });
+ sys.E.style.display = 'none';
+ if (caption) say(p, [caption], 70, 175, t0 + .1, { size: 28, fill: COL.dim });
+ const em = emat(p, sys, { A, b, E, side, name: 'P', names: side === 'right' ? ['A', '', 'AP', 'b'] : ['A', 'b', 'PA', 'Pb'], at: AT2, size: 38, cw: 64, ecw: 56, rh: 62, gap: 66, t0 });
+ return { sys, em };
+};
+const three = (p, { A, b }, caption, { t0 = .1, E = null, view = { yaw: -30, pitch: 22 } } = {}) => {
+ const sys = lin3(p, { A, b, eq: [90, 190], mat: null, sol: false, space: { cx: 1262, size: 520, ...view }, t0 });
+ sys.E.style.display = 'none';
+ if (caption) say(p, [caption], 64, 160, t0 + .1, { size: 26, fill: COL.dim });
+ const em = emat(p, sys, { A, b, E, name: 'P', names: ['A', 'b', 'PA', 'Pb'], at: AT3, size: 32, cw: 52, ecw: 44, rh: 54, gap: 64, t0 });
+ return { sys, em, V: sys.space };
+};
+const bare = A => {
+ const v = {}, fs = [];
+ A.forEach((r, i) => { r.forEach((x, j) => { v[`a${i}${j}`] = x; }); v[`b${i}`] = 0; });
+ return { v, set(to) { Object.assign(v, to); fs.forEach(f => f(v)); }, onChange: f => fs.push(f), solve: () => ({}), live() {}, to() {} };
+};
+const pin = (sys, x, y, t0, color = COL.chalk) => { const g = G(sys.stage, { x: sys.P.PX(x), y: sys.P.PY(y), o: 0 }); mk('circle', { r: 20, fill: 'none', stroke: color, 'stroke-width': 3.5, 'stroke-dasharray': '6 5' }, g); show(g, t0, .4); return g; };
+const triangle = (p, el, t0) => {
+ const e = path(p, `M${el.cx(0) - 28} ${el.ry(0) - 40}L${el.cx(2) + 30} ${el.ry(0) - 40}L${el.cx(2) + 30} ${el.ry(2) + 16}Z`, { fill: COL.chalk, stroke: COL.chalk, 'stroke-width': 2, 'fill-opacity': .1 }, { o: 0 });
+ show(e, t0, .6);
+ return e;
+};
+const colFlash = (el, j, at) => [...Array(el.n).keys()].forEach(i => el.flash(i, at, j));
+// E's numbers as keys, from a matrix
+const eKeys = P => Object.fromEntries(P.flatMap((r, i) => r.map((x, j) => [`e${i}${j}`, x])));
+const baseKeys = ({ A, b }) => Object.fromEntries([...A.flatMap((r, i) => r.map((x, j) => [`a${i}${j}`, x])), ...b.map((x, i) => [`b${i}`, x])]);
+const isPerm = (v, n) => { const I = [...Array(n).keys()], ok = x => x === 0 || x === 1; return I.every(i => I.every(j => ok(v[`e${i}${j}`]))) && I.every(i => I.reduce((s, j) => s + v[`e${i}${j}`], 0) === 1) && I.every(j => I.reduce((s, i) => s + v[`e${i}${j}`], 0) === 1); };
+const EK3 = ['e00', 'e01', 'e02', 'e10', 'e11', 'e12', 'e20', 'e21', 'e22'];
+const sameE = (v, P) => P.every((r, i) => r.every((x, j) => v[`e${i}${j}`] === x));
+const SIX = [
+ [[1, 0, 0], [0, 1, 0], [0, 0, 1]], [[0, 1, 0], [1, 0, 0], [0, 0, 1]], [[0, 0, 1], [0, 1, 0], [1, 0, 0]],
+ [[1, 0, 0], [0, 0, 1], [0, 1, 0]], [[0, 0, 1], [1, 0, 0], [0, 1, 0]], [[0, 1, 0], [0, 0, 1], [1, 0, 0]],
+];
+const SIXNAME = ['I', 'P₁₂', 'P₁₃', 'P₂₃', '', ''];
+// A small permutation matrix with, beside it, the rows of A as coloured bars: they slide from 1, 2, 3 into P's order.
+const mini = (p, P, name, x, y, t0, tMove) => {
+ const g = G(p, { o: 0 }), cw = 34, rh = 38, size = 26, top = y - size * .9, bot = y + 2 * rh + size * .3;
+ path(g, `M${x + 10} ${top}H${x}V${bot}H${x + 10}M${x + 3 * cw - 10} ${top}H${x + 3 * cw}V${bot}H${x + 3 * cw - 10}`, { stroke: COL.chalk, 'stroke-width': 2.5, fill: 'none' });
+ P.forEach((r, i) => r.forEach((v, j) => M(g, [String(v)], { x: x + cw * (j + .5), y: y + i * rh, size, fill: v ? COL.chalk : COL.dim, anchor: 'middle' })));
+ if (name) M(g, [name], { x: x + 1.5 * cw, y: bot + 38, size: 26, fill: COL.dim, anchor: 'middle' });
+ M(g, ['→'], { x: x + 3 * cw + 34, y: y + rh, size: 30, fill: COL.dim, anchor: 'middle' });
+ [0, 1, 2].forEach(k => {
+ const to = P.findIndex(r => r[k] === 1); // row k of A lands in row `to`
+ const bar = G(g, { x: x + 3 * cw + 64, y: y + k * rh - 22 });
+ mk('rect', { width: 64, height: 22, rx: 6, fill: EM_ROW[k] }, bar);
+ T(bar, `row ${k + 1}`, { x: 76, y: 18, size: 18, fill: EM_ROW[k], weight: 700 });
+ if (to !== k) tw(bar, { y: y + to * rh - 22 }, tMove, 1.2);
+ });
+ show(g, t0, .5);
+ return g;
+};
+
+/* ---------- practice data (every answer worked twice: by the rows of P, and by the order it gives) ---------- */
+const WHEREQ = [
+ { parts: ['P₁₃ (swap rows 1 and 3): the 1 of row 1 → column ', { box: '3' }, ', row 2 → ', { box: '2' }, ', row 3 → ', { box: '1' }], why: 'Row 1 takes row 3, row 2 stays, row 3 takes row 1.', hint: 'Swap rows 1 and 3 of the identity.' },
+ { parts: ['P₂₃: row 1 → column ', { box: '1' }, ', row 2 → ', { box: '3' }, ', row 3 → ', { box: '2' }], why: 'Row 1 stays; rows 2 and 3 take each other.', hint: 'Swap rows 2 and 3 of the identity.' },
+ { parts: ['2 × 2, P₁₂: row 1 → column ', { box: '2' }, ', row 2 → ', { box: '1' }], why: 'P = (0, 1), (1, 0).', hint: 'Row 1 of P must take row 2.' },
+ { parts: ['order row 3, row 1, row 2: row 1 → column ', { box: '3' }, ', row 2 → ', { box: '1' }, ', row 3 → ', { box: '2' }], why: 'The 1 of row k sits in the column of the row that lands there: 3, then 1, then 2.', hint: 'Which row of A goes on top? Put the 1 of row 1 in that column.' },
+ { parts: ['order row 2, row 3, row 1: row 1 → column ', { box: '2' }, ', row 2 → ', { box: '3' }, ', row 3 → ', { box: '1' }], why: 'Read the order: 2, 3, 1.', hint: 'Row 1 of P takes row 2 of A.' },
+];
+const ORDERQ = [
+ { parts: ['P rows (0, 1, 0), (0, 0, 1), (1, 0, 0); A rows (1, 2), (3, 4), (5, 6): row 1 of PA = (', { box: '3' }, ', ', { box: '4' }, ')'], why: 'Row 1 of P has its 1 in column 2: it takes row 2 of A.', hint: 'Where is the 1 in row 1 of P? That row of A comes.' },
+ { parts: ['the same P and A: row 2 of PA = (', { box: '5' }, ', ', { box: '6' }, '), row 3 = (', { box: '1' }, ', ', { box: '2' }, ')'], why: 'Row 2 takes row 3, row 3 takes row 1.', hint: 'Row 2 of P is (0, 0, 1); row 3 is (1, 0, 0).' },
+ { parts: ['P₁₂ on A | b rows (2, 1 | 3), (0, 4 | 8): (', { box: '0' }, ', ', { box: '4' }, ' | ', { box: '8' }, '), (', { box: '2' }, ', ', { box: '1' }, ' | ', { box: '3' }, ')'], why: 'The rows trade places, right sides too.', hint: 'Swap the two rows, the right sides with them.' },
+ { parts: ['A rows (1, 2), (3, 4), P₁₂ on the right: AP = (', { box: '2' }, ', ', { box: '1' }, '), (', { box: '4' }, ', ', { box: '3' }, ')'], why: 'On the right, P swaps the columns: (1, 3) and (2, 4) trade places.', hint: 'On the right P mixes columns: column 1 of AP is column 2 of A.' },
+ { parts: ['P rows (0, 1, 0), (0, 0, 1), (1, 0, 0): row 1 of PP = (', { box: '0' }, ', ', { box: '0' }, ', ', { box: '1' }, ')'], why: 'Row 1 of P takes row 2 of P, which is (0, 0, 1). So PP is the other cycle, not I.', hint: 'Row 1 of the left P is (0, 1, 0): it takes row 2 of the right P.' },
+];
+const TFC = [['t', 'true', COL.good, '1'], ['f', 'false', COL.bad, '2']];
+const TFQ = [
+ { parts: [$m('P₂₃ P₂₃ = I')], ans: ['t'], why: 'Swapping rows 2 and 3 twice puts them back.' },
+ { parts: ['P A x = P b has the same solution as A x = b'], ans: ['t'], why: 'The same equations in a new order: the lines and planes do not move.' },
+ { parts: [$m('A P'), ' swaps the rows of ', $m('A')], ans: ['f'], why: 'On the right, P swaps the columns.' },
+ { parts: ['every column of a permutation matrix has exactly one 1'], ans: ['t'], why: 'Each row of A lands in exactly one place.' },
+ { parts: ['there are 6 permutation matrices of size 3 × 3'], ans: ['t'], why: '3 · 2 · 1 = 6 orders.' },
+ { parts: ['the cycle (0, 1, 0), (0, 0, 1), (1, 0, 0) times itself is I'], ans: ['f'], why: 'Moving every row down one place twice is not the start: it is the other cycle. Three times gets back to I.' },
+];
+const HANDS = [
+ { P: [[0, 0, 1], [1, 0, 0], [0, 1, 0]], prompt: 'Put row 3 on top, then row 1, then row 2.', why: 'Rows (0, 0, 1), (1, 0, 0), (0, 1, 0): row 1 of P takes row 3, row 2 takes row 1, row 3 takes row 2.' },
+ { P: [[0, 0, 1], [0, 1, 0], [1, 0, 0]], prompt: 'Turn the order upside down: row 3, row 2, row 1.', why: 'P₁₃: swap rows 1 and 3 of the identity.' },
+];
+
+/* ---------- beats ---------- */
+const BEATS = [
+ ['intro', 'Row exchanges as matrices', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 2, Chapter 22', { x: 800, y: 270, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Row Exchanges as Matrices', { x: 800, y: 380, size: 88, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'swap the rows of the identity, and you have a matrix that swaps rows', 800, 480, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });
+ const lg = G(scene, { o: 0 });
+ const s = bare(ZERO.A); s.v.b0 = 4; s.v.b1 = 5;
+ const em = emat(lg, s, { A: ZERO.A, b: ZERO.b, name: 'P', names: ['A', 'b', 'PA', 'Pb'], at: [380, 640], size: 36, cw: 62, ecw: 54, rh: 56, t0: 0 });
+ show(lg, m('sub') + 1.5, .5);
+ emSwap(em, 0, 1, m('move') + .6, 1.6);
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);
+ }],
+
+ ['recall', 'A swap as a matrix', (m) => {
+ const p = panel(0);
+ text(p, 'Which matrix swaps two rows?', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, em } = two(p, ZERO, '0x + 2y = 4, 3x + y = 5', { t0: m('sys') - .3 });
+ put(em.Eg, { o: 0 }); show(em.Eg, m('eye'), .5);
+ em.setName('I');
+ hide(em.B.ring(0, 0, m('zero'), { color: COL.bad }), m('swap'), .3);
+ text(p, 'a 0 in the pivot spot (chapter 20)', 70, 640, m('zero') + .5, { size: 26, fill: COL.bad, weight: 600 });
+ em.flashE(0, m('eye') + .8, 0); em.flashE(1, m('eye') + 1.2, 1);
+ emSwap(em, 0, 1, m('swap') + .3, 1.8, { sys });
+ prog(q => { if (q > 0) em.setName('P'); else em.setName('I'); }, m('p'), 0, lin);
+ [0, 1].forEach(i => em.B.flash(i, m('sys') + .6 + 2.6 * i));
+ em.Pt.flash(0, m('ask') + .5); em.Pt.flash(1, m('ask') + 1.3);
+ em.ringE(0, 1, m('r1')); em.focusE(0, m('r1')); em.work(0, 0, { times: [m('r1') + 1.8, m('r1') + 3.2, m('r2') - 1.2] });
+ em.focusE(1, m('r2')); em.work(1, 0, { times: [m('r2') + 1.8, m('r2') + 3.2, m('same') - 1] });
+ em.focusE(null, m('same'));
+ pin(sys, 1, 2, m('same') + .5);
+ thick(sys, 0, m('same') + 3); thick(sys, 1, m('same') + 4);
+ em.Pt.ring(0, 0, m('piv'), { color: COL.good });
+ }],
+
+ ['name', 'Permutation matrices', (m) => {
+ const p = panel(0);
+ text(p, 'Permutation matrices', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, em } = two(p, ZERO, '0x + 2y = 4, 3x + y = 5', { E: [[0, 1], [1, 0]] });
+ text(p, 'permutation = a change of order', 70, 470, m('name') + .5, { size: 30, fill: COL.chalk, weight: 600 });
+ text(p, 'the identity, rows in a new order', 70, 530, m('rows'), { size: 28, fill: COL.dim, weight: 600 });
+ em.ringE(0, 1, m('ones')); em.ringE(1, 0, m('ones') + .5);
+ text(p, 'one 1 in every row and every column', 70, 590, m('ones') + .8, { size: 28, fill: COL.dim, weight: 600 });
+ em.flashE(0, m('where'), 1); em.B.flash(1, m('where') + 1.5); em.Pt.flash(0, m('where') + 3);
+ prog(q => em.setName(q > 0 ? 'P₁₂' : 'P'), m('name2'), 0, lin);
+ say(p, ['P₁₂: swap rows 1 and 2'], 70, 660, m('name2') + .3, { size: 34, fill: COL.chalk });
+ }],
+
+ ['three', 'Three rows', (m) => {
+ const p = panel(0);
+ text(p, 'P₂₃ in three dimensions', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, em, V } = three(p, AF, 'after column 1: x + 2y + z = 1, z = 1, y + 2z = 1', { t0: m('sys') - .3 });
+ V.sway(5, 13);
+ hide(em.B.ring(1, 1, m('sys') + 3, { color: COL.bad }), m('p'), .3);
+ hide(em.B.ring(2, 1, m('sys') + 5, { color: COL.good, dash: true }), m('p'), .3);
+ em.setName('I');
+ sys.planes[1].fade(.3, m('p') + 2, .4); sys.planes[2].fade(.3, m('p') + 2, .4);
+ emSwap(em, 1, 2, m('p') + 2.4, 1.8);
+ sys.planes[1].fade(1, m('p') + 4.4, .5); sys.planes[2].fade(1, m('p') + 4.4, .5);
+ prog(q => em.setName(q > 0 ? 'P₂₃' : 'I'), m('p') + 4.2, 0, lin);
+ em.focusE(0, m('r1')); em.work(0, m('r1'));
+ em.focusE(1, m('r2')); em.work(1, m('r2'));
+ em.focusE(2, m('r3')); em.work(2, m('r3'));
+ em.focusE(null, m('tri'));
+ triangle(p, em.Pt, m('tri'));
+ pulse(sys.meet.e, m('same') + 1); pulse(sys.meet.e, m('same') + 3);
+ }],
+
+ ['q1', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ const t = three(p, LEC, 'x + 2y + z = 2, 3x + 8y + z = 12, 4y + z = 2');
+ S.em = t.em;
+ }, { ask: done => quiz({ x: 40, y: 440, w: 820, cls: 'side' }, [{
+ id: 'c-p13', prompt: ['Build P₁₃, the matrix that swaps rows 1 and 3.'],
+ build: blanks([
+ { parts: ['rows 1, 2 of P₁₃: (', { box: '0' }, ' ', { box: '0' }, ' ', { box: '1' }, '), (', { box: '0' }, ' ', { box: '1' }, ' ', { box: '0' }, ')'],
+ why: 'Row 1 takes row 3; row 2 stays.', hint: 'Swap rows 1 and 3 of the identity: row 1 becomes (0, 0, 1).' },
+ { parts: ['row 3 of P₁₃: (', { box: '1' }, ' ', { box: '0' }, ' ', { box: '0' }, ')'],
+ why: 'Row 3 takes row 1. The planes stay; their order turns over.', hint: 'Row 3 of P must take row 1 of A.',
+ fx: () => fxp(q => { if (q >= 1) S.em.set(eKeys([[0, 0, 1], [0, 1, 0], [1, 0, 0]])); }, .2, 0) },
+ ]),
+ }], done) }],
+
+ ['twice', 'Swap twice', (m) => {
+ const p = panel(0);
+ text(p, 'Swap twice', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, em } = two(p, ZERO, '0x + 2y = 4, 3x + y = 5', { E: [[0, 1], [1, 0]] });
+ em.setName('P₁₂');
+ const part1 = G(p, {});
+ part1.appendChild(em.g);
+ emSwap(em, 0, 1, m('again') + .4, 1.8, { sys });
+ prog(q => em.setName(q > 0 ? 'I' : 'P₁₂'), m('again') + 2.2, 0, lin);
+ em.work(0, m('r1'));
+ text(p, 'back where it started', 70, 620, m('back'), { size: 30, fill: COL.good, weight: 600 });
+ say(p, ['P P = I'], 70, 700, m('pp'), { size: 44, fill: COL.chalk });
+ text(p, 'a swap undoes itself', 300, 694, m('undo'), { size: 30, fill: COL.chalk, weight: 600 });
+ hide(part1, m('calc') - .3, .4);
+ const part2 = G(p, { o: 0 }); show(part2, m('calc'), .4);
+ const e2 = emat(part2, bare([[0, 1], [1, 0]]), { A: [[0, 1], [1, 0]], b: [0, 0], E: [[0, 1], [1, 0]], name: 'P', names: ['P', '', 'PP', ''], noB: true, at: AT2, size: 38, cw: 64, ecw: 56, rh: 62, gap: 66, t0: 0 });
+ e2.work(0, m('calc') + .3); e2.Pt.flash(0, m('calc') + 3);
+ e2.work(1, m('calc2')); e2.Pt.flash(1, m('calc2') + 3);
+ [0, 1].forEach(i => e2.Pt.ring(i, i, m('eye') + .4 * i, { color: COL.good }));
+ }],
+
+ ['six', 'All six', (m) => {
+ const p = panel(0);
+ text(p, 'Three rows: six orders', 60, 110, .2, { size: 40, weight: 600 });
+ // three places, filled one after another
+ const slot = (k, t0, n, choices) => {
+ const x = 180 + k * 300, g = G(p, { o: 0 });
+ mk('rect', { x, y: 180, width: 200, height: 46, rx: 10, fill: 'none', stroke: COL.dim, 'stroke-width': 2.5, 'stroke-dasharray': '8 7' }, g);
+ choices.forEach((c, i) => mk('rect', { x: x + 12 + i * 64, y: 192, width: 52, height: 22, rx: 6, fill: EM_ROW[c] }, g));
+ T(g, `${n} choice${n > 1 ? 's' : ''}`, { x: x + 100, y: 260, size: 26, fill: COL.chalk, weight: 600, anchor: 'middle' });
+ show(g, t0, .5);
+ };
+ slot(0, m('top'), 3, [0, 1, 2]); slot(1, m('next'), 2, [1, 2]); slot(2, m('last'), 1, [2]);
+ say(p, ['3 · 2 · 1 = 6'], 1300, 220, m('count'), { size: 40, fill: COL.chalk });
+ const at = (k, t) => mini(p, SIX[k], SIXNAME[k], 140 + (k % 3) * 480, 380 + Math.floor(k / 3) * 250, t, t + .8);
+ at(0, m('i'));
+ [1, 2, 3].forEach((k, i) => at(k, m('swaps') + 1.2 * i));
+ [4, 5].forEach((k, i) => at(k, m('cycles') + 1.5 * i));
+ text(p, 'swap one pair', 620, 345, m('swaps'), { size: 24, fill: COL.dim, weight: 600 });
+ text(p, 'move every row', 620, 595, m('cycles'), { size: 24, fill: COL.dim, weight: 600 });
+ text(p, 'each = one swap after another', 620, 860, m('two'), { size: 26, fill: COL.chalk, weight: 600 });
+ }],
+
+ ['q2', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const t = three(p, AF, 'after column 1: x + 2y + z = 1, z = 1, y + 2z = 1');
+ S.em = t.em;
+ }, { ask: done => quiz(CARD3, [{
+ id: 'c-tri', prompt: ['Change the numbers of P until PA is a triangle (a number that is not 0 in every pivot spot, zeros below).'],
+ build: emTask(S.em, (v, pr) => isPerm(v, 3) && Math.abs(pr.a10) + Math.abs(pr.a20) + Math.abs(pr.a21) < 1e-9 && pr.a11 !== 0 && pr.a22 !== 0,
+ 'P₂₃ = (1, 0, 0), (0, 0, 1), (0, 1, 0): rows 2 and 3 trade places, and the pivots are 1, 1, 1.',
+ (v, pr) => !isPerm(v, 3) ? 'Keep P a permutation matrix: only 0s and 1s, one 1 in every row and every column.' : 'Not a triangle yet. Which two rows must trade places?',
+ () => S.em.set(eKeys([[1, 0, 0], [0, 0, 1], [0, 1, 0]])), { only: EK3 }),
+ }], done) }],
+
+ ['right', 'P on the right', (m) => {
+ const p = panel(0);
+ text(p, 'P on the right swaps columns', 60, 110, .2, { size: 40, weight: 600 });
+ const { sys, em } = two(p, { A: [[1, 2], [3, 4]], b: [5, 11] }, 'x + 2y = 5, 3x + 4y = 11', { t0: m('sys') - .3, side: 'right' });
+ // the old lines, dashed, and the old meeting point: they stay while the picture flips
+ const old = G(sys.stage, { o: 0 });
+ sys.P.line(1, 2, 3, 1, BLUE, 0, { dash: '8 9', w: 3, into: old }); sys.P.line(1, 2, 5, -1, CORAL, 0, { dash: '8 9', w: 3, into: old });
+ show(old, m('cols'), .3); tw(old, { o: .5 }, m('cols') + .4, .4);
+ [0, 1].forEach(i => em.B.flash(i, m('sys') + 1.5 + 3 * i));
+ thick(sys, 0, m('sys') + 2); thick(sys, 1, m('sys') + 5);
+ emSwap(em, 0, 1, m('cols') + .4, 1.8, { cols: true });
+ prog(q => em.setName('P'), m('cols'), 0, lin);
+ em.ringE(0, 0, m('c1') - .2); em.ringE(1, 0, m('c1') - .2);
+ colFlash(em.B, 1, m('c1') + 1.5); colFlash(em.Pt, 0, m('c1') + 3);
+ colFlash(em.B, 0, m('c2') + .4); colFlash(em.Pt, 1, m('c2') + 1.6);
+ say(p, ['2x + y = 5, 4x + 3y = 11'], 70, 470, m('eq'), { size: 34, fill: COL.chalk });
+ em.Pt.flash(0, m('eq') + .4); em.Pt.flash(1, m('eq') + 2.5); thick(sys, 0, m('eq') + .6); thick(sys, 1, m('eq') + 2.7);
+ colFlash(em.Pt, 0, m('xy') + .5); colFlash(em.Pt, 1, m('xy') + 2);
+ pulse(sys.meet, m('pt') + 3); pulse(sys.meet, m('flip') - 1);
+ colFlash(em.Pt, 0, m('rows') + 3); colFlash(em.B, 1, m('rows') + 3); em.flashE(0, m('rows') + 5);
+ text(p, 'x and y trade places', 70, 530, m('xy'), { size: 28, fill: COL.chalk, weight: 600 });
+ pin(sys, 1, 2, m('pt'), COL.dim); pin(sys, 2, 1, m('pt') + 1.2);
+ draw(path(sys.stage, `M${sys.P.PX(1) + 10} ${sys.P.PY(2) - 18}Q${sys.P.PX(2) + 30} ${sys.P.PY(2) - 20} ${sys.P.PX(2) + 14} ${sys.P.PY(1) - 18}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' }, { d: 0 }), m('pt') + .4, .8);
+ say(p, ['(1, 2) → (2, 1)'], 70, 590, m('pt') + .4, { size: 32, fill: COL.chalk });
+ const diag = sys.P.line(-6, -6, 6, 6, COL.dim, m('flip'), { dash: '10 10', w: 3, into: sys.stage });
+ tw(diag, { 'a_stroke-width': 7 }, m('flip') + 1, .4); tw(diag, { 'a_stroke-width': 3 }, m('flip') + 1.6, .5);
+ text(p, 'flipped over the line y = x', 70, 650, m('flip') + .5, { size: 28, fill: COL.chalk, weight: 600 });
+ text(p, 'P A: rows trade, nothing moves. A P: columns trade, x and y trade.', 70, 730, m('rows'), { size: 26, fill: COL.chalk, weight: 600 });
+ }],
+
+ ['q3', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const t = two(p, { A: [[1, 3], [2, 1]], b: [7, 4] }, 'x + 3y = 7, 2x + y = 4', { side: 'right' });
+ S.em = t.em;
+ pin(t.sys, 2, 1, .4, COL.task);
+ }, { ask: done => quiz(CARD2, [{
+ id: 'c-right', prompt: ['Change the numbers of P (on the right) until the lines meet at the ring, (2, 1).'],
+ build: emTask(S.em, (v, pr) => { const d = pr.a00 * pr.a11 - pr.a01 * pr.a10; return Math.abs(d) > 1e-9 && Math.abs(pr.a00 * 2 + pr.a01 - pr.b0) < 1e-9 && Math.abs(pr.a10 * 2 + pr.a11 - pr.b1) < 1e-9; },
+ 'P = (0, 1), (1, 0): the columns trade, 3x + y = 7 and x + 2y = 4 meet at (2, 1). The old answer was (1, 2).',
+ 'Not yet at (2, 1). The lines met at (1, 2): which P makes x and y trade places?', () => S.em.set(eKeys([[0, 1], [1, 0]])), { only: ['e00', 'e01', 'e10', 'e11'] }),
+ }], done) }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['A permutation matrix P is the identity with its rows in a new order.', 'w1'], ['P A puts the rows of A in that order: lines and planes do not move.', 'w2'],
+ ['A P reorders the columns: the unknowns trade places, the picture flips.', 'w3'], ['P P = I for a swap; three rows have 6 orders, 6 permutation matrices.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
+ mk('circle', { cx: 120, cy: -12, r: 26, fill: COL.chalk }, g);
+ T(g, String(i + 1), { x: 120, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 170, size: 34, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ });
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-where', prompt: ['Each row of P has one 1. Say which column it sits in.'],
+ build: blanks(WHEREQ),
+ }], done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-order', prompt: ['Reorder with P. Rows are written (numbers of A | right side).'],
+ build: blanks(ORDERQ),
+ }], done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-tf', prompt: ['True or false?'],
+ build: grid(TFQ, TFC, { text: true }),
+ }], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Build P', 60, 110, .2, { size: 40, weight: 600 });
+ const t = three(p, LEC, 'x + 2y + z = 2, 3x + 8y + z = 12, 4y + z = 2');
+ S.em = t.em;
+ }, { ask: done => quiz(CARD3, HANDS.map((h, k) => ({
+ id: `p-build${k + 1}`, prompt: [h.prompt],
+ build: (body, api) => { S.em.set(eKeys(SIX[0])); return emTask(S.em, v => sameE(v, h.P), h.why,
+ v => !isPerm(v, 3) ? 'Keep P a permutation matrix: only 0s and 1s, one 1 in every row and every column.' : 'Another order. The 1 in row 1 sits in the column of the row that goes on top.',
+ () => S.em.set(eKeys(h.P)), { only: EK3 })(body, api); },
+ })), done, 'Chapter practice · set 4 of 4') }],
+ ['play', 'Playground', (m) => {
+ const p = panel(0);
+ text(p, 'Playground', 60, 110, .2, { size: 40, weight: 600 });
+ const t = three(p, LEC, '');
+ S.em = t.em;
+ t.em.work(0, .3);
+ text(p, 'try: all six orders; a 2 instead of a 1; two 1s in one row', 64, 160, m('go'), { size: 24, fill: COL.dim });
+ }, { ask: playAsk(() => S.em, { pos: { x: 40, y: 600, w: 820, cls: 'side' }, tip: 'Your matrices. Change any number of P or of A | b, turn the space, or draw on the board. Nothing is marked.' }) }],
+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+boot();
+</script>
+</body>
+</html>
diff --git a/site/linear-algebra/lib/emat.js b/site/linear-algebra/lib/emat.js
new file mode 100644
index 0000000..75021c7
--- /dev/null
+++ b/site/linear-algebra/lib/emat.js
@@ -0,0 +1,317 @@
+// Row exchanges on an elim table, and a matrix on the left (or right) of a system, shown as a product computed row by row.
+//
+// elSwap(el, sys, 1, 2, at) // rows 2 and 3 of [A | b] slide past each other; the system takes the new order
+//
+// Loads after engine.js, elim.js (and linsys.js or space3.js).
+const EM_ROW = [COL.whole, COL.nat, COL.int], EM_COL = [COL.irr, COL.real, COL.rat];
+
+// Swap rows i and j of an elim table and of its system, on the beat clock (or on the answer clock with { now: true },
+// inside a question). The numbers slide past each other while the row colours trade (the table's bars, the equations'
+// bars and, in 2D, the lines), then the system takes the swapped numbers. Lines and planes stay where they are: the same
+// equations in a new order. label: [x, y] writes "row i ↔ row j" there.
+function elSwap(el, sys, i, j, at, dur = 1.4, { label = null, now = false } = {}) {
+ const n = el.n, keys = r => [...[...Array(n).keys()].map(c => `a${r}${c}`), `b${r}`];
+ const from = now ? { ...sys.v } : { ...el.plan }, next = {};
+ keys(i).forEach((k, c) => { const k2 = keys(j)[c]; next[k] = from[k2]; next[k2] = from[k]; });
+ const dy = el.ry(j) - el.ry(i);
+ const eqs = sys.eqRows ? sys.eqRows.map(r => r.g) : sys.rows || [];
+ const eqBar = g => g?.querySelector('rect');
+ const eqDy = eqs[i] && eqs[j] ? +eqBar(eqs[j]).getAttribute('y') - +eqBar(eqs[i]).getAttribute('y') : 0;
+ const lines = sys.lines?.[0]?.l ? sys.lines.map(l => l.l) : []; // 2D lines (lin3's lines are its meeting lines)
+ let lab = null;
+ if (label && !now) {
+ if (el.op_?.lab?.g.parentNode) hide(el.op_.lab.g, at, .3);
+ lab = G(el.g, { x: label[0], y: label[1], o: 0 });
+ M(lab, [`row ${i + 1}`], { size: 34, fill: EM_ROW[i], anchor: 'start' });
+ M(lab, ['↔'], { x: 112, size: 34, fill: COL.chalk, anchor: 'start' });
+ M(lab, [`row ${j + 1}`], { x: 166, size: 34, fill: EM_ROW[j], anchor: 'start' });
+ show(lab, at - .6, .4);
+ }
+ const frame = q => {
+ const s = q < 1 ? q : 0, c = (a, b) => q < 1 ? mix(a, b, q) : a;
+ el.cells[i].forEach(cl => put(cl.c, { y: el.ry(i) + dy * s }));
+ el.cells[j].forEach(cl => put(cl.c, { y: el.ry(j) - dy * s }));
+ el.bars[i].setAttribute('fill', c(EM_ROW[i], EM_ROW[j])); el.bars[j].setAttribute('fill', c(EM_ROW[j], EM_ROW[i]));
+ if (eqs[i] && eqs[j]) {
+ put(eqs[i], { y: eqDy * s }); put(eqs[j], { y: -eqDy * s });
+ eqBar(eqs[i]).setAttribute('fill', c(EM_ROW[i], EM_ROW[j])); eqBar(eqs[j]).setAttribute('fill', c(EM_ROW[j], EM_ROW[i]));
+ }
+ if (lines[i] && lines[j]) { lines[i].setAttribute('stroke', c(EM_ROW[i], EM_ROW[j])); lines[j].setAttribute('stroke', c(EM_ROW[j], EM_ROW[i])); }
+ if (q >= 1 && now) el.load(next);
+ };
+ if (now) { fxp(frame, 0, dur); return next; }
+ prog(frame, at, dur);
+ el.to(next, at + dur, 0);
+ return lab;
+}
+
+/* ---------- a matrix times [A | b], computed row by row ---------- */
+// emat draws E · [A | b] = [EA | Eb] (side 'left') or A · P = AP with b kept (side 'right'), in one line from `at`.
+// The product is the system sys (a linsys or lin3) shows: change a number of E, or of A and b, and the product, the
+// lines or planes and the working all follow. E's numbers are drawn here; [A | b] and the product are elim tables
+// (read-only uses of elim.js), so their rings, flashes and working rows are elim's.
+//
+// const em = emat(p, sys, { A, b, at: [70, 270] }); // E starts as the identity
+// em.to({ e10: -3 }, at, 2) // on the beat clock: row 2 of E becomes (−3, 1); the coral line turns
+// em.work(1, at) // under [A | b]: −3 × row 1, 1 × row 2, a rule, their sum = row 2 of EA
+// em.ringE(1, 0, at) // a circle round E's entry in row 2, column 1
+// em.live(true, { only: ['e10'] }) // the reader scrubs E's entry (drag sideways, or Tab and ↑/↓)
+//
+// em.v and em.set work for playAsk; emTask is the question type. Keys: e<i><j> for E, a<i><j> and b<i> for A and b.
+function emat(p, sys, { A, b, E = null, at: [x0, y0] = [70, 270], size = 40, cw = 70, ecw = 60, rh = 62, gap = 70, t0 = .1, dens = [1, 2], side = 'left', name = 'E', names = null, noB = false, step: eStep = 1, o = 0 } = {}) {
+ const n = A.length, I = [...Array(n).keys()], svg = $('stage');
+ const g = G(p, { o });
+ show(g, t0 + .2);
+ const st0 = {};
+ I.forEach(i => { I.forEach(j => { st0[`e${i}${j}`] = E ? E[i][j] : +(i === j); st0[`a${i}${j}`] = A[i][j]; }); st0[`b${i}`] = b[i]; });
+ const s = { ...st0 };
+ let plan = { ...s };
+
+ // exact numbers at rest (whole, or a fraction over dens), one decimal while they move
+ const parts = v => {
+ const r = Math.round(v);
+ if (Math.abs(v - r) < 1e-9) return [num(r)];
+ for (const d of dens) { const k = Math.round(v * d); if (d > 1 && Math.abs(v * d - k) < 1e-9) { const gg = gcd(Math.abs(k), d); return k < 0 ? ['−', F(Math.abs(k) / gg, d / gg)] : [F(k / gg, d / gg)]; } }
+ return [num(Math.round(v * 10) / 10)];
+ };
+ const key = ps => ps.map(q => typeof q === 'string' ? q : q.f.join('/')).join('');
+
+ /* ---------- E ---------- */
+ const ex = x0 + 30, ecx = j => ex + ecw * (j + .5), ry = i => y0 + i * rh;
+ const top = y0 - size * .95, bot = y0 + (n - 1) * rh + size * .35, EW = n * ecw;
+ const Eg = G(g, {});
+ path(Eg, `M${ex - 2} ${top}H${ex - 14}V${bot}H${ex - 2}M${ex + EW + 2} ${top}H${ex + EW + 14}V${bot}H${ex + EW + 2}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });
+ const Ebars = I.map(i => mk('rect', { x: ex - 34, y: ry(i) - size * .7, width: 7, height: size * .8, rx: 3.5, fill: EM_ROW[i] }, Eg));
+ const Ename = G(Eg, {});
+ const setName = nm => { Ename.replaceChildren(); M(Ename, [].concat(nm), { x: ex + EW / 2, y: top - 16, size: 28, fill: COL.dim, anchor: 'middle' }); };
+ setName(name);
+ const ecells = I.map(i => I.map(j => {
+ const k = `e${i}${j}`, c = G(Eg, { x: ecx(j), y: ry(i) });
+ const glow = mk('rect', { x: -ecw / 2 + 4, y: -size * .9, width: ecw - 8, height: size * 1.2, rx: 10, fill: COL.chalk }, c);
+ put(glow, { o: 0 });
+ const holder = G(c, {});
+ holder.style.pointerEvents = 'none';
+ const box = mk('rect', { x: -ecw / 2 + 3, y: -size * .92, width: ecw - 6, height: size * 1.24, rx: 9, fill: 'transparent', 'stroke-dasharray': '4 6' }, c);
+ box.setAttribute('aria-label', k);
+ return { k, c, glow, holder, box, txt: null };
+ }));
+
+ /* ---------- [A | b] (a bare system drawn by elim) and the product ---------- */
+ const bx = ex + EW + gap + 16;
+ const base = { v: {}, fs: [], set(to) { Object.assign(this.v, to); this.fs.forEach(f => f(this.v)); }, onChange(f) { this.fs.push(f); }, to() {}, solve: () => ({}), live() {} };
+ I.forEach(i => { I.forEach(j => { base.v[`a${i}${j}`] = s[`a${i}${j}`]; }); base.v[`b${i}`] = s[`b${i}`]; });
+ const B = elim(g, base, { at: [bx, y0], size, cw, rh, t0: -1, dens });
+ const px = bx + B.W + 120;
+ const eqSign = M(g, ['='], { x: bx + B.W + 42, y: y0 + (n - 1) * rh / 2 + 12, size: size * 1.1, fill: COL.chalk, anchor: 'middle' });
+ const Pt = elim(g, sys, { at: [px, y0], size, cw, rh, t0: -1, dens });
+ const label = (el, a, bb) => { el.names.replaceChildren(); [[a, el.cx(0) + (el.cx(n - 1) - el.cx(0)) / 2], [bb, el.cx(n)]].forEach(([t, x]) => { if (t) M(el.names, [t], { x, y: top - 16, size: 28, fill: COL.dim, anchor: 'middle' }); }); };
+ // names: [over A, over b, over the product's A part, over its b part]; noB hides the b columns (a matrix times a matrix)
+ const nm = names || (side === 'right' ? ['A', '', 'AP', 'b'] : ['A', 'b', 'EA', 'Eb']);
+ label(B, nm[0], nm[1]); label(Pt, nm[2], nm[3]);
+ if (side === 'right' || noB) { I.forEach(i => put(B.cells[i][n].c, { o: 0 })); put(B.divider, { o: 0 }); }
+ if (noB) { I.forEach(i => put(Pt.cells[i][n].c, { o: 0 })); put(Pt.divider, { o: 0 }); }
+ put(B.names, { o: 1 }); put(Pt.names, { o: 1 });
+
+ const prod = v => {
+ const out = {};
+ I.forEach(i => {
+ I.forEach(j => { out[`a${i}${j}`] = side === 'left' ? I.reduce((t, k) => t + v[`e${i}${k}`] * v[`a${k}${j}`], 0) : I.reduce((t, k) => t + v[`a${i}${k}`] * v[`e${k}${j}`], 0); });
+ out[`b${i}`] = side === 'left' ? I.reduce((t, k) => t + v[`e${i}${k}`] * v[`b${k}`], 0) : v[`b${i}`];
+ });
+ return out;
+ };
+ const listeners = [];
+ let quiet = false;
+ function draw() {
+ ecells.flat().forEach(cl => {
+ const ps = parts(s[cl.k]), kk = key(ps);
+ if (kk === cl.txt) return;
+ cl.txt = kk; cl.holder.replaceChildren();
+ M(cl.holder, ps, { size, fill: COL.chalk, anchor: 'middle' });
+ });
+ const bv = {}; I.forEach(i => { I.forEach(j => { bv[`a${i}${j}`] = s[`a${i}${j}`]; }); bv[`b${i}`] = s[`b${i}`]; });
+ base.set(bv);
+ quiet = true; sys.set(prod(s)); quiet = false;
+ drawWork();
+ listeners.forEach(f => f(s));
+ }
+ const edit = to => { let ch = false; for (const k in to) if (s[k] !== to[k]) { s[k] = to[k]; ch = true; } if (ch) draw(); };
+
+ /* ---------- the working: row i of the product as a sum of rows of A ---------- */
+ const W = G(g, { o: 0 });
+ let workRow = null, workKey = '', workN = 99; // workN: how many lines of the working show (the rows, then the rule and the sum)
+ function drawWork() {
+ if (workRow === null || side !== 'left') return;
+ const i = workRow, rows = I.map(k => [...I.map(j => s[`e${i}${k}`] * s[`a${k}${j}`]), s[`e${i}${k}`] * s[`b${k}`]]);
+ const pr = prod(s), sum = [...I.map(j => pr[`a${i}${j}`]), pr[`b${i}`]];
+ const kk = i + '|' + workN + '|' + rows.flat().concat(sum).map(v => key(parts(v))).join(',');
+ if (kk === workKey) return;
+ workKey = kk;
+ W.replaceChildren();
+ const y = r => y0 + (n + r) * rh + 6;
+ rows.forEach((vals, k) => {
+ if (k >= workN) return;
+ const e = s[`e${i}${k}`], zero = Math.abs(e) < 1e-9, fill = zero ? COL.faint : COL.chalk;
+ vals.forEach((v, j) => (j < n || !noB) && M(W, parts(v), { x: B.cx(j), y: y(k), size: size * .8, fill: j === n ? (zero ? COL.faint : COL.task) : fill, anchor: 'middle' }));
+ M(W, [...parts(e), ' × '], { x: bx - 36, y: y(k), size: 28, fill: zero ? COL.faint : COL.chalk, anchor: 'end' });
+ T(W, `row ${k + 1}`, { x: bx - 36, y: y(k) + 26, size: 18, fill: zero ? COL.faint : EM_ROW[k], weight: 700, anchor: 'end' });
+ });
+ if (workN <= n) return;
+ path(W, `M${bx - 10} ${y(n - 1) + size * .45}H${bx + (noB ? n * cw : B.W)}`, { stroke: COL.chalk, 'stroke-width': 2.5 });
+ sum.forEach((v, j) => (j < n || !noB) && M(W, parts(v), { x: B.cx(j), y: y(n) + 8, size: size * .85, fill: j === n ? COL.task : COL.chalk, anchor: 'middle' }));
+ T(W, `row ${i + 1} of ${nm[2]}`, { x: bx - 36, y: y(n) + 4, size: 24, fill: EM_ROW[i], weight: 700, anchor: 'end' });
+ }
+ // Show the working for row i (null: hide it) at `at`; it stays live while the numbers move.
+ // { times: [t1, …] } brings its lines in one at a time: the first row of A's share at t1, the next at t2, …, and
+ // the rule with the sum at the last time (n + 1 times in all), so each piece shows when the voice names it.
+ function work(i, at, { dur = .4, times = null } = {}) {
+ prog(q => { if (q > 0 && i !== null && (workRow !== i || times)) { workRow = i; workN = times ? 1 : 99; workKey = ''; drawWork(); } }, times ? times[0] : at, 0, lin);
+ if (times) times.slice(1).forEach((t, k) => prog(q => { if (q > 0) { workN = k + 2; drawWork(); } }, t, 0, lin));
+ if (i === null) hide(W, at, dur); else { put(W, { o: 0 }); show(W, times ? times[0] : at, dur); }
+ }
+
+ /* ---------- hands on ---------- */
+ let live = false, allowed = null;
+ const can = k => live && (!allowed || allowed.has(k));
+ ecells.flat().forEach(cl => {
+ let drag = null;
+ const set1 = v => edit({ [cl.k]: Math.max(-9, Math.min(9, Math.round(v / eStep) * eStep)) });
+ cl.box.addEventListener('pointerdown', e => { if (!can(cl.k)) return; e.preventDefault(); drag = { x: e.clientX, from: s[cl.k] }; cl.box.setPointerCapture(e.pointerId); });
+ cl.box.addEventListener('pointermove', e => { if (!drag) return; const k = svg.getScreenCTM().a; set1(drag.from + Math.round((e.clientX - drag.x) / k / 24) * eStep); });
+ const end = () => { drag = null; };
+ cl.box.addEventListener('pointerup', end);
+ cl.box.addEventListener('lostpointercapture', end);
+ cl.box.addEventListener('keydown', e => {
+ if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); cl.box.blur(); P.keys?.(e); return; }
+ if (!can(cl.k)) return;
+ const d = { ArrowUp: 1, ArrowRight: 1, ArrowDown: -1, ArrowLeft: -1 }[e.key];
+ if (!d) return;
+ e.preventDefault(); e.stopPropagation();
+ set1(s[cl.k] + d * eStep);
+ });
+ });
+ // [A | b] scrubs like elim's cells (whole steps); the base table's own boxes take the pointer.
+ B.cells.flat().forEach(cl => {
+ let drag = null;
+ const R = () => cl.k[0] === 'b' ? 30 : 9, set1 = v => edit({ [cl.k]: Math.max(-R(), Math.min(R(), Math.round(v))) });
+ cl.box.addEventListener('pointerdown', e => { if (!can(cl.k)) return; e.preventDefault(); drag = { x: e.clientX, from: s[cl.k] }; cl.box.setPointerCapture(e.pointerId); });
+ cl.box.addEventListener('pointermove', e => { if (!drag) return; const k = svg.getScreenCTM().a; set1(drag.from + Math.round((e.clientX - drag.x) / k / 22)); });
+ const end = () => { drag = null; };
+ cl.box.addEventListener('pointerup', end);
+ cl.box.addEventListener('lostpointercapture', end);
+ cl.box.addEventListener('keydown', e => {
+ if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); cl.box.blur(); P.keys?.(e); return; }
+ if (!can(cl.k)) return;
+ const d = { ArrowUp: 1, ArrowRight: 1, ArrowDown: -1, ArrowLeft: -1 }[e.key];
+ if (!d) return;
+ e.preventDefault(); e.stopPropagation();
+ set1(s[cl.k] + d);
+ });
+ });
+ const boxesLive = () => [...ecells.flat(), ...B.cells.flat()].forEach(cl => {
+ const ok = can(cl.k) && !((side === 'right' || noB) && cl.k[0] === 'b');
+ cl.box.style.cursor = ok ? 'ew-resize' : '';
+ cl.box.setAttribute('stroke', ok ? COL.faint : 'none');
+ if (ok) cl.box.setAttribute('tabindex', 0); else cl.box.removeAttribute('tabindex');
+ });
+ // A line or plane dragged in the picture changes the product; [A | b] follows (undone by E), when E can be undone.
+ const inv = M_ => {
+ if (n === 2) { const d = M_[0][0] * M_[1][1] - M_[0][1] * M_[1][0]; return Math.abs(d) < 1e-9 ? null : [[M_[1][1] / d, -M_[0][1] / d], [-M_[1][0] / d, M_[0][0] / d]]; }
+ const d = S3_det(M_);
+ if (Math.abs(d) < 1e-9) return null;
+ const c = (i, j) => { const r = I.filter(x => x !== i), k = I.filter(x => x !== j); return ((i + j) % 2 ? -1 : 1) * (M_[r[0]][k[0]] * M_[r[1]][k[1]] - M_[r[0]][k[1]] * M_[r[1]][k[0]]); };
+ return I.map(i => I.map(j => c(j, i) / d));
+ };
+ sys.onChange(v => {
+ if (quiet || !live) return;
+ const Ei = inv(I.map(i => I.map(j => s[`e${i}${j}`])));
+ if (!Ei) { quiet = true; sys.set(prod(s)); quiet = false; return; }
+ const next = {};
+ if (side === 'left') I.forEach(i => { I.forEach(j => { next[`a${i}${j}`] = I.reduce((t, k) => t + Ei[i][k] * v[`a${k}${j}`], 0); }); next[`b${i}`] = I.reduce((t, k) => t + Ei[i][k] * v[`b${k}`], 0); });
+ else I.forEach(i => { I.forEach(j => { next[`a${i}${j}`] = I.reduce((t, k) => t + v[`a${i}${k}`] * Ei[k][j], 0); }); next[`b${i}`] = v[`b${i}`]; });
+ for (const k in next) next[k] = Math.round(next[k] * 1e6) / 1e6;
+ Object.assign(s, next);
+ quiet = true; draw(); quiet = false;
+ });
+
+ draw();
+ const api = {
+ g, n, side, Eg, ecells, Ebars, B, Pt, eqSign, W, ecx, ry, bx, px, setName,
+ get plan() { return plan; },
+ // Move numbers of E (e..) and of [A | b] (a.., b..) over dur seconds on the beat clock; product and picture follow.
+ 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, from[k] + (goal[k] - from[k]) * q]))), at, dur, ease);
+ return at + dur;
+ },
+ work,
+ flashE(i, at, j = null) { ecells[i].forEach((cl, c) => { if (j === null || j === c) { tw(cl.glow, { o: .3 }, at, .25); tw(cl.glow, { o: 0 }, at + 1.1, .6); } }); },
+ ringE(i, j, at, { color = COL.chalk, dash = false } = {}) {
+ const rg = G(Eg, { x: ecx(j), y: ry(i) - size * .32, o: 0 });
+ mk('ellipse', { rx: ecw * .46, ry: size * .62, fill: 'none', stroke: color, 'stroke-width': 3.5, ...(dash ? { 'stroke-dasharray': '7 6' } : {}) }, rg);
+ show(rg, at, .35);
+ return rg;
+ },
+ // Dim all of E but row i (null: all rows back).
+ focusE(i, at, dur = .4) { I.forEach(r => [Ebars[r], ...ecells[r].map(c => c.c)].forEach(e => tw(e, { o: i === null || i === r ? 1 : .3 }, at, dur))); },
+ get v() { return { ...s }; },
+ set(vals) { edit(vals); },
+ live(on, { only = null } = {}) {
+ live = on;
+ allowed = on && only ? new Set(only) : null;
+ boxesLive();
+ // the picture can be dragged only when every number of [A | b] is free
+ if (sys.lock) { sys.lock(on && !only ? null : []); sys.live(on); } else sys.live(on && !only, {});
+ },
+ onChange(f) { listeners.push(f); },
+ prod: () => prod(s),
+ };
+ return api;
+}
+
+// A question on E (or on [A | b]): the reader scrubs the numbers named in only until test(v, product) holds.
+const emTask = (em, test, why, hint, reveal, { only = null } = {}) => (body, api) => {
+ em.live(true, { only });
+ return {
+ check: () => { const v = em.v, pr = em.prod(), ok = test(v, pr); api.grade(ok, ok ? why : typeof hint === 'function' ? hint(v, pr) : hint); },
+ reveal: () => { reveal?.(); return why; },
+ lock: () => em.live(false),
+ hint: [kbd('Tab'), ' to a number of the matrix, ', kbd('↑'), kbd('↓'), ' to change it, or drag it sideways'],
+ };
+};
+
+// Swap rows i and j of E on the beat clock (a row exchange done by a matrix): E's rows and, on the left, the product's
+// rows slide past each other while the product's row colours (and a linsys's lines) trade; then E takes the swapped
+// rows. { cols: true } swaps E's columns instead; on the right (side 'right') the product's columns slide past each
+// other, and the picture jumps to the swapped system at the end. sys: the linsys whose line colours should trade.
+function emSwap(em, i, j, at, dur = 1.4, { cols = false, sys = null } = {}) {
+ const n = em.n, I = [...Array(n).keys()], E = em.plan, next = {};
+ I.forEach(r => I.forEach(c => {
+ const [r2, c2] = cols ? [r, c === i ? j : c === j ? i : c] : [r === i ? j : r === j ? i : r, c];
+ next[`e${r}${c}`] = E[`e${r2}${c2}`];
+ }));
+ const Pt = em.Pt, rowsMove = !cols, lines = !cols && sys?.lines?.[0]?.l ? sys.lines.map(l => l.l) : [];
+ const right = em.side === 'right';
+ prog(q => {
+ const s = q < 1 ? q : 0, c = (a, b) => q < 1 ? mix(a, b, q) : a;
+ if (rowsMove) {
+ const dy = em.ry(j) - em.ry(i);
+ em.ecells[i].forEach(cl => put(cl.c, { y: em.ry(i) + dy * s })); em.ecells[j].forEach(cl => put(cl.c, { y: em.ry(j) - dy * s }));
+ if (!right) {
+ Pt.cells[i].forEach(cl => put(cl.c, { y: Pt.ry(i) + dy * s })); Pt.cells[j].forEach(cl => put(cl.c, { y: Pt.ry(j) - dy * s }));
+ Pt.bars[i].setAttribute('fill', c(EM_ROW[i], EM_ROW[j])); Pt.bars[j].setAttribute('fill', c(EM_ROW[j], EM_ROW[i]));
+ if (lines[i] && lines[j]) { lines[i].setAttribute('stroke', c(EM_ROW[i], EM_ROW[j])); lines[j].setAttribute('stroke', c(EM_ROW[j], EM_ROW[i])); }
+ }
+ } else {
+ const dx = em.ecx(j) - em.ecx(i), px = Pt.cx(j) - Pt.cx(i);
+ I.forEach(r => {
+ put(em.ecells[r][i].c, { x: em.ecx(i) + dx * s }); put(em.ecells[r][j].c, { x: em.ecx(j) - dx * s });
+ if (right) { put(Pt.cells[r][i].c, { x: Pt.cx(i) + px * s }); put(Pt.cells[r][j].c, { x: Pt.cx(j) - px * s }); }
+ });
+ }
+ }, at, dur);
+ em.to(next, at + dur, 0);
+ return next;
+}