Skip to content

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

12.8 KB
Raw Blame
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Function Notation — Elementary Algebra</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="audio/en/timings.js"></script>
<script>
'use strict';
const CHAPTER = { number: 46, title: 'Function Notation', minutes: 8, next: '../ch47/' };
const IN = COL.whole, OUT = COL.nat, NAMEC = COL.int, RULE = COL.irr;

/* ---------- chapter drawing helpers ---------- */
const mline = (p, parts, x, y, t0, fill = COL.chalk, size = 48, anchor = 'middle') => { 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; };
// A function machine centred on (x, y): a box named f with an input chute on the left and an output on the right.
function machine(p, x, y, t0, label = 'f') {
  const g = G(p, { x, y, o: 0 });
  path(g, 'M-260 0H-120M120 0H260', { stroke: COL.dim, 'stroke-width': 4, 'stroke-dasharray': '10 8' });
  path(g, 'M246 -12L262 0L246 12', { stroke: COL.dim, 'stroke-width': 4 });
  mk('rect', { x: -120, y: -80, width: 240, height: 160, rx: 24, fill: mix(COL.board, NAMEC, .2), stroke: NAMEC, 'stroke-width': 4 }, g);
  M(g, [label], { y: 22, size: 72, fill: NAMEC });
  show(g, t0);
  return g;
}
// Send a value through a machine at (x, y): in from the left, out on the right as the output.
function feed(p, x, y, inParts, outParts, t0) {
  const a = chip(p, inParts, IN, { x: x - 330, y, size: 40, o: 0 });
  show(a, t0, .3);
  tw(a, { x: x - 60, s: .4 }, t0 + .3, .8); hide(a, t0 + 1, .2);
  const b = chip(p, outParts, OUT, { x: x + 60, y, size: 40, o: 0, s: .4 });
  tw(b, { o: 1 }, t0 + 1.3, .2); tw(b, { x: x + 330, s: 1 }, t0 + 1.3, .8);
  return [a, b];
}
const F2 = x => 2 * x - 1;

