Skip to content

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

feat(linear-algebra): chapter 14 and bars.js; exact readouts change

yzrc9d6f39ab54e
diff --git a/site/linear-algebra/ch14/audio/en/ask.mp3 b/site/linear-algebra/ch14/audio/en/ask.mp3
new file mode 100644
index 0000000..55d4aca
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/ask.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/bars.mp3 b/site/linear-algebra/ch14/audio/en/bars.mp3
new file mode 100644
index 0000000..4a31158
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/bars.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/final1.mp3 b/site/linear-algebra/ch14/audio/en/final1.mp3
new file mode 100644
index 0000000..ef65f2d
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/final1.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/final2.mp3 b/site/linear-algebra/ch14/audio/en/final2.mp3
new file mode 100644
index 0000000..4723e04
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/final2.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/final3.mp3 b/site/linear-algebra/ch14/audio/en/final3.mp3
new file mode 100644
index 0000000..f2c453f
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/final3.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/final4.mp3 b/site/linear-algebra/ch14/audio/en/final4.mp3
new file mode 100644
index 0000000..ca444be
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/final4.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/finish.mp3 b/site/linear-algebra/ch14/audio/en/finish.mp3
new file mode 100644
index 0000000..6cd0ad9
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/finish.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/flat.mp3 b/site/linear-algebra/ch14/audio/en/flat.mp3
new file mode 100644
index 0000000..46d4627
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/flat.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/four.mp3 b/site/linear-algebra/ch14/audio/en/four.mp3
new file mode 100644
index 0000000..6c414fa
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/four.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/intro.mp3 b/site/linear-algebra/ch14/audio/en/intro.mp3
new file mode 100644
index 0000000..00cecdf
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/intro.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/lattice.mp3 b/site/linear-algebra/ch14/audio/en/lattice.mp3
new file mode 100644
index 0000000..69351ee
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/lattice.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/many.mp3 b/site/linear-algebra/ch14/audio/en/many.mp3
new file mode 100644
index 0000000..9b1fbac
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/many.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/match.mp3 b/site/linear-algebra/ch14/audio/en/match.mp3
new file mode 100644
index 0000000..327b0c8
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/match.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/nine.mp3 b/site/linear-algebra/ch14/audio/en/nine.mp3
new file mode 100644
index 0000000..e9426d7
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/nine.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/parallel.mp3 b/site/linear-algebra/ch14/audio/en/parallel.mp3
new file mode 100644
index 0000000..3a60bef
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/parallel.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/play.mp3 b/site/linear-algebra/ch14/audio/en/play.mp3
new file mode 100644
index 0000000..fcb600e
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/play.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/q1.mp3 b/site/linear-algebra/ch14/audio/en/q1.mp3
new file mode 100644
index 0000000..629dd73
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/q1.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/q2.mp3 b/site/linear-algebra/ch14/audio/en/q2.mp3
new file mode 100644
index 0000000..4d6b83b
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/q2.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/q3.mp3 b/site/linear-algebra/ch14/audio/en/q3.mp3
new file mode 100644
index 0000000..1c9e6c5
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/q3.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/q4.mp3 b/site/linear-algebra/ch14/audio/en/q4.mp3
new file mode 100644
index 0000000..9f6a5a4
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/q4.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/sheet.mp3 b/site/linear-algebra/ch14/audio/en/sheet.mp3
new file mode 100644
index 0000000..87a8182
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/sheet.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/timings.js b/site/linear-algebra/ch14/audio/en/timings.js
new file mode 100644
index 0000000..62d5895
--- /dev/null
+++ b/site/linear-algebra/ch14/audio/en/timings.js
@@ -0,0 +1,920 @@
+window.TIMINGS = {
+ "intro": {
+ "dur": 14.592,
+ "marks": {
+ "sub": 3.307,
+ "move": 8.06
+ },
+ "cues": [
+ [
+ 0.104,
+ "Chapter fourteen."
+ ],
+ [
+ 1.458,
+ "Can we solve for every b?"
+ ],
+ [
+ 3.307,
+ "This is the big question of lecture one, and the last chapter of unit one."
+ ],
+ [
+ 8.06,
+ "We keep the columns, move the target b anywhere we like, and ask: is there always a mix that reaches it?"
+ ]
+ ]
+ },
+ "ask": {
+ "dur": 54.72,
+ "marks": {
+ "eq": 2.227,
+ "cols": 7.826,
+ "mix": 16.797,
+ "flip": 23.073,
+ "big": 27.943,
+ "try": 35.547,
+ "b1": 37.721,
+ "b2": 42.201,
+ "b3": 48.06
+ },
+ "cues": [
+ [
+ 0.13,
+ "Here's our system from chapter two."
+ ],
+ [
+ 2.227,
+ "Two x minus y equals zero, and minus x plus two y equals three."
+ ],
+ [
+ 7.826,
+ "Read down the columns, as in chapter seven: x times two, minus one, plus y times minus one, two, equals b."
+ ],
+ [
+ 16.797,
+ "For b equals zero, three, the mix is x equals one and y equals two."
+ ],
+ [
+ 23.073,
+ "Until now, someone handed us one b, and we looked for its mix."
+ ],
+ [
+ 27.943,
+ "Now we ask something bigger."
+ ],
+ [
+ 29.635,
+ "Keep the two columns."
+ ],
+ [
+ 31.25,
+ "Can we find a mix for every b, for every point of the plane?"
+ ],
+ [
+ 35.547,
+ "Let's move b and watch the mix."
+ ],
+ [
+ 37.721,
+ "b equals three, zero: the mix is two and one."
+ ],
+ [
+ 42.201,
+ "b equals minus two, minus two: the mix is minus two and minus two."
+ ],
+ [
+ 48.06,
+ "b equals one, zero: two thirds and one third."
+ ],
+ [
+ 52.578,
+ "A fraction, but it's there."
+ ]
+ ]
+ },
+ "lattice": {
+ "dur": 34.704,
+ "marks": {
+ "dots": 1.458,
+ "grid": 5.117,
+ "fill": 12.617,
+ "drag": 17.201,
+ "follow": 18.945,
+ "rows": 21.706,
+ "cross": 23.385,
+ "ans": 29.023
+ },
+ "cues": [
+ [
+ 0.104,
+ "Why does it keep working?"
+ ],
+ [
+ 1.458,
+ "Mark every point that whole number mixes reach."
+ ],
+ [
+ 5.117,
+ "As in chapter six, they make a slanted grid: lines along column one, and lines along column two."
+ ],
+ [
+ 12.617,
+ "Fractions fill every gap between the lines."
+ ],
+ [
+ 15.82,
+ "Nothing is left out."
+ ],
+ [
+ 17.201,
+ "So drag b anywhere."
+ ],
+ [
+ 18.945,
+ "The mix follows it, and it never gets stuck."
+ ],
+ [
+ 21.706,
+ "The row picture agrees."
+ ],
+ [
+ 23.385,
+ "As b moves, the two lines slide, but they always cross, at exactly one point."
+ ],
+ [
+ 29.023,
+ "So for these two columns the answer is yes: every b has a mix, and only one."
+ ]
+ ]
+ },
+ "q1": {
+ "dur": 6.144,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 0.99,
+ "Move b until the mix is x equals one, y equals minus one."
+ ]
+ ]
+ },
+ "parallel": {
+ "dur": 60.192,
+ "marks": {
+ "c1": 1.862,
+ "c2": 3.698,
+ "turn": 10.456,
+ "squash": 12.422,
+ "par": 15.469,
+ "line": 20.716,
+ "why": 24.922,
+ "top": 29.714,
+ "bot": 32.135,
+ "rule": 36.224,
+ "b": 39.896,
+ "off": 42.565,
+ "rowp": 47.708,
+ "parl": 55.391
+ },
+ "cues": [
+ [
+ 0.091,
+ "Now a different pair of columns."
+ ],
+ [
+ 1.862,
+ "Column one is one, two."
+ ],
+ [
+ 3.698,
+ "Column two is minus one, two."
+ ],
+ [
+ 6.406,
+ "They point different ways, so the grid covers the plane."
+ ],
+ [
+ 10.456,
+ "Now swing column two around, and watch the grid squash, flatter and flatter, until column two is two, four: exactly twice column one."
+ ],
+ [
+ 20.716,
+ "Now every mix lands on one line, the line through one, two."
+ ],
+ [
+ 24.922,
+ "Here's why."
+ ],
+ [
+ 25.872,
+ "Take x times one, two, plus y times two, four."
+ ],
+ [
+ 29.714,
+ "The top is x plus two y."
+ ],
+ [
+ 32.135,
+ "The bottom is two x plus four y, and that's twice the top."
+ ],
+ [
+ 36.224,
+ "Whatever the mix, the bottom number comes out twice the top number."
+ ],
+ [
+ 39.896,
+ "Now take b equals three, five."
+ ],
+ [
+ 42.565,
+ "Five is not twice three."
+ ],
+ [
+ 44.349,
+ "So b is off the line, and no mix can reach it."
+ ],
+ [
+ 47.708,
+ "The row picture says the same."
+ ],
+ [
+ 49.792,
+ "x plus two y equals three, and two x plus four y equals five: two parallel lines that never meet."
+ ],
+ [
+ 57.721,
+ "No solution, seen two ways."
+ ]
+ ]
+ },
+ "many": {
+ "dur": 34.752,
+ "marks": {
+ "b": 1.875,
+ "on": 5.417,
+ "m2": 10.13,
+ "m3": 11.615,
+ "many": 15.534,
+ "rowp": 18.724,
+ "same": 22.812,
+ "sum": 25.273
+ },
+ "cues": [
+ [
+ 0.104,
+ "But some targets are on the line."
+ ],
+ [
+ 1.875,
+ "Slide b to two, four."
+ ],
+ [
+ 3.893,
+ "Four is twice two, so b is on the line, and now there is a mix: two of column one."
+ ],
+ [
+ 10.13,
+ "Or one of column two."
+ ],
+ [
+ 11.615,
+ "Or minus two of column one, plus two of column two."
+ ],
+ [
+ 15.534,
+ "In fact, endlessly many mixes reach it."
+ ],
+ [
+ 18.724,
+ "In the row picture, the two equations now make the same line, so every point on it solves both."
+ ],
+ [
+ 25.273,
+ "So when the columns lie on one line, a b off the line has no mix, and a b on the line has endlessly many."
+ ],
+ [
+ 33.19,
+ "Never exactly one."
+ ]
+ ]
+ },
+ "q2": {
+ "dur": 5.136,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Quick check."
+ ],
+ [
+ 1.133,
+ "With these two columns, which targets can a mix reach?"
+ ]
+ ]
+ },
+ "sheet": {
+ "dur": 43.632,
+ "marks": {
+ "sys": 2.057,
+ "ask": 5.846,
+ "s12": 9.427,
+ "c3": 17.135,
+ "z1": 19.661,
+ "zneg": 26.38,
+ "sweep": 28.841,
+ "any": 35.768,
+ "drag": 39.622,
+ "follow": 41.068
+ },
+ "cues": [
+ [
+ 0.104,
+ "Now three dimensions."
+ ],
+ [
+ 2.057,
+ "The lecture's three equations, and their three columns."
+ ],
+ [
+ 5.846,
+ "Can three columns reach every point in space?"
+ ],
+ [
+ 9.427,
+ "Start with columns one and two alone."
+ ],
+ [
+ 12.266,
+ "All their mixes make a flat sheet through the origin, tilted in space."
+ ],
+ [
+ 17.135,
+ "Column three points out of that sheet."
+ ],
+ [
+ 19.661,
+ "Now add one of column three: the whole sheet lifts, to pass through the tip of column three."
+ ],
+ [
+ 26.38,
+ "Minus one drops it below the origin."
+ ],
+ [
+ 28.841,
+ "As z runs from low to high, the sheet sweeps through all of space, and passes every point."
+ ],
+ [
+ 35.768,
+ "So every b lies on one of these sheets, and has a mix."
+ ],
+ [
+ 39.622,
+ "Move b anywhere, and the mix follows, just as in the plane."
+ ]
+ ]
+ },
+ "flat": {
+ "dur": 51.696,
+ "marks": {
+ "move": 2.305,
+ "fall": 3.555,
+ "now": 6.445,
+ "sum": 11.029,
+ "stuck": 13.971,
+ "test": 19.362,
+ "scrub": 27.747,
+ "zero": 33.854,
+ "old": 35.755,
+ "calc": 39.648,
+ "off": 44.453,
+ "rows": 47.63
+ },
+ "cues": [
+ [
+ 0.104,
+ "But three columns can fail too."
+ ],
+ [
+ 2.305,
+ "Watch column three fall into the sheet of columns one and two."
+ ],
+ [
+ 6.445,
+ "Now column three is one, one, minus three: exactly column one plus column two."
+ ],
+ [
+ 13.971,
+ "Adding column three no longer lifts the sheet."
+ ],
+ [
+ 17.513,
+ "Every mix stays inside it."
+ ],
+ [
+ 19.362,
+ "You can check this with numbers."
+ ],
+ [
+ 21.25,
+ "For every point on this sheet, the top, plus twice the middle, plus the bottom, comes out zero."
+ ],
+ [
+ 27.747,
+ "Change the mix, and A x, where the mix lands, moves around inside the sheet, and that sum stays zero."
+ ],
+ [
+ 35.755,
+ "Now take the old target, zero, minus one, four."
+ ],
+ [
+ 39.648,
+ "Zero, minus two, plus four: that's two, not zero."
+ ],
+ [
+ 44.453,
+ "This b is off the sheet, and no mix reaches it."
+ ],
+ [
+ 47.63,
+ "In the row picture, the three planes have no point in common."
+ ]
+ ]
+ },
+ "q3": {
+ "dur": 8.4,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 1.042,
+ "Change the mix until A x lands on the ring, three, zero, minus three."
+ ],
+ [
+ 6.992,
+ "There's more than one way."
+ ]
+ ]
+ },
+ "bars": {
+ "dur": 35.496,
+ "marks": {
+ "two": 1.849,
+ "bars": 5.586,
+ "drag": 12.734,
+ "follow": 13.997,
+ "three": 18.424,
+ "four": 23.346,
+ "no": 27.969,
+ "fourb": 31.849
+ },
+ "cues": [
+ [
+ 0.104,
+ "What about four numbers?"
+ ],
+ [
+ 1.849,
+ "Here's b in the plane: two numbers, and an arrow."
+ ],
+ [
+ 5.586,
+ "Now draw each number as a bar instead: up for positive, down for negative, as long as the number is big."
+ ],
+ [
+ 12.734,
+ "Move the arrow, and the bars move with it."
+ ],
+ [
+ 15.755,
+ "Same two numbers, two pictures."
+ ],
+ [
+ 18.424,
+ "In space, three numbers: three axes, or three bars."
+ ],
+ [
+ 23.346,
+ "Four numbers would need a fourth axis, at right angles to all three."
+ ],
+ [
+ 27.969,
+ "Our space has no room for it, so we can't draw that arrow."
+ ],
+ [
+ 31.849,
+ "But the bars don't mind."
+ ],
+ [
+ 33.372,
+ "Four numbers: four bars."
+ ]
+ ]
+ },
+ "four": {
+ "dur": 47.616,
+ "marks": {
+ "names": 4.167,
+ "e1": 11.328,
+ "e2": 13.021,
+ "e3": 16.068,
+ "e4": 19.206,
+ "cols": 22.331,
+ "c1": 24.648,
+ "asbars": 28.854,
+ "call": 30.339,
+ "b": 32.435,
+ "mix": 36.055,
+ "ax": 39.935
+ },
+ "cues": [
+ [
+ 0.117,
+ "Here's a system with four equations and four unknowns."
+ ],
+ [
+ 4.167,
+ "We've run out of letters, so we number the unknowns: x one, x two, x three, x four."
+ ],
+ [
+ 11.328,
+ "x one equals one."
+ ],
+ [
+ 13.021,
+ "x one plus x two equals three."
+ ],
+ [
+ 16.068,
+ "x two plus x three equals four."
+ ],
+ [
+ 19.206,
+ "And x three plus x four equals two."
+ ],
+ [
+ 22.331,
+ "Read down the columns, as always."
+ ],
+ [
+ 24.648,
+ "Column one is one, one, zero, zero, drawn as bars."
+ ],
+ [
+ 30.339,
+ "And the other three columns."
+ ],
+ [
+ 32.435,
+ "On the right, b: one, three, four, two."
+ ],
+ [
+ 36.055,
+ "In front of each column, its amount: x one to x four."
+ ],
+ [
+ 39.935,
+ "The bars in the middle are A x, the mix of the columns."
+ ],
+ [
+ 43.971,
+ "The dashed outlines are b's bars: the targets."
+ ]
+ ]
+ },
+ "match": {
+ "dur": 51.168,
+ "marks": {
+ "zero": 1.419,
+ "x1": 6.68,
+ "x1b": 8.294,
+ "top": 12.8,
+ "x2": 14.544,
+ "x2v": 18.411,
+ "x2b": 20.065,
+ "two": 24.219,
+ "x3": 25.664,
+ "x3v": 28.464,
+ "x3b": 30.273,
+ "x4": 33.112,
+ "all": 38.594,
+ "row": 44.505
+ },
+ "cues": [
+ [
+ 0.104,
+ "Let's find the mix."
+ ],
+ [
+ 1.419,
+ "With every amount zero, A x is all zeros: no bars."
+ ],
+ [
+ 6.68,
+ "Turn x one up to one."
+ ],
+ [
+ 8.294,
+ "Column one adds one to the top row and one to the second row."
+ ],
+ [
+ 12.8,
+ "The top bar matches b."
+ ],
+ [
+ 14.544,
+ "The second row needs three and has one."
+ ],
+ [
+ 17.461,
+ "Two more: so x two is two."
+ ],
+ [
+ 20.065,
+ "Column two adds two to rows two and three."
+ ],
+ [
+ 24.219,
+ "Row two matches."
+ ],
+ [
+ 25.664,
+ "Row three needs four and has two: so x three is two."
+ ],
+ [
+ 30.273,
+ "Now rows three and four both match."
+ ],
+ [
+ 33.112,
+ "Row four needs two, and already has two, so x four stays zero."
+ ],
+ [
+ 38.594,
+ "Every bar matches."
+ ],
+ [
+ 40.104,
+ "A x equals b, with the mix one, two, two, zero."
+ ],
+ [
+ 44.505,
+ "And reading across a row gives back its equation: row two says one plus two is three."
+ ]
+ ]
+ },
+ "q4": {
+ "dur": 5.352,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Your turn."
+ ],
+ [
+ 0.99,
+ "Change the amounts until every bar of A x matches b."
+ ]
+ ]
+ },
+ "nine": {
+ "dur": 33.0,
+ "marks": {
+ "nine": 1.576,
+ "same": 5.898,
+ "move": 10.404,
+ "match": 13.242,
+ "cant": 15.404,
+ "q": 21.693,
+ "yes": 26.12
+ },
+ "cues": [
+ [
+ 0.104,
+ "And nine equations?"
+ ],
+ [
+ 1.576,
+ "Nine unknowns, nine columns, nine numbers in each."
+ ],
+ [
+ 5.898,
+ "The same rules: each amount times its column, added row by row."
+ ],
+ [
+ 10.404,
+ "Change the amounts, and the bars move, until every row matches."
+ ],
+ [
+ 15.404,
+ "We cannot draw nine axes."
+ ],
+ [
+ 17.721,
+ "But we can still compute, and still see the numbers move."
+ ],
+ [
+ 21.693,
+ "And the big question is the same: do the columns reach every b?"
+ ],
+ [
+ 26.12,
+ "Yes, when each column points in a truly new direction, one that no mix of the others can make."
+ ]
+ ]
+ },
+ "unit": {
+ "dur": 44.28,
+ "marks": {
+ "sys": 1.849,
+ "row": 3.19,
+ "col": 10.599,
+ "ax": 17.669,
+ "big": 21.302,
+ "yes": 24.427,
+ "no": 29.805,
+ "next": 38.698
+ },
+ "cues": [
+ [
+ 0.104,
+ "That closes unit one."
+ ],
+ [
+ 1.849,
+ "One system, and the row picture: each equation is a line, or in space a plane, and the solution is where they all meet."
+ ],
+ [
+ 10.599,
+ "The column picture: each column is an arrow, and the solution is the mix of the columns that lands on b."
+ ],
+ [
+ 17.669,
+ "And one short name for both: A x equals b."
+ ],
+ [
+ 21.302,
+ "The big question: can we solve it for every b?"
+ ],
+ [
+ 24.427,
+ "Yes, when the columns point in different directions and fill the whole space."
+ ],
+ [
+ 29.805,
+ "No, when they lie flat, on a line or in a plane."
+ ],
+ [
+ 33.776,
+ "Then some b are out of reach, and the others have endlessly many mixes."
+ ],
+ [
+ 38.698,
+ "In unit two, we learn how to find the mix for any system, step by step."
+ ]
+ ]
+ },
+ "wrap": {
+ "dur": 31.296,
+ "marks": {
+ "w1": 0.99,
+ "w2": 9.31,
+ "w3": 16.094,
+ "w4": 22.786,
+ "end": 29.102
+ },
+ "cues": [
+ [
+ 0.104,
+ "To sum up."
+ ],
+ [
+ 0.99,
+ "Can we solve A x equals b for every b?"
+ ],
+ [
+ 5.143,
+ "Ask whether the mixes of the columns fill the whole space."
+ ],
+ [
+ 9.31,
+ "Two columns that point different ways fill the plane."
+ ],
+ [
+ 12.682,
+ "Two along one line fill only that line."
+ ],
+ [
+ 16.094,
+ "Three columns not in one plane fill space."
+ ],
+ [
+ 19.635,
+ "Three in one plane fill only that plane."
+ ],
+ [
+ 22.786,
+ "With more numbers we can't draw the axes, but the rules are the same, and the bars show the numbers move."
+ ],
+ [
+ 29.102,
+ "Now try the chapter practice."
+ ]
+ ]
+ },
+ "final1": {
+ "dur": 3.96,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Chapter practice."
+ ],
+ [
+ 1.51,
+ "Do the columns reach every b?"
+ ]
+ ]
+ },
+ "final2": {
+ "dur": 2.4,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Can a mix of these columns reach b?"
+ ]
+ ]
+ },
+ "final3": {
+ "dur": 2.832,
+ "marks": {},
+ "cues": [
+ [
+ 0.091,
+ "Work out these mixes, number by number."
+ ]
+ ]
+ },
+ "final4": {
+ "dur": 5.424,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Last set."
+ ],
+ [
+ 1.237,
+ "Move b, or the amounts, until A x equals b."
+ ]
+ ]
+ },
+ "play": {
+ "dur": 15.144,
+ "marks": {
+ "go": 3.75
+ },
+ "cues": [
+ [
+ 0.104,
+ "Playground."
+ ],
+ [
+ 1.068,
+ "Nothing here is marked right or wrong."
+ ],
+ [
+ 3.75,
+ "Drag the columns and b, change any number, and watch the grid of mixes: when does it fill the plane, and when does it squash to a line?"
+ ],
+ [
+ 13.49,
+ "Press continue when you're done."
+ ]
+ ]
+ },
+ "finish": {
+ "dur": 13.104,
+ "marks": {},
+ "cues": [
+ [
+ 0.104,
+ "Well done."
+ ],
+ [
+ 1.12,
+ "That's the end of chapter fourteen, can we solve for every b, and the end of unit one."
+ ],
+ [
+ 7.201,
+ "Next: elimination, a way to find the mix for any system, step by step."
+ ]
+ ]
+ }
+};
diff --git a/site/linear-algebra/ch14/audio/en/unit.mp3 b/site/linear-algebra/ch14/audio/en/unit.mp3
new file mode 100644
index 0000000..d448e64
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/unit.mp3 differ
diff --git a/site/linear-algebra/ch14/audio/en/wrap.mp3 b/site/linear-algebra/ch14/audio/en/wrap.mp3
new file mode 100644
index 0000000..6b503a1
Binary files /dev/null and b/site/linear-algebra/ch14/audio/en/wrap.mp3 differ
diff --git a/site/linear-algebra/ch14/index.html b/site/linear-algebra/ch14/index.html
new file mode 100644
index 0000000..3f091ce
--- /dev/null
+++ b/site/linear-algebra/ch14/index.html
@@ -0,0 +1,734 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Can We Solve for Every b?</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/bars.js"></script>
+<script src="../lib/play.js"></script>
+<script src="audio/en/timings.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 14, title: 'Can We Solve for Every b?', minutes: 14, language: 'en' };
+
+/* ---------- the systems of this chapter ---------- */
+const LA = [[2, -1], [-1, 2]]; // the lecture's 2 × 2: columns (2, −1), (−1, 2)
+const PAR0 = [[1, -1], [2, 2]], PAR = [[1, 2], [2, 4]]; // column 2 swings from (−1, 2) to (2, 4) = 2·column 1
+const LEC3 = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]]; // the lecture's 3 × 3
+const FLAT3 = [[2, -1, 1], [-1, 2, 1], [0, -3, -3]]; // column 3 = column 1 + column 2 = (1, 1, −3)
+const N3 = [1, 2, 1]; // col 1 × col 2 / 3: the sheet of col 1, col 2 is x + 2y + z = 0
+const VIEW = { yaw: 50, pitch: 20 }; // chapter 13's view: the lecture columns land far apart
+const BID = [[1, 0, 0, 0], [1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1]]; // x₁ = …, x₁ + x₂ = …, x₂ + x₃ = …, x₃ + x₄ = …
+const AXC = [COL.whole, COL.nat, COL.int]; // steps along x, y, z (chapter 11's walk)
+const SUB = BR_SUB;
+
+/* ---------- chapter drawing helpers ---------- */
+const CARD = { x: 40, y: 600, w: 720, cls: 'side' }; // under the column form, beside the plane
+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 fmt1 = n => { const r = Math.round(n * 10) / 10; return num(Number.isInteger(r) ? r : +r.toFixed(1)); };
+const pairStr = (x, y) => `(${num(x)}, ${num(y)})`;
+const tri = q => `(${q.map(c => fmt1(c)).join(', ')})`;
+// A number changes: it lights amber and goes back to its own colour.
+const flash = (els, t0) => els.forEach(e => {
+ const base = e.getAttribute('fill');
+ tw(e, { c_fill: base === COL.task ? COL.chalk : COL.task }, t0, .25); tw(e, { c_fill: base }, t0 + .7, .4); // over in 1.1 s: flashes 1.3 s apart never overlap
+});
+const thick = (e, t0, w = 5) => { tw(e, { 'a_stroke-width': w + 5 }, t0, .3); tw(e, { 'a_stroke-width': w }, t0 + .8, .5); };
+const box = (p, x, y, w, h, color, t, until) => {
+ const r = mk('rect', { x, y, width: w, height: h, rx: 12, fill: color, 'fill-opacity': .08, stroke: color, 'stroke-width': 2.5, 'stroke-dasharray': '6 6' }, p);
+ put(r, { o: 0 }); show(r, t, .3); if (until !== undefined) hide(r, until, .3);
+ return r;
+};
+
+/* ---------- 2D: equations, column form, mix and plane, one linsys ---------- */
+const sys2 = (p, A, b, { t0 = .1, view = 'col' } = {}) => {
+ const sys = linsys(p, { A, b, eq: [90, 200], size: 46, mat: null, sol: false, view, t0 });
+ sys.labels(['col 1', 'col 2', 'b']);
+ return sys;
+};
+// x·[col 1] + y·[col 2] = [b], its numbers read from the system as it moves.
+const colForm2 = (sys, p, t0, { x = 90, y = 420, size = 44 } = {}) => {
+ const g = G(p, { o: 0 }), rh = 58, top = y - size * .95, bot = y + rh + size * .35, texts = {};
+ const br = bx => path(g, `M${bx + 12} ${top}H${bx}V${bot}H${bx + 12}M${bx + 88} ${top}H${bx + 100}V${bot}H${bx + 88}`, { stroke: COL.chalk, 'stroke-width': 3, fill: 'none' });
+ const sign = (s, sx, it = false) => { const t = T(g, s, { x: sx, y: y + rh / 2 + 4, size, fill: COL.chalk, font: MATH, anchor: 'middle' }); if (it) t.setAttribute('font-style', 'italic'); };
+ sign('x', x + 14, true); br(x + 36); sign('+', x + 262); sign('y', x + 296, true); br(x + 318); sign('=', x + 455); br(x + 488);
+ [['a00', x + 86, 0], ['a10', x + 86, 1], ['a01', x + 368, 0], ['a11', x + 368, 1], ['b0', x + 538, 0], ['b1', x + 538, 1]].forEach(([k, cx, i]) => {
+ texts[k] = T(g, '', { x: cx, y: y + rh * i, size: size * .9, fill: k[0] === 'b' ? COL.task : LS_COLS[+k[2]], font: MATH, anchor: 'middle' });
+ });
+ const upd = v => { for (const k in texts) { const s = fmt1(v[k]); if (texts[k].textContent !== s) texts[k].textContent = s; } };
+ sys.onChange(upd); upd(sys.v);
+ show(g, t0);
+ return { g, num: k => [texts[k]] };
+};
+// The mix, exact: "x = 2/3, y = 1/3", or why there is none, or that there are endlessly many.
+const exact2 = (n, v) => { // whole numbers within 1e-9 count as whole: a tween's last step can land a hair off
+ const det = Math.round(v.a00 * v.a11 - v.a01 * v.a10);
+ if (!Object.values(v).every(z => Math.abs(z - Math.round(z)) < 1e-9) || !det) return [fmt1(n)];
+ const k = Math.round(n * det), g = gcd(Math.abs(k), Math.abs(det)) || 1, nn = k / g * Math.sign(det), dd = Math.abs(det) / g;
+ return dd === 1 ? [num(nn)] : [nn < 0 ? '−' : '', F(Math.abs(nn), dd)];
+};
+const mixOut = (sys, p, t0, { x = 90, y = 555 } = {}) => {
+ const g = G(p, { o: 0 });
+ let key = '';
+ const upd = (v, s) => {
+ const k = s.x !== undefined ? [...exact2(s.x, v), '|', ...exact2(s.y, v)].map(z => typeof z === 'string' ? z : z.f.join('/')).join() : s.none ? 'none' : 'many';
+ if (k === key) return;
+ key = k; g.replaceChildren();
+ if (s.x !== undefined) M(g, ['mix: x = ', ...exact2(s.x, v), ', y = ', ...exact2(s.y, v)], { x, y, size: 40, fill: COL.task, anchor: 'start' });
+ else T(g, s.none ? 'no mix reaches b' : 'endlessly many mixes reach b', { x, y: y - 4, size: 32, fill: s.none ? COL.bad : COL.task, weight: 600 });
+ };
+ sys.onChange(upd); upd(sys.v, sys.solve());
+ show(g, t0);
+ return g;
+};
+// The lattice of whole-number mixes on the plane (as chapter 6): dots at every x·col 1 + y·col 2 with whole x, y,
+// lines along each column, a shade when the columns fill the plane and an amber line when they lie on one line.
+const lattice2 = sys => {
+ const P2 = sys.P, { PX, PY } = P2, g = G(P2.g, {});
+ P2.g.insertBefore(g, sys.ROWV); // under the lines and arrows
+ const shade = mk('rect', { x: PX(P2.x0), y: PY(P2.y1), width: PX(P2.x1) - PX(P2.x0), height: PY(P2.y0) - PY(P2.y1), fill: COL.task, 'fill-opacity': .1 }, g);
+ const L = [0, 1].map(i => path(g, '', { stroke: LS_COLS[i], 'stroke-width': 1.5, 'stroke-opacity': .5, fill: 'none' }));
+ const dots = path(g, '', { stroke: COL.chalk, 'stroke-width': 7, 'stroke-linecap': 'round', 'stroke-opacity': .55, fill: 'none' });
+ const span = path(g, '', { stroke: COL.task, 'stroke-width': 7, 'stroke-opacity': .6, 'stroke-linecap': 'round', fill: 'none' });
+ [shade, ...L, dots, span].forEach(e => put(e, { o: 0 }));
+ const inBox = (X, Y) => X >= P2.x0 - 1e-9 && X <= P2.x1 + 1e-9 && Y >= P2.y0 - 1e-9 && Y <= P2.y1 + 1e-9;
+ const clipDir = (q, e) => { // the part of the line through q along e inside the grid
+ const ts = [], tryT = (t, val, lo, hi) => { if (val >= lo - 1e-9 && val <= hi + 1e-9) ts.push(t); };
+ if (Math.abs(e[0]) > 1e-9) for (const X of [P2.x0, P2.x1]) { const t = (X - q[0]) / e[0]; tryT(t, q[1] + t * e[1], P2.y0, P2.y1); }
+ if (Math.abs(e[1]) > 1e-9) for (const Y of [P2.y0, P2.y1]) { const t = (Y - q[1]) / e[1]; tryT(t, q[0] + t * e[0], P2.x0, P2.x1); }
+ if (ts.length < 2) return '';
+ const a = Math.min(...ts), b = Math.max(...ts);
+ return b - a < 1e-9 ? '' : `M${PX(q[0] + a * e[0]).toFixed(1)} ${PY(q[1] + a * e[1]).toFixed(1)}L${PX(q[0] + b * e[0]).toFixed(1)} ${PY(q[1] + b * e[1]).toFixed(1)}`;
+ };
+ const att = (e, d) => { if (e.getAttribute('d') !== d) e.setAttribute('d', d); };
+ const draw_ = v => {
+ const a = [v.a00, v.a10], b = [v.a01, v.a11], det = a[0] * b[1] - b[0] * a[1];
+ let d1 = '', d2 = '', dd = '', sp = '';
+ if (Math.abs(det) > 1e-6) {
+ const cs = [], ds = [];
+ for (const X of [P2.x0, P2.x1]) for (const Y of [P2.y0, P2.y1]) { cs.push((X * b[1] - b[0] * Y) / det); ds.push((a[0] * Y - X * a[1]) / det); }
+ const cr = [Math.ceil(Math.min(...cs)), Math.floor(Math.max(...cs))], dr = [Math.ceil(Math.min(...ds)), Math.floor(Math.max(...ds))];
+ // ponytail: nearly parallel columns need ever more lines; past 300 the grid is left out (a smear by then)
+ if (cr[1] - cr[0] < 300 && dr[1] - dr[0] < 300) {
+ for (let k = dr[0]; k <= dr[1]; k++) d1 += clipDir([k * b[0], k * b[1]], a);
+ for (let k = cr[0]; k <= cr[1]; k++) d2 += clipDir([k * a[0], k * a[1]], b);
+ }
+ if ((cr[1] - cr[0] + 1) * (dr[1] - dr[0] + 1) < 6000)
+ for (let i = cr[0]; i <= cr[1]; i++) for (let j = dr[0]; j <= dr[1]; j++) { const X = i * a[0] + j * b[0], Y = i * a[1] + j * b[1]; if (inBox(X, Y)) dd += `M${PX(X).toFixed(1)} ${PY(Y).toFixed(1)}h0`; }
+ } else {
+ const e = Math.hypot(...a) > 1e-9 ? a : b;
+ if (Math.hypot(...e) > 1e-9) sp = clipDir([0, 0], e);
+ for (let i = -12; i <= 12; i++) for (let j = -12; j <= 12; j++) { const X = i * a[0] + j * b[0], Y = i * a[1] + j * b[1]; if (inBox(X, Y)) dd += `M${PX(X).toFixed(1)} ${PY(Y).toFixed(1)}h0`; }
+ }
+ att(L[0], d1); att(L[1], d2); att(dots, dd); att(span, sp);
+ };
+ sys.onChange(draw_); draw_(sys.v);
+ return { g, shade, L, dots, span };
+};
+// A pointer that rides on b's tip while the beat moves b ("drag b anywhere").
+const hand = sys => {
+ const { PX, PY } = sys.P, g = G(sys.P.g, { o: 0 });
+ g.style.pointerEvents = 'none';
+ path(g, 'M0 0L0 30L8 23L14 36L20 33L14 21L24 21Z', { fill: COL.chalk, stroke: COL.board, 'stroke-width': 2.5, 'stroke-linejoin': 'round' });
+ const upd = v => put(g, { x: PX(v.b0) + 6, y: PY(v.b1) + 6 });
+ sys.onChange(upd); upd(sys.v);
+ return g;
+};
+// A dashed trip on the plane: x·col 1 from the origin, then y·col 2, nudged sideways by off px so trips along one line stay apart.
+const trip = (sys, into, A, x, y, t0, off = 0) => {
+ const { PX, PY } = sys.P, c1 = [A[0][0], A[1][0]], c2 = [A[0][1], A[1][1]];
+ const L = Math.hypot(...c1) || 1, nx = -c1[1] / L * off, ny = -c1[0] / L * off; // screen normal (y is down)
+ const pt = (X, Y) => `${(PX(X) + nx).toFixed(1)} ${(PY(Y) + ny).toFixed(1)}`;
+ const m = [x * c1[0], x * c1[1]], e = [m[0] + y * c2[0], m[1] + y * c2[1]];
+ const legs = [];
+ if (x) legs.push(path(into, `M${pt(0, 0)}L${pt(...m)}`, { stroke: LS_COLS[0], 'stroke-width': 5, 'stroke-dasharray': '10 8', fill: 'none' }, { d: 0 }));
+ if (y) legs.push(path(into, `M${pt(...m)}L${pt(...e)}`, { stroke: LS_COLS[1], 'stroke-width': 5, 'stroke-dasharray': '10 8', fill: 'none' }, { d: 0 }));
+ legs.forEach((l, i) => draw(l, t0 + i * .7, .7));
+ return legs;
+};
+const hideCols = (sys, which, t0 = 0, dur = 0) => which.forEach(e => tw(e, { o: 0 }, t0, dur));
+
+/* ---------- 3D: the sheet of reachable points ---------- */
+const sheet = (V, d = 0, { fo = .13 } = {}) => {
+ const it = V.poly(S3_cut(...N3, d, V.R), { color: COL.task, fo, w: 2 });
+ it.at = dd => it.set(S3_cut(...N3, dd, V.R) || null);
+ return it;
+};
+const ring3 = (V, q, label, color = COL.task) => {
+ const d = V.point(q, { color, r: 15, label, size: 26 });
+ const c = d.e.firstChild; c.setAttribute('fill', 'none'); c.setAttribute('stroke', color); c.setAttribute('stroke-dasharray', '4 4'); c.setAttribute('stroke-width', 3);
+ return d;
+};
+const sys3 = (p, A, b, { t0 = .1, mixAt } = {}) => {
+ const sys = lin3(p, { A, b, eq: [90, 180], size: 44, mat: null, mix: [90, 450], mixAt, view: 'col', sol: false, space: { ...VIEW }, t0 });
+ sys.labels(['col 1', 'col 2', 'col 3', 'b']);
+ return sys;
+};
+
+/* ---------- bars: row labels beside a vector of bars ---------- */
+const rowNames = (p, bs, names, x, t0, colors = []) => names.map((n, i) => say(p, [n], x, bs.zeroY(i) + 12, t0 + i * .15, { size: 34, fill: colors[i] || COL.dim, anchor: 'end' }));
+// The equations of the 4 × 4 system written above the bars: each term over its own column of bars.
+const eqsAbove = (p, bs, A, b, y0, t0, { gap = 42, size = 32 } = {}) => A.map((row, i) => {
+ const g = G(p, { o: 0 }), y = y0 + i * gap;
+ row.forEach((a, j) => {
+ const x = bs.cols[j].bx, zero = a === 0;
+ if (j) T(g, '+', { x: st(bs.plusSigns[j - 1]).x, y, size, fill: COL.chalk, font: MATH, anchor: 'middle', o: zero ? .3 : 1 });
+ M(g, [(zero ? '0' : a === 1 ? '' : num(a)) + 'x' + SUB[j + 1]], { x, y, size, fill: COL.chalk, anchor: 'middle', o: zero ? .3 : 1 });
+ });
+ T(g, '=', { x: st(bs.eqs[0]).x, y, size, fill: COL.chalk, font: MATH, anchor: 'middle' });
+ T(g, num(b[i]), { x: bs.b.bx, y, size, fill: COL.task, font: MATH, anchor: 'middle' });
+ show(g, t0[i] ?? t0);
+ return g;
+});
+const barsFlash = (bs, keys, t0) => flash(keys.flatMap(k => bs.num(k)), t0);
+
+/* ---------- practice data ---------- */
+const FILLQ = [
+ { parts: [$m('[1, 0]'), ' and ', $m('[0, 1]')], ans: ['y'], why: 'Right and up: different directions. x·[1, 0] + y·[0, 1] = [x, y] is every point.' },
+ { parts: [$m('[2, 1]'), ' and ', $m('[4, 2]')], ans: ['n'], why: '[4, 2] is 2·[2, 1]: one line.' },
+ { parts: [$m('[1, 3]'), ' and ', $m('[3, 1]')], ans: ['y'], why: 'Neither is a multiple of the other: they point different ways.' },
+ { parts: [$m('[−1, 2]'), ' and ', $m('[2, −4]')], ans: ['n'], why: '[2, −4] is −2·[−1, 2]. A negative multiple still lies on the same line.' },
+ { parts: [$m('[0, 0]'), ' and ', $m('[1, 1]')], ans: ['n'], why: 'The zero column adds nothing: only the line of [1, 1].' },
+ { parts: [$m('[3, −1]'), ' and ', $m('[1, 2]')], ans: ['y'], why: 'Different directions: every b.' },
+];
+const FILL3Q = [
+ { parts: [$m('(1, 0, 0), (0, 1, 0), (0, 0, 1)')], ans: ['y'], why: 'Along x, along y, up z: x·… + y·… + z·… = (x, y, z) is every point.' },
+ { parts: [$m('(1, 0, 0), (0, 1, 0), (1, 1, 0)')], ans: ['n'], why: 'All three lie on the floor (bottom number 0). (1, 1, 0) is col 1 + col 2.' },
+ { parts: [$m('(1, 1, 0), (0, 1, 1), (1, 0, 1)')], ans: ['y'], why: 'No column is a mix of the other two; they fill space.' },
+ { parts: [$m('(1, 2, 3), (2, 4, 6), (0, 0, 1)')], ans: ['n'], why: 'Col 2 = 2·col 1. Two directions only: a plane.' },
+ { parts: [$m('(2, −1, 0), (−1, 2, −3), (1, 1, −3)')], ans: ['n'], why: 'Col 3 = col 1 + col 2: the flat sheet of this chapter.' },
+ { parts: [$m('(1, 0, 0), (1, 1, 0), (1, 1, 1)')], ans: ['y'], why: 'Only col 3 leaves the floor, and col 1, col 2 point different ways on it.' },
+];
+const REACH2Q = [
+ { parts: ['b = ', $m('[2, −2]')], ans: ['y'], why: '−2 = −2. b is 2·col 1.' },
+ { parts: ['b = ', $m('[−4, 4]')], ans: ['y'], why: '4 = −(−4). b is −4·col 1.' },
+ { parts: ['b = ', $m('[1, 1]')], ans: ['n'], why: 'The bottom must be minus the top: 1 is not −1.' },
+ { parts: ['b = ', $m('[0, 0]')], ans: ['y'], why: '0 = −0: the mix 0, 0 reaches it (and so do many others).' },
+ { parts: ['b = ', $m('[3, −2]')], ans: ['n'], why: '−2 is not −3.' },
+];
+const REACH3Q = [
+ { parts: ['floor columns, b = ', $m('(2, 3, 0)')], ans: ['y'], why: 'Bottom 0: on the floor. 2·col 1 + 3·col 2.' },
+ { parts: ['floor columns, b = ', $m('(0, 0, 1)')], ans: ['n'], why: 'Every mix has bottom 0; this b has bottom 1.' },
+ { parts: ['floor columns, b = ', $m('(−1, 4, 0)')], ans: ['y'], why: 'Bottom 0: −1·col 1 + 4·col 2.' },
+ { parts: ['sheet columns, b = ', $m('(3, 0, −3)')], ans: ['y'], why: '3 + 2·0 + (−3) = 0: on the sheet. 2·col 1 + col 2 reaches it.' },
+ { parts: ['sheet columns, b = ', $m('(0, −1, 4)')], ans: ['n'], why: '0 − 2 + 4 = 2, not 0: off the sheet.' },
+ { parts: ['sheet columns, b = ', $m('(1, 1, 1)')], ans: ['n'], why: '1 + 2 + 1 = 4, not 0.' },
+];
+const COMBQ = [
+ { parts: ['2·(1, 0, 3, −1) + (0, 2, −1, 4) = (', { box: '2' }, ', ', { box: '2' }, ', ', { box: '5' }, ', ', { box: '2' }, ')'], why: '(2, 0, 6, −2) + (0, 2, −1, 4) = (2, 2, 5, 2).', hint: 'Double the first: (2, 0, 6, −2). Then add number by number.' },
+ { parts: ['3·(1, −1, 0, 2) − (2, 0, 1, 1) = (', { box: '1' }, ', ', { box: '-3' }, ', ', { box: '-1' }, ', ', { box: '5' }, ')'], why: '(3, −3, 0, 6) − (2, 0, 1, 1) = (1, −3, −1, 5).', hint: 'Triple the first: (3, −3, 0, 6). Then take away (2, 0, 1, 1).' },
+ { parts: ['−(1, 2, 3, 4) + (4, 3, 2, 1) = (', { box: '3' }, ', ', { box: '1' }, ', ', { box: '-1' }, ', ', { box: '-3' }, ')'], why: '(−1, −2, −3, −4) + (4, 3, 2, 1) = (3, 1, −1, −3).', hint: 'The minus flips every sign: (−1, −2, −3, −4).' },
+];
+const MIX4Q = [
+ { parts: ['b = (2, 5, 4, 1): x₁, x₂, x₃, x₄ = ', { box: '2' }, ', ', { box: '3' }, ', ', { box: '1' }, ', ', { box: '0' }], why: 'x₁ = 2; 2 + x₂ = 5, x₂ = 3; 3 + x₃ = 4, x₃ = 1; 1 + x₄ = 1, x₄ = 0.', hint: 'Go from the top: x₁ is the first number of b. Then x₁ + x₂ must be the second.' },
+ { parts: ['b = (−1, 0, 2, 2): x₁, x₂, x₃, x₄ = ', { box: '-1' }, ', ', { box: '1' }, ', ', { box: '1' }, ', ', { box: '1' }], why: 'x₁ = −1; −1 + x₂ = 0, x₂ = 1; 1 + x₃ = 2, x₃ = 1; 1 + x₄ = 2, x₄ = 1.', hint: 'x₁ = −1. Then −1 + x₂ = 0.' },
+];
+const YN = [['y', 'Yes', COL.good, 'Y'], ['n', 'No', COL.bad, 'N']];
+
+/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */
+const BEATS = [
+ ['intro', 'Can we solve for every b?', (m, D) => {
+ const g = G(scene, { o: 0, y: 24 });
+ T(g, 'Unit 1, Chapter 14', { x: 800, y: 300, size: 28, fill: COL.dim, anchor: 'middle' });
+ T(g, 'Can We Solve for Every b?', { x: 800, y: 410, size: 84, weight: 600, anchor: 'middle' });
+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);
+ const r = text(scene, 'the big question of lecture 1: which targets can the columns reach?', 800, 530, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });
+ // two columns at a point; the target b hops, and each time a dashed mix of the columns follows it there
+ const k = 34, c1 = [2, -1], c2 = [-1, 2], lg = G(scene, { x: 800, y: 700, o: 0 });
+ const P_ = (x, y) => `${x * k} ${-y * k}`;
+ path(lg, `M0 0L${P_(...c1)}`, { stroke: LS_COLS[0], 'stroke-width': 6, 'stroke-linecap': 'round' });
+ path(lg, `M0 0L${P_(...c2)}`, { stroke: LS_COLS[1], 'stroke-width': 6, 'stroke-linecap': 'round' });
+ show(lg, m('sub') + 1, .6);
+ const dot = G(lg, { x: 0, y: -3 * k, o: 0 });
+ mk('circle', { r: 11, fill: COL.task, stroke: COL.board, 'stroke-width': 3 }, dot);
+ [[1, 2], [2, 1], [-2, -2]].forEach(([x, y], i) => {
+ const t = m('move') + .6 + i * 1.9, mid = [x * c1[0], x * c1[1]], end = [mid[0] + y * c2[0], mid[1] + y * c2[1]];
+ const leg = G(lg, { o: 0 });
+ path(leg, `M0 0L${P_(...mid)}`, { stroke: LS_COLS[0], 'stroke-width': 4, 'stroke-dasharray': '8 7', fill: 'none' });
+ path(leg, `M${P_(...mid)}L${P_(...end)}`, { stroke: LS_COLS[1], 'stroke-width': 4, 'stroke-dasharray': '8 7', fill: 'none' });
+ tw(dot, { x: end[0] * k, y: -end[1] * k, o: 1 }, t, .7);
+ show(leg, t + .6, .4); hide(leg, t + 1.6, .3);
+ });
+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(lg, D - .9, .8);
+ }],
+
+ ['ask', 'The big question', (m) => {
+ const p = S.p = panel(0);
+ text(p, 'Can we find a mix for every b?', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sys2(p, LA, [0, 3], { t0: m('eq') - .3 });
+ put(sys.COLV, { o: 0 }); show(sys.COLV, m('cols') + 1.5, .6);
+ S.cf = colForm2(sys, p, m('cols'));
+ flash([...sys.num('a00'), ...sys.num('a10')], m('cols') + 1.2); flash([...sys.num('a01'), ...sys.num('a11')], m('cols') + 3.4);
+ box(p, 114, 366, 124, 140, LS_COLS[0], m('cols') + 1.2, m('cols') + 3.2); box(p, 396, 366, 124, 140, LS_COLS[1], m('cols') + 3.4, m('cols') + 5.4);
+ box(p, 566, 366, 124, 140, COL.task, m('cols') + 5.6, m('mix'));
+ S.out = mixOut(sys, p, m('mix'));
+ thick(sys.combo[0], m('mix') + 1.5, 4); thick(sys.combo[1], m('mix') + 2.3, 4);
+ // "until now": one b at a time; "now": every point of the plane
+ const one = text(p, 'until now: one b → find its mix', 90, 650, m('flip'), { size: 30, fill: COL.dim });
+ const all = text(p, 'now: every b → is there always a mix?', 90, 700, m('big'), { size: 32, fill: COL.task, weight: 600 });
+ const { PX, PY } = sys.P, qs = G(p, {});
+ [[-4, 3], [3, 4], [5, -2], [-2, -5], [1, -1], [-5, 0], [4, 1], [-1, 5], [2, -4]].forEach(([x, y], i) => {
+ const d = G(qs, { x: PX(x), y: PY(y), o: 0, s: .4 });
+ mk('circle', { r: 9, fill: 'none', stroke: COL.task, 'stroke-width': 3 }, d);
+ tw(d, { o: .9, s: 1 }, m('big') + 2.5 + i * .25, .4, back);
+ });
+ hide(qs, m('try') - .3, .4);
+ [['b1', 3, 0], ['b2', -2, -2], ['b3', 1, 0]].forEach(([k, b0, b1]) => {
+ sys.to({ b0, b1 }, m(k), 1.3);
+ flash([...sys.num('b0'), ...sys.num('b1'), ...S.cf.num('b0'), ...S.cf.num('b1')], m(k) + .2);
+ });
+ S.notes = [one, all];
+ }],
+
+ ['lattice', 'Why every b works', (m) => {
+ const p = S.p, sys = S.sys;
+ S.notes.forEach(e => hide(e, .1, .4));
+ const lat = lattice2(sys);
+ show(lat.dots, m('dots'), .8);
+ show(lat.L[0], m('grid') + .6, .6); show(lat.L[1], m('grid') + 2.2, .6);
+ show(lat.shade, m('fill'), 1.2);
+ text(p, 'whole mixes: a slanted grid; fractions fill the gaps', 90, 650, m('grid'), { size: 28, fill: COL.dim });
+ const h = hand(sys);
+ show(h, m('drag'), .3); hide(h, m('ans') - .2, .3);
+ // b roams; the mix follows (colour form, readout and the dashed legs); in the row picture the crossing follows
+ const pts = [[4, 3], [-3, 4], [-5, -2], [2, -5], [5, 1], [-2, 2], [1, -3], [0, 3]];
+ const trails = [];
+ let t = m('drag') + .2, k = 0;
+ while (t + 1.4 < m('ans') - .2 && k < pts.length) {
+ const inRow = t >= m('rows') - .1;
+ const tr = sys.to({ b0: pts[k][0], b1: pts[k][1] }, t, 1.4, io, { trail: inRow });
+ if (tr) trails.push(tr);
+ t += 1.75; k++;
+ }
+ sys.view('row', m('rows')); sys.view('col', m('ans'));
+ hide(lat.g, m('rows'), .4); show(lat.g, m('ans'), .4);
+ trails.forEach(tr => hide(tr, m('ans'), .4));
+ text(p, 'every b: exactly one mix', 90, 710, m('ans') + .4, { size: 34, fill: COL.good, weight: 600 });
+ }],
+
+ ['q1', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sys2(p, LA, [0, 3]);
+ colForm2(sys, p, .3); mixOut(sys, p, .4);
+ const lat = lattice2(sys);
+ [...lat.L, lat.dots].forEach(e => show(e, .4, .5));
+ }, { ask: done => quiz(CARD, [{
+ id: 'c-mix', prompt: ['Move ', $m('b'), ' until the mix is ', $m('x = 1'), ', ', $m('y = −1'), '.'],
+ build: lsTask(S.sys, (v, s) => s.x !== undefined && Math.abs(s.x - 1) < 1e-9 && Math.abs(s.y + 1) < 1e-9,
+ 'b = 1·(2, −1) − 1·(−1, 2) = (3, −3). One step along column 1, one step back along column 2.',
+ 'Start at the tip of column 1, (2, −1). Then take column 2 away: go back by (−1, 2).',
+ () => S.sys.set({ b0: 3, b1: -3 }), { only: ['b0', 'b1'] }),
+ }], done) }],
+
+ ['parallel', 'Columns on one line', (m) => {
+ const p = S.p = panel(0);
+ text(p, 'When the columns line up', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sys2(p, PAR0, [0, 0]);
+ S.cf = colForm2(sys, p, .4);
+ const lat = S.lat = lattice2(sys);
+ [...lat.L, lat.dots].forEach(e => show(e, .5, .6)); show(lat.shade, m('c2') + 2.4, .8);
+ hide(lat.shade, m('squash'), 2.4);
+ show(lat.span, m('par') - .2, .5);
+ hideCols(sys, [sys.bArrow, sys.combo[0], sys.combo[1]]);
+ sys.labels(['col 1', 'col 2', '']); prog(() => sys.labels(['col 1', 'col 2', 'b']), m('b') + .4, 0);
+ thick(sys.cols[0], m('c1')); flash([...S.cf.num('a00'), ...S.cf.num('a10')], m('c1'));
+ thick(sys.cols[1], m('c2')); flash([...S.cf.num('a01'), ...S.cf.num('a11')], m('c2'));
+ sys.to({ a01: 2, a11: 4 }, m('turn') + .2, m('par') - m('turn'), io);
+ flash([...S.cf.num('a01'), ...S.cf.num('a11'), ...sys.num('a01'), ...sys.num('a11')], m('par'));
+ thick(lat.span, m('line'), 7);
+ // why: the bottom of any mix is twice its top
+ const why = G(p, {});
+ say(why, ['top: x + 2y'], 90, 600, m('top'), { size: 36, fill: COL.chalk });
+ say(why, ['bottom: 2x + 4y = 2·(x + 2y)'], 90, 655, m('bot'), { size: 36, fill: COL.chalk });
+ const rule = S.rule = text(p, 'bottom = 2 × top, whatever the mix', 90, 715, m('rule'), { size: 32, fill: COL.task, weight: 600 });
+ box(p, 114, 366, 124, 140, LS_COLS[0], m('why'), m('why') + 3); box(p, 396, 366, 124, 140, LS_COLS[1], m('why') + .4, m('why') + 3.4);
+ // b = (3, 5): off the line
+ show(sys.bArrow, m('b'), .3);
+ sys.to({ b0: 3, b1: 5 }, m('b'), 1.3);
+ S.out = mixOut(sys, p, m('b') + 1.4);
+ const { PX, PY } = sys.P, ring = G(sys.P.g, { x: PX(3), y: PY(5), o: 0 });
+ mk('circle', { r: 16, fill: 'none', stroke: COL.bad, 'stroke-width': 3.5 }, ring);
+ show(ring, m('off'), .3); pulse(ring, m('off') + .4, 1.5);
+ const offT = text(p, '5 ≠ 2 · 3: b is off the line', 90, 775, m('off') + .4, { size: 30, fill: COL.bad, weight: 600 });
+ hide(why, m('rowp') - .3, .3);
+ sys.view('row', m('rowp')); hide(lat.g, m('rowp'), .4); hide(ring, m('rowp'), .3);
+ flash([...sys.num('b0'), ...sys.num('b1')], m('rowp') + 1.5);
+ sys.focus(0, m('rowp') + 1.6); sys.focus(1, m('rowp') + 4.4); sys.focus(null, m('parl'));
+ sys.lines.forEach((l, i) => thick(l.l, m('parl') + i * .5));
+ const parT = text(p, 'parallel lines: no solution', 90, 600, m('parl'), { size: 32, fill: COL.bad, weight: 600 });
+ S.drop = [offT, parT, ring];
+ }],
+
+ ['many', 'Endlessly many mixes', (m) => {
+ const p = S.p, sys = S.sys, lat = S.lat;
+ S.drop.forEach(e => hide(e, .1, .3));
+ sys.view('col', .1); show(lat.g, .1, .4);
+ // the second line is dashed when both equations make one line, so both colours show
+ sys.onChange((v, s) => sys.lines[1].l.setAttribute('stroke-dasharray', s.many ? '14 12' : ''));
+ sys.to({ b0: 2, b1: 4 }, m('b'), 1.3);
+ flash([...sys.num('b0'), ...sys.num('b1'), ...S.cf.num('b0'), ...S.cf.num('b1')], m('b') + .3);
+ const onT = text(p, '4 = 2 · 2: b is on the line', 90, 775, m('b') + 1.6, { size: 30, fill: COL.good, weight: 600 });
+ const trips = G(sys.P.g, {});
+ const mixes = [['on', 2, 0, 12], ['m2', 0, 1, -12], ['m3', -2, 2, 0]];
+ mixes.forEach(([k, x, y, off], i) => {
+ trip(sys, trips, PAR, x, y, m(k) + .2, off);
+ say(p, [`x = ${num(x)}, y = ${num(y)}`], 90, 625 + i * 48, m(k), { size: 34, fill: COL.task });
+ });
+ hide(S.rule, .1, .3);
+ sys.view('row', m('rowp')); hide(lat.g, m('rowp'), .4); hide(trips, m('rowp'), .4);
+ const sameT = text(p, 'the same line: every point on it solves both', 760, 860, m('same'), { size: 26, fill: COL.task, weight: 600, anchor: 'middle' });
+ hide(onT, m('sum') - .3, .3);
+ const sum = G(p, { o: 0 });
+ T(sum, 'columns on one line:', { x: 90, y: 790, size: 28, fill: COL.dim });
+ T(sum, 'b off the line → no mix; b on the line → endlessly many', { x: 90, y: 835, size: 28, fill: COL.task, weight: 600 });
+ show(sum, m('sum'), .5); hide(sameT, m('sum'), .3);
+ sys.view('col', m('sum')); show(lat.g, m('sum'), .4);
+ sys.to({ b0: 3, b1: 5 }, m('sum') + 1.4, 1.1); sys.to({ b0: 2, b1: 4 }, m('sum') + 5.4, 1.1);
+ }],
+
+ ['q2', 'Quick check', () => {
+ const p = panel(0);
+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sys2(p, PAR, [0, 0]);
+ sys.E.style.display = 'none';
+ sys.labels(['col 1', 'col 2', '']);
+ hideCols(sys, [sys.bArrow, sys.combo[0], sys.combo[1], sys.ROWV]);
+ const lat = lattice2(sys);
+ [lat.span, lat.dots].forEach(e => show(e, .4, .5));
+ }, { ask: done => quiz({ x: 40, y: 150, w: 720, cls: 'side' }, [{
+ id: 'c-reach', prompt: ['Columns ', $m('(1, 2)'), ' and ', $m('(2, 4)'), '. Can a mix reach this b?'],
+ build: grid([['3, 6', true], ['1, 3', false], ['−2, −4', true], ['0, 0', true], ['4, 2', false]].map(([s, ok]) => ({
+ parts: ['b = ', $m(`(${s})`)], ans: [ok ? 'y' : 'n'],
+ why: ok ? `The bottom is twice the top: on the line.` : `The bottom is not twice the top: off the line.`,
+ fx: () => { const [x, y] = s.split(', ').map(z => +z.replace('−', '-')); S.sys.P.dot(x, y, ok ? COL.good : COL.bad, 0, { run: fx, into: qlayer(), label: `(${s})` }); },
+ })), YN, { multi: false, text: true }),
+ }], done) }],
+
+ ['sheet', 'Three columns fill space', (m) => {
+ const p = S.p = panel(0);
+ text(p, 'Three columns in space', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sys3(p, LEC3, [0, -1, 4], { t0: m('sys') - .3, mixAt: false }), V = sys.space;
+ V.sway(5, 16);
+ const ask = text(p, 'every b in space?', 90, 680, m('ask'), { size: 32, fill: COL.task, weight: 600 });
+ hide(ask, m('s12') - .3, .3);
+ // b and column 3 wait; the sheet of col 1 and col 2 first
+ [sys.bArrow.e, sys.tipLabels[3], ...sys.combo.map(c => c.e)].forEach(e => put(e, { o: 0 }));
+ put(sys.cols[2].e, { o: .2 }); put(sys.tipLabels[2], { o: .2 });
+ const sh = S.sheet = sheet(V, 0);
+ put(sh.e, { o: 0 }); show(sh.e, m('s12'), .8);
+ thick(sys.cols[0].e, m('s12') + 1.5); thick(sys.cols[1].e, m('s12') + 2.3);
+ const n1 = text(p, 'mixes of col 1 and col 2: a flat sheet', 90, 680, m('s12') + 1, { size: 30, fill: COL.task, weight: 600 });
+ tw(sys.cols[2].e, { o: 1 }, m('c3'), .4); tw(sys.tipLabels[2], { o: 1 }, m('c3'), .4); thick(sys.cols[2].e, m('c3') + .3);
+ hide(n1, m('z1') - .2, .3);
+ // z lifts the sheet: it passes through b = z·col 3 (the mix 0, 0, z)
+ show(sys.CF, m('z1'), .5); show(sys.bArrow.e, m('z1') + .2, .4); show(sys.tipLabels[3], m('z1') + .4, .4);
+ prog(q => sh.at(2 * q), m('z1') + .2, 1.4);
+ const zT = T(p, '', { x: 90, y: 680, size: 32, fill: COL.task, font: MATH, weight: 600, o: 0 });
+ const zSet = z => { const s = `z = ${fmt1(z)}: the sheet moves to z·col 3`; if (zT.textContent !== s) zT.textContent = s; };
+ prog(q => zSet(q), m('z1') + .2, 1.4); show(zT, m('z1') + .2, .3);
+ sys.to({ x2: -1 }, m('zneg'), 1.4); prog(q => { sh.at(2 - 4 * q); zSet(1 - 2 * q); }, m('zneg'), 1.4);
+ // the sweep: b waits, the sheet runs from far below to far above
+ [sys.bArrow.e, sys.tipLabels[3], sys.CF, ...sys.combo.map(c => c.e)].forEach(e => hide(e, m('sweep') - .2, .3));
+ const sw = m('any') - m('sweep') - .4;
+ prog(q => { const z = -1 - 7 * Math.min(1, q * 4) + 16 * Math.max(0, q * 4 - 1) / 3; sh.at(2 * z); zSet(z); }, m('sweep'), sw, lin);
+ hide(zT, m('any') - .2, .3);
+ // every b sits on one sheet: b roams, the mix follows, the sheet through b follows
+ sys.onChange(v => { if (st(sys.CF).o > .01) sh.at(N3[0] * v.b0 + N3[1] * v.b1 + N3[2] * v.b2); });
+ sys.to({ b0: 1, b1: 0, b2: 1 }, m('any') - .1, .01); prog(() => sh.at(2), m('any'), 0);
+ tw(sh.e, { o: .25 }, m('any'), .4);
+ [sys.bArrow.e, sys.tipLabels[3], sys.CF, ...sys.combo.map(c => c.e)].forEach(e => show(e, m('any'), .4));
+ text(p, 'every b lies on one of the sheets: it has a mix', 90, 680, m('any') + .3, { size: 30, fill: COL.good, weight: 600 });
+ [[3, 0, -3], [-1, 1, 1], [2, 0, -4]].forEach((b, i) => {
+ sys.to({ b0: b[0], b1: b[1], b2: b[2] }, m('drag') + .1 + i * 1.3, 1.1);
+ flash(['x0', 'x1', 'x2'].flatMap(k => sys.num(k)), m('drag') + 1 + i * 1.3);
+ });
+ }],
+
+ ['flat', 'Three columns in one sheet', (m) => {
+ const p = panel(0);
+ text(p, 'When the three columns lie flat', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sys3(p, LEC3, [0, -1, 4]), V = sys.space; // mix 0, 0, 1: b is column 3, and rides with it
+ V.sway(5, 16);
+ const sh = sheet(V, 2); // through column 3's tip; it comes down with column 3
+ sys.onChange(v => sh.at(N3[0] * v.b0 + N3[1] * v.b1 + N3[2] * v.b2));
+ sys.to({ a02: 1, a12: 1, a22: -3 }, m('fall'), 2.2);
+ flash(['a02', 'a12', 'a22'].flatMap(k => sys.num(k)), m('now'));
+ const sum = say(p, ['col 3 = (2, −1, 0) + (−1, 2, −3) = (1, 1, −3)'], 90, 660, m('sum'), { size: 32, fill: S3_COLS[2] });
+ const stuck = text(p, 'every mix stays in the sheet', 90, 710, m('stuck'), { size: 30, fill: COL.task, weight: 600 });
+ hide(sum, m('test') - .3, .3); hide(stuck, m('test') - .3, .3);
+ // the test: top + 2·middle + bottom of A x, live
+ const tg = G(p, { o: 0 });
+ T(tg, 'top + 2·middle + bottom:', { x: 90, y: 660, size: 28, fill: COL.dim });
+ const tv = T(tg, '', { x: 90, y: 712, size: 36, fill: COL.task, font: MATH, weight: 600 });
+ const tst = v => { const s = `${fmt1(v.b0)} + 2·(${fmt1(v.b1)}) + (${fmt1(v.b2)}) = ${fmt1(v.b0 + 2 * v.b1 + v.b2)}`; if (tv.textContent !== s) tv.textContent = s; };
+ sys.onChange(tst); tst(sys.v);
+ show(tg, m('test') + .5, .4);
+ prog(() => sys.labels(['col 1', 'col 2', 'col 3', 'A x']), m('scrub'), 0);
+ [[1, 1, 0], [2, 0, -1], [0, -1, 1], [1, 1, 0]].forEach(([a, b, c], i) => {
+ sys.to({ x0: a, x1: b, x2: c }, m('scrub') + .3 + i * 1.5, 1.2);
+ flash(['x0', 'x1', 'x2'].flatMap(k => sys.num(k)), m('scrub') + .3 + i * 1.5);
+ });
+ pulse(tv, m('zero'), 1.3);
+ // the old target: off the sheet
+ const ring = ring3(V, [0, -1, 4], 'b');
+ put(ring.e, { o: 0 }); show(ring.e, m('old'), .4);
+ const calc = say(p, ['0 + 2·(−1) + 4 = 2 ≠ 0'], 90, 770, m('calc'), { size: 34, fill: COL.bad });
+ pulse(ring.e.firstChild, m('off'), 1.5);
+ const offT = text(p, 'b is off the sheet: no mix reaches it', 90, 820, m('off') + .3, { size: 30, fill: COL.bad, weight: 600 });
+ // the row picture of the same system with this b: three planes, no common point
+ [sys.CF, tg, calc, offT, ring.e, sh.e].forEach(e => hide(e, m('rows') - .2, .3));
+ sys.to({ b0: 0, b1: -1, b2: 4 }, m('rows'), .01);
+ sys.view('row', m('rows'));
+ text(p, 'three planes, no point in common', 90, 680, m('rows') + .6, { size: 32, fill: COL.bad, weight: 600 });
+ }],
+
+ ['q3', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = lin3(p, { A: FLAT3, b: [2, -1, 0], eq: [90, 180], size: 44, mat: null, mix: [90, 450], view: 'col', sol: false, space: { ...VIEW } });
+ sys.labels(['col 1', 'col 2', 'col 3', 'A x']);
+ sys.set({ x0: 1, x1: 0, x2: 0 });
+ sheet(sys.space, 0);
+ ring3(sys.space, [3, 0, -3], '(3, 0, −3)');
+ }, { ask: done => quiz({ x: 40, y: 615, w: 720, cls: 'side' }, [{
+ id: 'c-flat', prompt: ['Change the mix until ', $m('A x'), ' lands on the ring ', $m('(3, 0, −3)'), '.'],
+ build: lin3Task(S.sys, v => [v.b0 - 3, v.b1, v.b2 + 3].every(d => Math.abs(d) < 1e-9),
+ 'For example 2·col 1 + 1·col 2 = (4 − 1, −2 + 2, 0 − 3) = (3, 0, −3), or col 1 + col 3. Column 3 is col 1 + col 2, so many mixes land on the same point.',
+ 'Try x = 2: that gives (4, −2, 0). What must you add to reach (3, 0, −3)? Look at column 2.',
+ () => S.sys.set({ x0: 2, x1: 1, x2: 0 }), ['x0', 'x1', 'x2']),
+ }], done) }],
+
+ ['bars', 'Numbers as bars', (m) => {
+ const p = panel(0);
+ text(p, 'More numbers than axes', 60, 110, .2, { size: 40, weight: 600 });
+ // 2D: b as an arrow (with its x and y steps) and as two bars, one state
+ const g2 = G(p, {}), P2 = plane(g2, { cx: 1160, cy: 450, u: 52, t0: m('two') - .3 });
+ const bs2 = bars(g2, { b: [3, 2], x0: 330, top: 250, band: 170, unit: 18, bw: 60, size: 40, t0: m('bars') });
+ rowNames(g2, bs2, ['x', 'y'], 300, m('bars') + .3, AXC);
+ const legX = path(g2, '', { stroke: AXC[0], 'stroke-width': 4, 'stroke-dasharray': '8 7', fill: 'none' });
+ const legY = path(g2, '', { stroke: AXC[1], 'stroke-width': 4, 'stroke-dasharray': '8 7', fill: 'none' });
+ const arr = path(g2, '', { stroke: COL.task, fill: COL.task, 'stroke-width': 6, 'stroke-linejoin': 'round' });
+ const tipT = T(g2, 'b', { size: 30, fill: COL.task, font: MATH, weight: 600 });
+ tipT.setAttribute('font-style', 'italic');
+ const hand2 = G(g2, { o: 0 });
+ path(hand2, 'M0 0L0 30L8 23L14 36L20 33L14 21L24 21Z', { fill: COL.chalk, stroke: COL.board, 'stroke-width': 2.5 });
+ const draw2 = v => {
+ const X = P2.PX(v.b0), Y = P2.PY(v.b1), O = [P2.PX(0), P2.PY(0)], L = Math.hypot(X - O[0], Y - O[1]) || 1, ux = (X - O[0]) / L, uy = (Y - O[1]) / L;
+ legX.setAttribute('d', `M${O[0]} ${O[1]}H${X.toFixed(1)}`); legY.setAttribute('d', `M${X.toFixed(1)} ${O[1]}V${Y.toFixed(1)}`);
+ arr.setAttribute('d', L < 2 ? '' : `M${O[0]} ${O[1]}L${(X - ux * 11).toFixed(1)} ${(Y - uy * 11).toFixed(1)}M${(X - 18 * ux - 9 * uy).toFixed(1)} ${(Y - 18 * uy + 9 * ux).toFixed(1)}L${X.toFixed(1)} ${Y.toFixed(1)}L${(X - 18 * ux + 9 * uy).toFixed(1)} ${(Y - 18 * uy - 9 * ux).toFixed(1)}Z`);
+ put(tipT, { x: X + ux * 22 - 8, y: Y + uy * 22 + 10 }); put(hand2, { x: X + 6, y: Y + 6 });
+ };
+ bs2.onChange(draw2); draw2(bs2.v);
+ [legX, legY, arr, tipT].forEach(e => { put(e, { o: 0 }); show(e, m('two') + .2, .5); });
+ show(hand2, m('drag'), .3); hide(hand2, m('three') - .6, .3);
+ bs2.to({ b0: -2 }, m('bars') + 2.6, 1); bs2.to({ b0: 3 }, m('bars') + 4.6, 1);
+ bs2.to({ b0: -2, b1: 4 }, m('drag') + .2, 1.3); bs2.to({ b0: 4, b1: -3 }, m('follow') + 1, 1.3); bs2.to({ b0: 3, b1: 2 }, m('follow') + 2.6, 1.1);
+ barsFlash(bs2, ['b0', 'b1'], m('follow'));
+ hide(g2, m('three') - .4, .4);
+ // 3D: three numbers, three steps, three bars
+ const g3 = G(p, { o: 0 });
+ show(g3, m('three') - .1, .4);
+ const V = space3(g3, { ...VIEW, t0: m('three') }), O3 = [0, 0, 0];
+ V.sway(5, 14);
+ const legs = AXC.map(c => { const l = V.line(null, null, { color: c, w: 4, dash: '8 7' }); return l; });
+ const arr3 = V.arrow(O3, [3, 2, 2], { color: COL.task, w: 6 });
+ const bs3 = bars(g3, { b: [3, 2, 2], x0: 330, top: 230, band: 140, unit: 15, bw: 60, size: 40, t0: m('three') + .3 });
+ rowNames(g3, bs3, ['x', 'y', 'z'], 300, m('three') + .5, AXC);
+ const draw3 = v => { const b = [v.b0, v.b1, v.b2]; legs[0].set(O3, [b[0], 0, 0]); legs[1].set([b[0], 0, 0], [b[0], b[1], 0]); legs[2].set([b[0], b[1], 0], b); arr3.set(O3, b); };
+ bs3.onChange(draw3); draw3(bs3.v);
+ bs3.to({ b0: -2, b1: 1, b2: 3 }, m('three') + 1.8, 1.4);
+ // a fourth axis has nowhere to go
+ const ax4 = V.line([0, 0, 0], [-3, -3, 3.5], { color: COL.chalk, w: 3, dash: '6 8' });
+ put(ax4.e, { o: 0 }); show(ax4.e, m('four') + .3, .4);
+ const q4 = text(g3, '4th axis?', 1150, 140, m('four') + .6, { size: 30, fill: COL.chalk, anchor: 'middle', weight: 600 });
+ const no = text(g3, 'no room: every direction here is already a mix of x, y and z', 1150, 860, m('no'), { size: 26, fill: COL.bad, anchor: 'middle', weight: 600 });
+ hide(g3, m('fourb') - .4, .4);
+ // four numbers: four bars
+ const g4 = G(p, { o: 0 });
+ show(g4, m('fourb'), .3);
+ const bs4 = bars(g4, { b: [3, -1, 2, 0], x0: 720, top: 220, band: 130, unit: 14, bw: 60, size: 40, t0: m('fourb') });
+ rowNames(g4, bs4, ['1st', '2nd', '3rd', '4th'], 690, m('fourb') + .2);
+ bs4.to({ b0: 1, b1: 2, b2: -2, b3: 3 }, m('fourb') + 1.4, 1.2);
+ S.keep = [q4, no];
+ }],
+
+ ['four', 'Four equations, four unknowns', (m) => {
+ const p = S.p = panel(0);
+ text(p, 'Four equations, four unknowns', 60, 110, .2, { size: 40, weight: 600 });
+ const bs = S.bs = bars(p, { A: BID, b: [1, 3, 4, 2], x0: 110, top: 360, band: 100, unit: 10, bw: 30, size: 30, t0: .1 });
+ // the parts appear on their words
+ [...bs.cols.map(c => c.g), ...bs.mixG, ...bs.plusSigns, bs.eqSign, bs.ax.g, ...bs.eqs, bs.b.g, bs.zeros].forEach(e => put(e, { o: 0 }));
+ [1, 2, 3, 4].forEach(j => hide(say(p, ['x' + SUB[j]], 500 + j * 120, 250, m('names') + .6 + j * .9, { size: 56, anchor: 'middle', fill: BR_COLS[j - 1] }), m('e1') - .3, .3));
+ eqsAbove(p, bs, BID, [1, 3, 4, 2], 175, ['e1', 'e2', 'e3', 'e4'].map(k => m(k)));
+ show(bs.zeros, m('cols'), .5);
+ box(p, bs.cols[0].bx - 52, 140, 104, 170, LS_COLS[0], m('c1'), m('call') + 1);
+ show(bs.cols[0].g, m('asbars'), .6);
+ [1, 2, 3].forEach(j => { show(bs.cols[j].g, m('call') + (j - 1) * .5, .5); show(bs.plusSigns[j - 1], m('call') + (j - 1) * .5, .4); });
+ box(p, bs.b.bx - 48, 140, 96, 170, COL.task, m('b'), m('b') + 2.5);
+ show(bs.b.g, m('b') + .3, .5);
+ bs.mixG.forEach((g, j) => show(g, m('mix') + j * .3, .4));
+ show(bs.eqSign, m('ax'), .4); show(bs.ax.g, m('ax'), .6); bs.eqs.forEach((e, i) => show(e, m('ax') + 2 + i * .2, .3));
+ flash(bs.b.rows.map(r => r.s.t), m('ax') + 3.2);
+ }],
+
+ ['match', 'Matching b, row by row', (m) => {
+ const p = S.p, bs = S.bs;
+ [['x1', 'x0', 1, 'x1b', ['a00', 'a10']], ['x2v', 'x1', 2, 'x2b', ['a11', 'a21']], ['x3v', 'x2', 2, 'x3b', ['a22', 'a32']]].forEach(([k, key, val, kb, cells]) => {
+ bs.to({ [key]: val }, m(k), 1);
+ barsFlash(bs, [key], m(k));
+ barsFlash(bs, cells, m(kb));
+ });
+ const glow = (rows, t, color = COL.task, dur = 1.6) => rows.forEach(i => {
+ const r = mk('rect', { x: 96, y: bs.zeroY(i) - 50, width: 1430, height: 100, rx: 10, fill: color, 'fill-opacity': .1, stroke: color, 'stroke-opacity': .5, 'stroke-width': 2 }, p);
+ put(r, { o: 0 }); show(r, t, .3); hide(r, t + dur, .4);
+ });
+ glow([0, 1, 2, 3], m('zero') + .4, COL.chalk, 2.4);
+ glow([0, 1], m('x1b')); glow([1], m('x2'), COL.nat, 2.6); glow([1, 2], m('x2b')); glow([2], m('x3'), COL.int, 2.4); glow([2, 3], m('x3b'));
+ glow([3], m('x4'), COL.chalk, 3); glow([0, 1, 2, 3], m('all'), COL.good, 3);
+ pulse(bs.eqs[0], m('top'), 1.6);
+ pulse(bs.eqs[1], m('two'), 1.6);
+ pulse(bs.eqs[2], m('x3b') + .6, 1.6); pulse(bs.eqs[3], m('x3b') + 1.2, 1.6);
+ barsFlash(bs, ['x3'], m('x4') + 2);
+ const all = G(p, { o: 0 });
+ M(all, ['A x = b, mix (1, 2, 2, 0)'], { x: 800, y: 858, size: 38, fill: COL.good, anchor: 'middle' });
+ show(all, m('all'), .5); hide(all, m('row') - .3, .3);
+ const zy = bs.zeroY(1);
+ box(p, 96, zy - 50, 1430, 100, COL.nat, m('row'));
+ box(p, 96, 175 + 42 - 34, 1430, 46, COL.nat, m('row'));
+ say(p, ['row 2: x₁ + x₂ = 1 + 2 = 3'], 800, 858, m('row') + .5, { size: 34, fill: COL.nat, anchor: 'middle' });
+ }],
+
+ ['q4', 'Your turn', () => {
+ const p = panel(0);
+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });
+ S.sys = bars(p, { A: BID, b: [2, 1, 2, 4], x0: 110, top: 190, band: 100, unit: 10, bw: 30, size: 30 });
+ }, { ask: done => quiz(BAND, [{
+ id: 'c-bars', prompt: ['Change the amounts ', $m('x₁'), ' to ', $m('x₄'), ' until every bar of ', $m('A x'), ' matches ', $m('b'), '.'],
+ build: barsTask(S.sys, (v, ax, ok) => ok, 'x₁ = 2, x₂ = −1, x₃ = 3, x₄ = 1: (2, 2 − 1, −1 + 3, 3 + 1) = (2, 1, 2, 4).',
+ (v, ax) => `Go row by row from the top. Row 1 is x₁ alone: it must be ${num(2)}. Then row 2 is x₁ + x₂.`,
+ () => S.sys.set({ x0: 2, x1: -1, x2: 3, x3: 1 }), { only: ['x0', 'x1', 'x2', 'x3'] }),
+ }], done) }],
+
+ ['nine', 'Nine equations', (m) => {
+ const p = panel(0);
+ text(p, 'Nine equations, nine unknowns', 60, 110, .2, { size: 40, weight: 600 });
+ const A9 = Array.from({ length: 9 }, (_, i) => Array.from({ length: 9 }, (_, j) => +(j === i || j === i - 1)));
+ const x9 = [1, 1, -1, 2, 0, -2, 1, 1, -1], b9 = A9.map(r => r.reduce((s, a, j) => s + a * x9[j], 0));
+ const names = Array(9).fill(''); names.push('A x', 'b');
+ const bs = bars(p, { A: A9, b: b9, x0: 50, top: 180, band: 62, unit: 8, bw: 18, size: 22, numbers: false, mw: 50, gap: 18, names, t0: m('nine') - .3 });
+ put(bs.ax.g, { o: 0 }); bs.eqs.forEach(e => put(e, { o: 0 }));
+ show(bs.ax.g, m('same'), .5); bs.eqs.forEach(e => show(e, m('same') + .3, .3));
+ const span = m('match') - m('move') + 1.2;
+ x9.forEach((x, j) => bs.to({ [`x${j}`]: x }, m('move') + j * span / 9, .55));
+ const cant = text(p, 'nine axes: we can’t draw them. nine numbers: we can compute, and watch them move.', 800, 855, m('cant'), { size: 28, fill: COL.task, anchor: 'middle', weight: 600 });
+ hide(cant, m('q') - .3, .3);
+ text(p, 'every b? yes, when each column brings a new direction', 800, 855, m('yes'), { size: 28, fill: COL.good, anchor: 'middle', weight: 600 });
+ // keep the bars alive while the voice talks: the amounts step back and land again
+ x9.forEach((x, j) => { bs.to({ [`x${j}`]: 0 }, m('cant') + 1.5 + j * .15, .5); bs.to({ [`x${j}`]: x }, m('q') + .4 + j * .35, .6); });
+ bs.eqs.forEach((e, i) => pulse(e, m('yes') + .3 + i * .12, 1.5));
+ }],
+
+ ['unit', 'Unit 1 in one picture', (m) => {
+ const p = panel(0);
+ text(p, 'Unit 1: one system, three views', 60, 110, .2, { size: 40, weight: 600 });
+ const row = linsys(p, { A: LA, b: [0, 3], eq: [610, 200], size: 44, mat: null, sol: false, view: 'row', plane: { cx: 300, cy: 560, u: 24, step: 2 }, t0: m('sys') - .3 });
+ const col = linsys(p, { A: LA, b: [0, 3], eq: [610, 200], size: 44, mat: null, sol: false, view: 'col', plane: { cx: 800, cy: 560, u: 24, step: 2 }, t0: m('col') });
+ col.E.style.display = 'none';
+ put(row.stage, { o: 0 }); show(row.stage, m('row'), .5);
+ col.labels(['col 1', 'col 2', 'b']);
+ const mat = linsys(p, { A: LA, b: [0, 3], eq: [610, 200], size: 44, mat: [1090, 500], sol: false, hidePlane: true, t0: m('ax') - .4 });
+ mat.E.style.display = 'none';
+ const head = (s, x, t) => text(p, s, x, 770, t, { size: 28, fill: COL.dim, anchor: 'middle', weight: 600 });
+ head('row picture: lines meet', 300, m('row') + .5); head('column picture: a mix makes b', 800, m('col') + .5); head('A x = b', 1330, m('ax'));
+ row.lines.forEach((l, i) => thick(l.l, m('row') + 1.5 + i * .8));
+ thick(col.combo[0], m('col') + 2.5, 4); thick(col.combo[1], m('col') + 3.3, 4); thick(col.bArrow, m('col') + 4.6, 6);
+ col.to({ a01: 4, a11: -2 }, m('no') + .8, 1.6); // they lie flat: b = (0, 3) is out of reach
+ thick(col.bArrow, m('no') + 3.2, 6);
+ prog(() => col.labels(['', 'col 2', 'b']), m('no') + .8, 0); prog(() => col.labels(['col 1', 'col 2', 'b']), m('next') + 1.2, 0);
+ col.to({ b0: -4, b1: 2 }, m('no') + 5.6, 1.2); // a b on their line: endlessly many mixes
+ col.to({ a01: -1, a11: 2, b0: 0, b1: 3 }, m('next'), 1.2);
+ const big = G(p, { o: 0 });
+ T(big, 'every b?', { x: 90, y: 830, size: 30, fill: COL.task, weight: 600 });
+ show(big, m('big'), .4);
+ text(p, 'yes: the columns fill the space', 270, 830, m('yes'), { size: 30, fill: COL.good, weight: 600 });
+ text(p, 'no: they lie flat (a line, a plane)', 810, 830, m('no'), { size: 30, fill: COL.bad, weight: 600 });
+ text(p, 'next: Unit 2, elimination', 1520, 110, m('next'), { size: 30, fill: COL.task, anchor: 'end', weight: 600 });
+ }],
+
+ ['wrap', 'Summary', (m) => {
+ const p = panel(0);
+ [['Every b? Ask whether the mixes of the columns fill the whole space.', 'w1'],
+ ['2 columns, different ways: the plane. Along one line: only that line.', 'w2'],
+ ['3 columns not in one plane: all of space. In one plane: only that plane.', 'w3'],
+ ['More numbers: no axes to draw, the same rules; bars show the numbers.', 'w4']].forEach(([str, mark], i) => {
+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
+ mk('circle', { cx: 150, cy: -12, r: 26, fill: COL.task }, g);
+ T(g, String(i + 1), { x: 150, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
+ T(g, str, { x: 210, size: 34, weight: 600 });
+ tw(g, { o: 1, x: 0 }, m(mark), .6);
+ });
+ }],
+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
+ id: 'p-fill2', prompt: ['Can a mix of these two columns reach every b in the plane?'],
+ build: grid(FILLQ, YN, { multi: false, text: true }),
+ }, {
+ id: 'p-fill3', prompt: ['Can a mix of these three columns reach every b in space?'],
+ build: grid(FILL3Q, YN, { multi: false, text: true }),
+ }], done, 'Chapter practice · set 1 of 4') }],
+ ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-reach2', prompt: ['Columns ', $m('(1, −1)'), ' and ', $m('(−3, 3)'), '. Every mix has its bottom equal to minus its top. Can a mix reach b?'],
+ build: grid(REACH2Q, YN, { multi: false, text: true }),
+ }, {
+ id: 'p-reach3', prompt: ['Floor columns: ', $m('(1, 0, 0), (0, 1, 0), (1, 1, 0)'), '. Sheet columns: ', $m('(2, −1, 0), (−1, 2, −3), (1, 1, −3)'), ' (on the sheet, top + 2·middle + bottom = 0). Can a mix reach b?'],
+ build: grid(REACH3Q, YN, { multi: false, text: true }),
+ }], done, 'Chapter practice · set 2 of 4') }],
+ ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
+ id: 'p-comb4', prompt: ['Work out each mix, number by number.'],
+ build: blanks(COMBQ),
+ }, {
+ id: 'p-mix4', prompt: ['With the columns of this chapter, ', $m('A x = (x₁, x₁ + x₂, x₂ + x₃, x₃ + x₄)'), '. Find the mix for each b.'],
+ build: blanks(MIX4Q),
+ }], done, 'Chapter practice · set 3 of 4') }],
+ ['final4', 'Chapter practice', () => {
+ const p = panel(0);
+ text(p, 'Move b', 60, 110, .2, { size: 40, weight: 600 });
+ const sys = S.sys = sys2(p, PAR, [3, 5]);
+ S.cf = colForm2(sys, p, .3); mixOut(sys, p, .4);
+ const lat = S.lat = lattice2(sys);
+ [lat.span, lat.dots, ...lat.L].forEach(e => show(e, .4, .5));
+ }, { ask: done => quiz(CARD, [{
+ id: 'p-onto', prompt: ['Columns ', $m('(1, 2)'), ' and ', $m('(2, 4)'), '. Move ', $m('b'), ' to a point a mix can reach (not the origin).'],
+ build: lsTask(S.sys, (v, s) => !!s.many && (v.b0 !== 0 || v.b1 !== 0), 'On the amber line the bottom of b is twice its top, and endlessly many mixes reach it.',
+ 'Every mix lands on the amber line: the bottom number twice the top. Put b on it.', () => S.sys.set({ b0: 1, b1: 2 }), { only: ['b0', 'b1'] }),
+ }, {
+ id: 'p-swing', prompt: ['Now move a column so that every b has a mix, with ', $m('b = (3, 5)'), '.'],
+ build: (body, api) => { S.sys.set({ b0: 3, b1: 5 }); return lsTask(S.sys, (v, s) => s.x !== undefined, 'The columns now point different ways: the grid fills the plane, and b has exactly one mix.',
+ 'Drag the tip of column 1 or column 2 off the line, so the two point different ways.', () => S.sys.set({ a01: -1, a11: 2 }), { only: ['a00', 'a10', 'a01', 'a11'] })(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 sys = S.sys = sys2(p, LA, [0, 3]);
+ colForm2(sys, p, .3); mixOut(sys, p, .4);
+ const lat = lattice2(sys);
+ [lat.span, lat.dots, ...lat.L].forEach(e => show(e, .4, .5));
+ const hint = text(p, 'try: lay column 2 along column 1; then put b on their line, and off it', 330, 110, m('go'), { size: 24, fill: COL.dim });
+ hide(hint, m('go') + 8, .6);
+ }, { ask: playAsk(() => S.sys, { pos: { x: 40, y: 578, w: 720, cls: 'side' }, tip: 'Your two columns and b. Drag the tips, change any number, 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/bars.js b/site/linear-algebra/lib/bars.js
new file mode 100644
index 0000000..9307b78
--- /dev/null
+++ b/site/linear-algebra/lib/bars.js
@@ -0,0 +1,210 @@
+// Vectors with any number of numbers, drawn as bars: each number is a bar that grows up (positive) or down (negative)
+// from its own zero line, with the number beside it. Entry 1 is on top, as in a written column, so reading down a
+// group is a column and reading across a band is one equation (row i of every column, of A x and of b).
+//
+// bars(p, { A, b, mix }) draws a system A x = b as
+// x₁·[col 1] + x₂·[col 2] + … = [A x] =/≠ [b]
+// with A x (the combination, chalk) beside b (amber); b's heights are also drawn as dashed outlines on A x, so the
+// reader sees each bar of A x reach its target, and a row that matches turns green with "=". Without A (A: []) it
+// draws b alone, as filled amber bars: one vector, to sit beside an arrow that shows the same numbers.
+// One state v (a{i}{j}, b{i}, x{j}) is drawn everywhere. The beat moves it with bars.to() (on the beat clock, so
+// seeking replays it); bars.live(true, { only }) lets the reader scrub numbers (drag, or Tab then ↑/↓) and drag bars
+// up and down; bars.set() changes it at once; bars.num(key) gives every text showing a value (to flash it).
+// Loads after engine.js.
+const BR_SUB = '₀₁₂₃₄₅₆₇₈₉';
+const BR_COLS = [COL.irr, COL.real, COL.rat, '#7fd8d8']; // columns 1–3 as style.json; column 4 teal (no hue left)
+
+function bars(p, { A = [], b = [], mix = null, x0 = 120, top = 250, band = 110, unit = 10, bw = 40, size = 30, numbers = true,
+ names = null, colors = null, gap = 28, mw = 72, t0 = .1, range = 9 } = {}) {
+ const n = b.length, m = A.length ? A[0].length : 0, svg = $('stage'), listeners = [], slots = [];
+ const v = {};
+ for (let i = 0; i < n; i++) { v[`b${i}`] = b[i]; for (let j = 0; j < m; j++) v[`a${i}${j}`] = A[i][j]; }
+ for (let j = 0; j < m; j++) v[`x${j}`] = mix ? mix[j] : 0;
+ let plan = { ...v }, live = false, allowed = null;
+ const can = k => live && (!allowed || allowed.has(k));
+ const colorOf = j => (colors || BR_COLS)[j % 4];
+ const g = G(p, { o: 0 });
+ g.style.userSelect = 'none';
+
+ const fmt = x => { const r = Math.round(x * 10) / 10, s = Number.isInteger(r) ? String(Math.abs(r)) : Math.abs(r).toFixed(1); return (r < 0 ? '−' : '') + s; };
+ const setText = (e, s) => { if (e.textContent !== s) e.textContent = s; };
+ const att = (e, k, x) => { if (e.getAttribute(k) !== String(x)) e.setAttribute(k, x); };
+ const zeroY = i => top + i * band + band / 2;
+ const H = band / 2 - 8; // the tallest bar; a bigger number is cut there (its number still says it)
+ const hOf = x => Math.max(-H, Math.min(H, x * unit));
+ const ax = (s = v) => Array.from({ length: n }, (_, i) => { let t = 0; for (let j = 0; j < m; j++) t += s[`a${i}${j}`] * s[`x${j}`]; return t; });
+ const close = (a, c) => Math.abs(a - c) < 1e-6;
+
+ /* ---------- numbers you can scrub (as in linsys): drag sideways or up, or Tab to it and press ↑/↓ ---------- */
+ function slot(into, key, x, y, { anchor = 'start', fill = COL.chalk, fs = size, w = fs * 1.9 } = {}) {
+ const box = mk('rect', { x: anchor === 'end' ? x - w : anchor === 'middle' ? x - w / 2 : x - 6, y: y - fs * .85, width: w + 6, height: fs * 1.15, rx: 8, fill: 'transparent' }, into);
+ const t = T(into, '', { x, y, size: fs, fill, font: MATH, anchor });
+ t.style.pointerEvents = 'none'; // Firefox hit-tests the text over the box: the box must get the pointer
+ const s = { key, t, box, set: () => setText(t, fmt(v[key])) };
+ box.setAttribute('aria-label', key);
+ let drag = null;
+ box.addEventListener('pointerdown', e => {
+ if (!can(key)) return;
+ e.preventDefault();
+ drag = { x: e.clientX, y: e.clientY, from: Math.round(v[key]) };
+ box.setPointerCapture(e.pointerId);
+ });
+ box.addEventListener('pointermove', e => {
+ if (!drag) return;
+ const k = svg.getScreenCTM().a;
+ edit({ [key]: clamp(drag.from + Math.round((e.clientX - drag.x - (e.clientY - drag.y)) / k / 22)) });
+ });
+ const end = () => { drag = null; };
+ box.addEventListener('pointerup', end);
+ box.addEventListener('lostpointercapture', end);
+ box.addEventListener('keydown', e => {
+ if (!can(key)) return;
+ if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); box.blur(); P.keys?.(e); return; } // Enter checks
+ const d = { ArrowUp: 1, ArrowRight: 1, ArrowDown: -1, ArrowLeft: -1 }[e.key];
+ if (!d) return;
+ e.preventDefault(); e.stopPropagation(); // the player's ←/→ must not leave the beat
+ edit({ [key]: clamp(Math.round(v[key]) + d) });
+ });
+ slots.push(s);
+ return s;
+ }
+ const clamp = x => Math.max(-range, Math.min(range, x));
+
+ // A bar can be dragged up and down too: the band's strip under it is its hit box.
+ function grab(into, key, x, i) {
+ const r = mk('rect', { x: x - bw / 2 - 6, y: top + i * band + 4, width: bw + 12, height: band - 8, fill: 'transparent' }, into);
+ r.setAttribute('aria-hidden', 'true');
+ let on = false;
+ const to = e => {
+ const q = svg.createSVGPoint(); q.x = e.clientX; q.y = e.clientY;
+ const y = q.matrixTransform(g.getScreenCTM().inverse()).y;
+ edit({ [key]: clamp(Math.round((zeroY(i) - y) / unit)) });
+ };
+ r.addEventListener('pointerdown', e => { if (!can(key)) return; e.preventDefault(); on = true; r.setPointerCapture(e.pointerId); to(e); });
+ r.addEventListener('pointermove', e => { if (on) to(e); });
+ r.addEventListener('pointerup', () => { on = false; });
+ r.addEventListener('lostpointercapture', () => { on = false; });
+ return r;
+ }
+
+ /* ---------- the layout, left to right ---------- */
+ const bracketD = (xa, xb) => { const y0 = top + 6, y1 = top + n * band - 6; return `M${xa + 12} ${y0}H${xa}V${y1}H${xa + 12}M${xb - 12} ${y0}H${xb}V${y1}H${xb - 12}`; };
+ const groupW = bw + (numbers ? size * 2 : 0) + 30; // bar, number, padding
+ const mid = top + n * band / 2;
+ const zeros = G(g, {}); // a faint zero line across each band: read across it and you read one equation
+ const group = (gx, color, { name, keys, filled = true, num = numbers, dashed = false, grabbable = true }) => {
+ const gg = G(g, {}), bx = gx + 15 + bw / 2;
+ path(gg, bracketD(gx, gx + groupW), { stroke: COL.chalk, 'stroke-width': 2.5, fill: 'none', 'stroke-opacity': .8 });
+ const rows = [];
+ for (let i = 0; i < n; i++) {
+ const bar = mk('rect', { x: bx - bw / 2, width: bw, y: zeroY(i), height: 0, rx: 3, fill: filled ? color : 'none', 'fill-opacity': .85, stroke: dashed ? color : 'none', 'stroke-width': 2.5, ...(dashed ? { 'stroke-dasharray': '6 5' } : {}) }, gg);
+ bar.style.pointerEvents = 'none';
+ const hit = keys && grabbable ? grab(gg, keys[i], bx, i) : null;
+ const s = num ? (keys ? slot(gg, keys[i], bx + bw / 2 + 10, zeroY(i) + size * .35, { fill: color }) : { t: T(gg, '', { x: bx + bw / 2 + 10, y: zeroY(i) + size * .35, size, fill: color, font: MATH }) }) : null;
+ rows.push({ bar, hit, s });
+ }
+ const label = name ? M(gg, [name], { x: gx + groupW / 2, y: top + n * band + 40, size: 30, fill: COL.dim, anchor: 'middle' }) : null;
+ return { g: gg, rows, bx, x: gx, label };
+ };
+ const plusSigns = [], mixG = [], cols = [];
+ let x = x0;
+ for (let j = 0; j < m; j++) {
+ if (j) { plusSigns.push(T(g, '+', { x: x + 4, y: mid + 14, size: 40, fill: COL.chalk, font: MATH, anchor: 'middle' })); x += gap; }
+ const mg = mixG[j] = G(g, {});
+ M(mg, ['x' + BR_SUB[j + 1]], { x: x + mw / 2, y: top - 12, size: 26, fill: COL.dim, anchor: 'middle' });
+ slot(mg, `x${j}`, x + mw - 10, mid + size * .35, { anchor: 'end', fs: size + 6, fill: COL.chalk });
+ x += mw;
+ cols.push(group(x, colorOf(j), { name: names?.[j] ?? `col ${j + 1}`, keys: Array.from({ length: n }, (_, i) => `a${i}${j}`) }));
+ x += groupW + gap;
+ }
+ let axG = null, eqs = [], eqSign = null;
+ if (m) {
+ eqSign = T(g, '=', { x: x, y: mid + 14, size: 40, fill: COL.chalk, font: MATH, anchor: 'middle' });
+ x += gap;
+ axG = group(x, COL.chalk, { name: names?.[m] ?? 'A x', keys: null });
+ // b's heights over A x: dashed outlines, the targets each bar of A x must reach
+ axG.goal = Array.from({ length: n }, () => { const r = mk('rect', { x: axG.bx - bw / 2 - 3, width: bw + 6, rx: 4, fill: 'none', stroke: COL.task, 'stroke-width': 2.5, 'stroke-dasharray': '7 5' }, axG.g); r.style.pointerEvents = 'none'; return r; });
+ x += groupW + 14;
+ eqs = Array.from({ length: n }, (_, i) => T(g, '', { x: x + 22, y: zeroY(i) + Math.min(38, band * .45) * .34, size: Math.min(38, band * .45), fill: COL.dim, font: MATH, anchor: 'middle', weight: 600 }));
+ x += 44;
+ }
+ const bG = n ? group(x, COL.task, { name: names?.[m + 1] ?? 'b', keys: Array.from({ length: n }, (_, i) => `b${i}`) }) : null;
+ x += groupW;
+ for (let i = 0; i < n; i++) path(zeros, `M${x0 - 10} ${zeroY(i)}H${x + 10}`, { stroke: COL.chalk, 'stroke-opacity': .12, 'stroke-width': 1.5 });
+
+ /* ---------- one state, drawn everywhere ---------- */
+ const barTo = (bar, val, dx = 0) => {
+ const h = hOf(val), y = zeroY(+bar.dataset.i);
+ att(bar, 'y', Math.round((h > 0 ? y - h : y) * 10) / 10);
+ att(bar, 'height', Math.round(Math.abs(h) * 10) / 10);
+ };
+ [...cols, axG, bG].filter(Boolean).forEach(G_ => G_.rows.forEach((r, i) => { r.bar.dataset.i = i; }));
+ axG?.goal.forEach((r, i) => { r.dataset.i = i; });
+ function draw() {
+ slots.forEach(s => s.set());
+ cols.forEach((c, j) => c.rows.forEach((r, i) => barTo(r.bar, v[`a${i}${j}`])));
+ bG?.rows.forEach((r, i) => barTo(r.bar, v[`b${i}`]));
+ const s = ax(), ok = [];
+ axG?.rows.forEach((r, i) => {
+ barTo(r.bar, s[i]);
+ const hit = close(s[i], v[`b${i}`]);
+ ok.push(hit);
+ att(r.bar, 'fill', hit ? COL.good : COL.chalk);
+ if (r.s) { setText(r.s.t, fmt(s[i])); att(r.s.t, 'fill', hit ? COL.good : COL.chalk); }
+ // a target of 0 is a short dashed line on the zero line
+ const goal = axG.goal[i], h = hOf(v[`b${i}`]), y = zeroY(i);
+ att(goal, 'y', Math.round((h > 0 ? y - h : y) * 10) / 10 - (Math.abs(h) < 1 ? 1.5 : 0));
+ att(goal, 'height', Math.max(3, Math.round(Math.abs(h) * 10) / 10));
+ setText(eqs[i], hit ? '=' : '≠');
+ att(eqs[i], 'fill', hit ? COL.good : COL.faint);
+ });
+ listeners.forEach(f => f(v, s, ok.length > 0 && ok.every(Boolean)));
+ }
+ function edit(to) {
+ let changed = false;
+ for (const k in to) if (k in v && v[k] !== to[k]) { v[k] = to[k]; changed = true; }
+ if (changed) draw();
+ }
+ draw();
+ show(g, t0, .5);
+
+ return {
+ v, g, cols, ax: axG, b: bG, mixG, plusSigns, eqSign, eqs, zeros, zeroY, size,
+ combo: () => ax(),
+ match: () => n > 0 && m > 0 && ax().every((t, i) => close(t, v[`b${i}`])),
+ // Move the numbers to new values over dur seconds, on the beat clock (deterministic, so seeking replays it).
+ to(next, at, dur = 1, ease = io) {
+ const from = { ...plan };
+ plan = { ...plan, ...next };
+ const goal = { ...plan }, keys = Object.keys(next);
+ prog(q => edit(Object.fromEntries(keys.map(k => [k, from[k] + (goal[k] - from[k]) * q]))), at, dur, ease);
+ },
+ set(to) { edit(to); plan = { ...plan, ...to }; }, // at once, for a reader's action or an answer shown
+ // Hands on: scrub numbers and drag bars. { only: ['x0', …] } unlocks only those; off with live(false) or a new beat.
+ live(on, { only } = {}) {
+ live = on;
+ allowed = on && only ? new Set(only) : null;
+ for (const s of slots) {
+ const ok = can(s.key);
+ s.box.style.cursor = ok ? 'ns-resize' : '';
+ s.box.setAttribute('stroke', ok ? COL.faint : 'none');
+ s.box.setAttribute('stroke-dasharray', '4 6');
+ if (ok) s.box.setAttribute('tabindex', 0); else s.box.removeAttribute('tabindex');
+ }
+ [...cols, bG].filter(Boolean).forEach(c => c.rows.forEach(r => { if (r.hit) r.hit.style.cursor = can(r.s?.key ?? '') ? 'ns-resize' : ''; }));
+ },
+ num: key => slots.filter(s => s.key === key).map(s => s.t),
+ onChange(f) { listeners.push(f); },
+ };
+}
+
+// A question that is a task on the bars: the reader changes the numbers until test(v, combo, match) holds, then checks.
+const barsTask = (bs, test, why, hint, reveal, { only } = {}) => (body, api) => {
+ bs.live(true, { only });
+ return {
+ check: () => { const ok = test(bs.v, bs.combo(), bs.match()); api.grade(ok, ok ? why : typeof hint === 'function' ? hint(bs.v, bs.combo()) : hint); },
+ reveal: () => { reveal?.(); return why; },
+ lock: () => bs.live(false),
+ hint: [kbd('Tab'), ' pick a number ', kbd('↑'), kbd('↓'), ' change it, or drag it'],
+ };
+};
diff --git a/site/linear-algebra/lib/linsys.js b/site/linear-algebra/lib/linsys.js
index 9ddf227..2286ce9 100644
--- a/site/linear-algebra/lib/linsys.js
+++ b/site/linear-algebra/lib/linsys.js
@@ -227,7 +227,8 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [
combo[0].setAttribute('d', reach ? arrowD(0, 0, s.x * c0[0], s.x * c0[1]) : '');
combo[1].setAttribute('d', reach ? arrowD(s.x * c0[0], s.x * c0[1], bb[0], bb[1]) : '');
// The readout under the equations, rebuilt only when it changes.
- const key = s.x !== undefined ? frac(s.x).join() + '|' + frac(s.y).join() : s.none ? 'none' : 'many';
+ const txt = parts => parts.map(q => typeof q === 'string' ? q : q.f.join('/')).join(''); // a fraction part is { f: [n, d] }, not text
+ const key = s.x !== undefined ? txt(frac(s.x)) + '|' + txt(frac(s.y)) : s.none ? 'none' : 'many';
if (readout && key !== solKey) {
solKey = key;
sol.replaceChildren();
diff --git a/site/linear-algebra/lib/space3.js b/site/linear-algebra/lib/space3.js
index cab9334..2dfbf7b 100644
--- a/site/linear-algebra/lib/space3.js
+++ b/site/linear-algebra/lib/space3.js
@@ -720,7 +720,8 @@ function lin3(p, { A = [[2, -1, 0], [-1, 2, -1], [0, -3, 4]], b = [0, -1, 4], eq
const reach = X && X.every(c => Math.abs(c) <= 12);
let at = O;
I.forEach(j => { const nxt = j === 2 && !mix ? bb : at.map((c, l) => c + X?.[j] * col(j)[l]); combo[j].set(reach ? at : null, reach ? nxt : null); at = reach ? nxt : O; });
- const key = one ? [s.x, s.y, s.z].map(c => exact(c).join()).join('|') : s.none ? 'none' : 'many' + s.rank;
+ const txt = parts => parts.map(q => typeof q === 'string' ? q : q.f.join('/')).join(''); // a fraction part is { f: [n, d] }, not text
+ const key = one ? [s.x, s.y, s.z].map(c => txt(exact(c))).join('|') : s.none ? 'none' : 'many' + s.rank;
if (readout && key !== solKey) {
solKey = key;
sol.replaceChildren();