/* ---------- beats ---------- */
const BEATS = [
  ['intro', 'Function notation', (m, D) => {
    const g = G(scene, { o: 0, y: 24 });
    T(g, 'Unit 8, Chapter 46', { x: 800, y: 330, size: 28, fill: COL.dim, anchor: 'middle' });
    T(g, 'Function Notation', { x: 800, y: 430, size: 88, weight: 600, anchor: 'middle' });
    tw(g, { o: 1, y: 0 }, .2, 1.1, out);
    const r = mline(scene, 'f(x)', 800, 600, m('sub'), COL.dim, 60);
    tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8);
  }],
  ['notation', 'Reading f(x)', (m) => {
    const p = panel(0);
    const row = tokens(p, [{ t: 'f', fill: NAMEC }, '(', { t: 'x', fill: IN }, ')', ' = ', { t: '2x − 1', fill: RULE }], { x: 800, y: 260, size: 96, anchor: 'middle', o: 0 });
    row.forEach(e => show(e, .3));
    const lab = (k, str, color, t0, dy = 90) => {
      const e = row[k];
      draw(path(p, `M${e._px} ${row.y + 20}V${row.y + dy - 30}`, { stroke: color, 'stroke-width': 3 }, { d: 0 }), t0, .3);
      text(p, str, e._px, row.y + dy, t0 + .2, { size: 28, fill: color, anchor: 'middle', weight: 600 });
    };
    lab(0, 'name', NAMEC, m('name'), 150);
    lab(2, 'input', IN, m('input'));
    lab(5, 'rule for the output', RULE, m('rule'));
    text(p, '“f of x”', 800, 120, m('read'), { size: 36, fill: COL.dim, anchor: 'middle' });
    mline(p, 'f(x)  ≠  f · x', 1340, 450, m('warn'), COL.bad, 40);
    machine(p, 800, 600, m('mach'));
    const a = chip(p, ['x'], IN, { x: 470, y: 600, size: 40, o: 0 });
    show(a, m('in'), .3); tw(a, { x: 740, s: .4 }, m('in', .3), .8); hide(a, m('in', 1), .2);
    const b = chip(p, ['f(x)'], OUT, { x: 860, y: 600, size: 40, o: 0, s: .4 });
    tw(b, { o: 1 }, m('out'), .2); tw(b, { x: 1130, s: 1 }, m('out'), .8);
    mline(p, 'g(x),   h(t),   …', 800, 790, m('other'), COL.dim, 40);
  }],
  ['q1', 'Quick check', () => { panel(0); }, { ask: done => quiz({ x: 300, y: 260, w: 1000, cls: 'side' }, [{
    id: 'c-mean', prompt: ['What does ', $m('f(3)'), ' mean?'],
    build: choice([['f times 3'], ['the output of f when the input is 3'], ['the input of f when the output is 3']], 1, 'The number in the parentheses is the input; f(3) is what comes out.',
      ['f(x) is not multiplication: f names the function.', null, 'The 3 is inside the parentheses, so it is the input, not the output.']),
  }], done) }],
  ['eval', 'Evaluating', (m) => {
    const p = panel(0), X = 700;
    eqLine(p, 'f(x)', '2x − 1', 160, .2, { xEq: X });
    text(p, 'find f(3)', 1150, 150, m('ask'), { size: 30, fill: IN, weight: 600 });
    const r = tokens(p, ['f(', { t: '3', fill: IN }, ') = 2(', { t: '3', fill: IN }, ') − 1'], { x: X - 116, y: 280, size: 50, o: 0 });
    const src = chip(p, ['3'], IN, { x: 1230, y: 220, size: 36, o: 0 });
    show(src, m('ask', .3), .3);
    r.forEach(e => show(e, m('sub'), .3));
    [1, 3].forEach((k, i) => { put(r[k], { x: 1230, y: 220 }); tw(r[k], { x: r[k]._px, y: 280 }, m('sub', .2 + i * .4), .7); });
    hide(src, m('sub', 1.2), .3);
    eqLine(p, 'f(3)', '6 − 1', 400, m('calc'), { xEq: X, note: '2 · 3 = 6' });
    eqLine(p, 'f(3)', '5', 520, m('ans'), { xEq: X, fill: COL.good });
    machine(p, 800, 720, m('mach'), 'f');
    feed(p, 800, 720, ['3'], ['5'], m('mach', .3));
  }],
  ['graph', 'Points on the graph', (m) => {
    const p = panel(0), P = S.P = plane(S.pg = G(scene), { cx: 1100, cy: 470, u: 40, x0: -4, x1: 5, y0: -7, y1: 9, t0: .2 });
    P.layer = p;
    eqLine(p, 'f(x)', '2x − 1', 160, .2, { xEq: 280, size: 46 });
    mline(p, 'f(3) = 5', 160, 300, m('pt'), COL.chalk, 46, 'start');
    mline(p, '→  (3, 5)', 360, 300, m('pt', .6), COL.task, 46, 'start');
    P.walk(3, 5, m('pt', 1), { label: '(3, 5)' });
    [[-2, 'more'], [0, 'more'], [1, 'more'], [4, 'more']].forEach(([x, k], i) => {
      P.dot(x, F2(x), COL.task, m(k, i * .4));
      mline(p, `f(${num(x)}) = ${num(F2(x))}`, 160, 380 + i * 60, m(k, i * .4), COL.dim, 36, 'start');
    });
    P.line(-3, F2(-3), 4.5, F2(4.5), COL.task, m('line'));
    text(p, 'graph of f', P.PX(4.6), P.PY(F2(4.6)) - 24, m('line', .8), { size: 24, fill: COL.task, anchor: 'end', weight: 600 });
    const v = path(p, `M${P.PX(0)} ${P.PY(0)}V${P.PY(-1)}`, { stroke: OUT, 'stroke-width': 5 }, { d: 0 });
    P.dot(0, 0, IN, m('read'));
    draw(v, m('down'), .5);
    P.dot(0, -1, OUT, m('down', .4), { label: 'f(0) = −1', dx: 16, dy: 30 });
  }],
  ['q2', 'Quick check', () => { S.P.layer = panel(0); S.P.line(-3, F2(-3), 4.5, F2(4.5), COL.task, .2); eqLine(S.P.layer, 'f(x)', '2x − 1', 160, .2, { xEq: 280, size: 46 }); }, { ask: done => quiz({ x: 80, y: 300, w: 560, cls: 'side' }, [{
    id: 'c-pt', prompt: ['Pick the point on the graph that shows ', $m('f(−2)'), '.'],
    build: pickPoint(S.P, [-2, -5], 'f(−2) = 2(−2) − 1 = −5, so the point is (−2, −5).',
      (x, y) => x !== -2 ? `The input is −2, so the point must have x = −2. You picked x = ${num(x)}.` : `x = −2 is right; now the height must be f(−2) = 2(−2) − 1.`),
  }], done) }],
  ['expr', 'An expression as input', (m) => {
    const p = panel(0), X = 700;
    hide(S.pg, 0, .4);
    eqLine(p, 'f(x)', '2x − 1', 160, .2, { xEq: X });
    text(p, 'find f(a + 2)', 1150, 150, m('ask'), { size: 30, fill: IN, weight: 600 });
    const r = tokens(p, ['f(', { t: 'a + 2', fill: IN }, ') = 2(', { t: 'a + 2', fill: IN }, ') − 1'], { x: X - 190, y: 290, size: 50, o: 0 });
    r.forEach(e => show(e, m('sub'), .3));
    [1, 3].forEach((k, i) => { put(r[k], { x: 1240, y: 140 }); tw(r[k], { x: r[k]._px, y: 290 }, m('sub', .2 + i * .4), .7); });
    eqLine(p, 'f(a + 2)', '2a + 4 − 1', 410, m('dist'), { xEq: X, note: 'distribute' });
    eqLine(p, 'f(a + 2)', '2a + 3', 530, m('comb'), { xEq: X, note: 'combine like terms', fill: COL.good });
    const box = put(mk('rect', { x: X - 260, y: 470, width: 520, height: 86, rx: 16, fill: 'none', stroke: COL.good, 'stroke-width': 3 }, p), { o: 0 });
    show(box, m('ans'));
  }],
  ['solve', 'Finding the input', (m) => {
    const p = panel(0), X = 360, P = plane(p, { cx: 1100, cy: 470, u: 40, x0: -4, x1: 5, y0: -7, y1: 9, t0: .2 });
    P.layer = p;
    P.line(-3, F2(-3), 4.5, F2(4.5), COL.task, .3);
    eqLine(p, 'f(x)', '2x − 1', 160, .2, { xEq: X, size: 46 });
    mline(p, 'f(x) = 7,  x = ?', 160, 250, m('ask'), OUT, 42, 'start');
    eqLine(p, '2x − 1', '7', 360, m('set'), { xEq: X, size: 46 });
    eqLine(p, '2x', '8', 450, m('add'), { xEq: X, size: 46, note: '+1 both sides', noteX: 520 });
    eqLine(p, 'x', '4', 540, m('div'), { xEq: X, size: 46, note: '÷2 both sides', noteX: 520, fill: COL.good });
    mline(p, 'f(4) = 8 − 1 = 7  ✓', 160, 650, m('chk'), COL.dim, 38, 'start');
    const h = path(p, `M${P.PX(-4)} ${P.PY(7)}H${P.PX(4)}`, { stroke: OUT, 'stroke-width': 4, 'stroke-dasharray': '10 8' }, { o: 0 });
    show(h, m('graph'));
    text(p, 'height 7', P.PX(-4) + 6, P.PY(7) - 12, m('graph'), { size: 22, fill: OUT, weight: 600 });
    P.dot(4, 7, OUT, m('graph', .6));
    draw(path(p, `M${P.PX(4)} ${P.PY(7)}V${P.PY(0)}`, { stroke: IN, 'stroke-width': 4 }, { d: 0 }), m('graph', 1), .6);
    P.dot(4, 0, IN, m('graph', 1.6), { label: 'x = 4', dx: 14, dy: -16 });
  }],
  ['q3', 'Quick check', () => { panel(0); }, { ask: done => quiz({ x: 300, y: 260, w: 1000, cls: 'side' }, [{
    id: 'c-solve', prompt: [$m('g(x) = 4x + 6'), '. For what input does ', $m('g(x) = −2'), '?'],
    build: blanks([{ parts: ['x = ', { box: '-2' }], why: '4x + 6 = −2, so 4x = −8 and x = −2.', hint: 'Set 4x + 6 equal to −2 and solve for x.' }]),
  }], done) }],
  ['wrap', 'Summary', (m) => {
    const p = panel(0);
    [['f(x): the output of f for the input x. Not multiplication.', 'w1', NAMEC], ['Evaluate: replace every x with the input, then calculate.', 'w2', IN],
     ['Each pair (x, f(x)) is a point on the graph.', 'w3', COL.task], ['Find an input: set the rule equal to the output and solve.', 'w4', OUT]].forEach(([str, mark, c], i) => {
      const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
      mk('circle', { cx: 170, cy: -12, r: 26, fill: c }, g);
      T(g, String(i + 1), { x: 170, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
      T(g, str, { x: 230, size: 32, weight: 600 });
      tw(g, { o: 1, x: 0 }, m(mark), .6);
    });
  }],
  ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
    id: 'p-eval', prompt: ['Evaluate each function.'], build: blanks([
      { parts: ['f(x) = x − 7:    f(5) = ', { box: '-2' }], why: '5 − 7 = −2.', hint: 'Replace x with 5.' },
      { parts: ['g(x) = −6x + 9:    g(−2) = ', { box: '21' }], why: '−6(−2) + 9 = 12 + 9 = 21.', hint: 'A negative times a negative is positive.' },
      { parts: ['h(a) = a', E(2), ' + 4:    h(−3) = ', { box: '13' }], why: '(−3)² + 4 = 9 + 4 = 13.', hint: '(−3)² is 9, not −9.' },
      { parts: ['k(p) = p', E(2), ' − 5p:    k(6) = ', { box: '6' }], why: '36 − 30 = 6.', hint: 'Replace both p’s with 6.' },
      { parts: ['j(x) = 9x', E(2), ' − 6x + 1:    j(−2) = ', { box: '49' }], why: '9(4) + 12 + 1 = 49.', hint: '(−2)² = 4, and −6(−2) = 12.' },
    ]),
  }], done, 'Chapter practice   1 of 3') }],
  ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
    id: 'p-input', prompt: ['Find each input.'], build: blanks([
      { parts: ['f(x) = x + 3,   f(x) = −2:    x = ', { box: '-5' }], why: 'x + 3 = −2, so x = −5.', hint: 'Subtract 3 from both sides.' },
      { parts: ['m(n) = −9 + ', F(1, 2), 'n,   m(n) = 3:    n = ', { box: '24' }], why: '½n = 12, so n = 24.', hint: 'Add 9 to both sides, then multiply by 2.' },
      { parts: ['p(t) = ', F('8t + 7', 3), ',   p(t) = −3:    t = ', { box: '-2' }], why: '8t + 7 = −9, so 8t = −16 and t = −2.', hint: 'Multiply both sides by 3 first.' },
      { parts: ['g(x) = 3x + 5,   g(x) = 12:    x = ', { box: '7/3' }], why: '3x = 7, so x = 7/3.', hint: 'Subtract 5, then divide by 3. The answer may be a fraction.' },
    ]),
  }], done, 'Chapter practice   2 of 3') }],
  ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
    id: 'p-expr', prompt: ['Write each result in the form shown.'], build: blanks([
      { parts: ['f(x) = 2x + 7:    f(3a) = ', { box: '6' }, 'a + ', { box: '7' }], why: '2(3a) + 7 = 6a + 7.', hint: 'Replace x with 3a.' },
      { parts: ['g(x) = 5x − 2:    g(b + 1) = ', { box: '5' }, 'b + ', { box: '3' }], why: '5(b + 1) − 2 = 5b + 5 − 2 = 5b + 3.', hint: 'Distribute the 5, then combine.' },
      { parts: ['h(x) = 4 − x:    h(2c) = ', { box: '4' }, ' − ', { box: '2' }, 'c'], why: '4 − 2c.', hint: 'Replace x with 2c.' },
    ]),
  }], done, 'Chapter practice   3 of 3') }],
  ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
boot();
</script>
</body>
</html>