An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Inequalities — Elementary Mathematics</title><link rel="stylesheet" href="../lib/engine.css"><link rel="expect" href="#bar" blocking="render"><style>.screen .grid .num{font-size:34px}.screen .blanks .math{font-size:32px}.side .keys{font-size:19px}.side .grid .row{grid-template-columns:65px minmax(0,1fr) 26px;gap:8px}.side .grid .why{padding-left:0;font-size:19px}.triplets .bline{gap:12px}.triplets .box{width:7ch!important}</style></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:14,title:'Inequalities',minutes:10,language:'en', next: '../ch15/' };
const iqColor=v=>v>0?POS:v<0?NEG:COL.chalk;
const iqText=(p,s,x,y,t=0,size=30,col=COL.chalk,anchor='start')=>{const e=T(p,s,{x,y,size,fill:col,anchor,o:0});show(e,t);return e;};
const iqMath=(p,s,x,y,t=0,size=52,col=COL.chalk,anchor='middle')=>{const e=M(p,Array.isArray(s)?s:[s],{x,y,size,fill:col,anchor,o:0});show(e,t);return e;};
const iqTitle=(p,s,sub='')=>{iqText(p,s,100,110,.1,43);if(sub)iqText(p,sub,100,165,.15,27,COL.dim);};
function iqLine(p,lo=-4,hi=4,u=160,y=520,o=800,step=1,labels=null){const g=G(p),x=v=>o+v*u;path(g,`M${x(lo)-15} ${y}H${x(hi)+15}`,{stroke:COL.chalk,'stroke-width':3});path(g,`M${x(lo)-5} ${y-7}L${x(lo)-15} ${y}L${x(lo)-5} ${y+7} M${x(hi)+5} ${y-7}L${x(hi)+15} ${y}L${x(hi)+5} ${y+7}`,{stroke:COL.chalk,'stroke-width':2,fill:'none'});for(let i=0;i<=Math.round((hi-lo)/step);i++){const v=lo+i*step;path(g,`M${x(v)} ${y-8}V${y+8}`,{stroke:COL.dim,'stroke-width':2});T(g,labels?labels(i,v):num(Number(v.toFixed(6))),{x:x(v),y:y+48,size:27,anchor:'middle',font:MATH,fill:Math.abs(v)<1e-10?COL.chalk:COL.dim});}return {g,x,lo,hi,u,y,o};}
function iqPoint(l,v,label=num(v),t=0,dy=-55,size=40,id='point'){const g=G(l.g,{x:l.x(v),y:l.y,o:0});g.dataset.pointId=id;g.dataset.value=v;const c=mk('circle',{r:11,fill:iqColor(v)},g);if(label!==null)M(g,Array.isArray(label)?label:[label],{x:0,y:dy,size,anchor:'middle',fill:iqColor(v)});show(g,t,.5);return {g,c,v};}
function iqComparison(p,a,sym,b,t=0,y=790,size=64){return tokens(p,[{t:a,fill:rat(a)?iqColor(rat(a)[0]):COL.chalk},' '+sym+' ',{t:b,fill:rat(b)?iqColor(rat(b)[0]):COL.chalk}],{x:800,y,size,anchor:'middle'}).map(e=>{put(e,{o:0});show(e,t);return e;});}
function iqDistance(l,v,t=0,y=340){const g=G(l.g,{o:0});const a=l.x(v),b=l.x(0);path(g,`M${a} ${y}H${b} M${a} ${y-8}V${y+8} M${b} ${y-8}V${y+8}`,{stroke:COL.task,'stroke-width':4});path(g,`M${a} ${y+8}V${l.y-16} M${b} ${y+8}V${l.y-16}`,{stroke:COL.task,'stroke-width':2,'stroke-dasharray':'6 6'});T(g,Math.abs(v)+' units',{x:(a+b)/2,y:y-25,size:28,fill:COL.task,anchor:'middle'});show(g,t);return g;}
function iqFractionModel(p,pt=0){const l=iqLine(p,-1,0,1200,650,1400,.25),rows=[];for(const [n,den,y] of [[3,4,270],[3,5,440]]){const g=G(p),cells=[];for(let i=0;i<den;i++){const c=mk('rect',{x:200+i*1200/den,y,width:1200/den,height:70,fill:i>=den-n?mix(COL.board,NEG,.45):COL.board,stroke:COL.chalk,'stroke-width':2},g);c.dataset.cellId=`whole-${den}-${i}`;cells.push(c);}iqMath(g,['−',F(3,den)],125,y+52,0,60,NEG);rows.push({g,cells,den,y});}const pts=[iqPoint(l,-.75,['−',F(3,4)],pt,-45,60,'fraction-fourths'),iqPoint(l,-.6,['−',F(3,5)],pt,105,60,'fraction-fifths')];return {l,rows,pts};}
function iqSubdivide(model,t){const cuts=[];for(const row of model.rows)for(let i=1;i<20;i++)if(i%(20/row.den)){const e=path(row.g,`M${200+i*60} ${row.y}V${row.y+70}`,{stroke:COL.dim,'stroke-width':1.5},{d:0});draw(e,t,.9);cuts.push(e);}return cuts;}
function iqRegion(l,bound,dir,closed,t=0,ct=t){const x=l.x(bound),edge=l.x(dir<0?l.lo:l.hi),g=G(l.g),r=mk('rect',{x,y:l.y-10,width:0,height:20,fill:COL.task,opacity:.3},g);put(r,{a_x:x,a_width:0});tw(r,{a_x:Math.min(x,edge),a_width:Math.abs(edge-x)},t,1.4,lin);const arrow=path(g,`M${edge-dir*15} ${l.y-10}L${edge} ${l.y}L${edge-dir*15} ${l.y+10}`,{stroke:COL.task,'stroke-width':4,fill:'none'},{o:0});show(arrow,t+1.2);const c=mk('circle',{cx:x,cy:l.y,r:13,fill:closed?COL.task:COL.board,stroke:COL.task,'stroke-width':4},g);put(c,{o:0});show(c,ct);g.dataset.bound=bound;g.dataset.closed=String(closed);g.dataset.direction=dir;return {g,r,c,bound,dir,closed};}
const iqNorm=s=>String(s).trim().replace(/^\+\s*/,'').replace(/(\d),(?=\d{3}\b)/g,'$1');
const iqCmp=(a,b)=>{const d=BigInt(a[0])*BigInt(b[1])-BigInt(b[0])*BigInt(a[1]);return d<0n?-1:d>0n?1:0;};
function iqQualify(values,bound,dir){const rs=values.map(v=>rat(iqNorm(v)));return rs.every(Boolean)&&rs.every(r=>dir<0?iqCmp(r,bound)<=0:iqCmp(r,bound)<0)&&rs.every((r,i)=>rs.slice(0,i).every(q=>iqCmp(r,q)!==0));}
// Exact rational membership uses original typed numerators/denominators, never floating division.
const iqTriplets=rows=>(body,api)=>{body.classList.add('blanks','triplets');const built=rows.map(it=>{const line=h('div','bline'),mark=h('span','mark'),why=h('div','why');line.append(mathEl(it.parts,32));const boxes=it.answers.map(a=>{const b=h('input','box');Object.assign(b,{type:'text',inputMode:'decimal',autocomplete:'off',spellcheck:false});b.dataset.ans=a;b.setAttribute('aria-label','Distinct qualifying value');line.append(b);return b;});line.append(mark);body.append(h('div','brow',[line,why]));return {it,boxes,mark,why};});const judge=r=>{const ok=iqQualify(r.boxes.map(b=>b.value),r.it.bound,r.it.dir);r.boxes.forEach(b=>{b.classList.toggle('good',ok);b.classList.toggle('bad',!ok)});r.mark.className='mark '+(ok?'good':'bad');r.mark.textContent=ok?'✓':'✗';r.why.replaceChildren(ok?'':rich(r.it.hint,20));return ok;};const all=built.flatMap(r=>r.boxes);requestAnimationFrame(()=>all[0].focus({preventScroll:true}));return {check(){const right=built.filter(judge).length;api.grade(right===built.length,right===built.length?'Every value fits its condition, and each row has three different values.':`${right} of ${built.length} right. Check the condition, and use three different values in each row.`,{right,total:built.length});},reveal(){built.forEach(r=>{r.boxes.forEach((b,i)=>b.value=r.it.answers[i]);judge(r);r.why.replaceChildren(rich(r.it.why,20))});return 'One possible set is shown. Other different values that fit work too.';},lock(){all.forEach(b=>b.disabled=true)},hint:['type integers, decimals, or fractions; ',kbd('Tab'),' next box, ',kbd('Enter'),' check, ',kbd('Esc'),' leave the box']};};
const iqOrderCols=[['l','<',COL.chalk],['e','=',COL.chalk],['g','>',COL.chalk]],iqTruthCols=[['t','true',COL.chalk],['f','false',COL.dim]];
const BEATS=[
['intro','Inequalities',(m,D)=>{const g=G(scene,{o:0,y:24});T(g,'Unit 1 · The Number System · Chapter 14',{x:800,y:230,size:28,fill:COL.dim,anchor:'middle'});T(g,'Inequalities',{x:800,y:370,size:86,weight:600,anchor:'middle'});M(g,['< > ≠ ≤ ≥'],{x:800,y:550,size:88,anchor:'middle',fill:COL.task});tw(g,{o:1,y:0},.2,1,out);iqText(g,'Compare positions · describe possibilities',800,700,m('sub'),35,COL.dim,'middle');hide(g,D-.8,.7);}],
['order','Left is smaller; right is greater',m=>{const p=panel(0);iqTitle(p,'Position explains the comparison');const l=iqLine(p,-4,6,115,530,660);S.iqLine=l;S.iqPoints=[iqPoint(l,-3,'−3',.4),iqPoint(l,5,'5',.4)];iqText(p,'← smaller',250,300,m('compare'),37,COL.task);iqText(p,'greater →',1320,300,m('compare'),37,COL.task,'end');iqComparison(p,'−3','<','5',m('compare'));iqText(p,'point toward the smaller value · open toward the greater',800,875,m('mouth'),27,COL.dim,'middle');}],
['reverse','Same order, reversed sentence',m=>{const p=panel(0);iqTitle(p,'The values stay in place');const l=iqLine(p,-4,6,115,560,660);iqPoint(l,-3,'−3',0);iqPoint(l,5,'5',0);const a=G(p,{x:580,y:300}),b=G(p,{x:1020,y:300}),s=G(p,{x:800,y:275});M(a,['−3'],{size:70,anchor:'middle',fill:NEG});M(b,['5'],{size:70,anchor:'middle',fill:POS});M(s,['<'],{y:25,size:82,anchor:'middle'});tw(a,{y:230},m('swap'),.5);tw(b,{y:390},m('swap'),.5);tw(a,{x:1020},m('swap',.5),1.4);tw(b,{x:580},m('swap',.5),1.4);tw(a,{y:300},m('swap',1.9),.5);tw(b,{y:300},m('swap',1.9),.5);hide(s,m('swap'),.15);show(s,m('sign'),.15);tw(s,{r:180},m('sign'),.7);iqMath(p,'−3 < 5 means 5 > −3',800,805,m('same'),53);S.iqSwap={a,b,s,l};}],
['negatives','Distance is not signed order',m=>{const p=panel(0);iqTitle(p,'−7 and −2','The one farther from zero sits farther left.');const l=iqLine(p,-8,2,118,610,1110,1,(_,v)=>v===-7||v===-2?'':num(v));S.iqLine=l;iqPoint(l,-7,'−7',m('distance',-2.8),48,40);iqPoint(l,-2,'−2',m('distance',-2.8),48,40);iqDistance(l,-7,m('distance'),460);iqDistance(l,-2,m('distance',1),545);iqComparison(p,'−7','<','−2',m('order'),790);iqText(p,'negative < 0 < positive',800,880,m('zero'),36,COL.chalk,'middle');}],
['q1','Quick check',()=>{const p=panel(0);iqTitle(p,'Which temperature is warmer?','Temperatures rise toward the right. Units: °C.');const l=iqLine(p,-10,0,115,500,1380);S.iqChoices=[-9,-4].map(v=>{const e=iqPoint(l,v,num(v)+'°',0,-70,44,'temperature-'+v);return {el:e.g,box:[l.x(v)-35,410,70,120],label:num(v)+' degrees Celsius'};});},{ask:done=>quiz(BAND,[{id:'c-temperature',prompt:'Choose the warmer temperature: −9°C or −4°C.',build:pickEls(S.iqChoices,1,'−4°C is warmer: −4 is greater than −9 and lies farther right.',()=>'Nine degrees below zero is colder than four degrees below zero.')}],done)}],
['decimals','Compare equal place sizes',m=>{const p=panel(0);iqTitle(p,'A zoomed decimal line','Enlarged interval 2.30–2.40 · one small interval = 0.01');const l=iqLine(p,2.3,2.4,12000,540,-27400,.01,(_,v)=>v.toFixed(2));S.iqLine=l;iqPoint(l,2.34,'2.34',m('points'),-90,52);iqPoint(l,2.37,'2.37',m('points'),-90,52);iqComparison(p,'2.34','<','2.37',m('compare'),730,76);iqMath(p,'2.340 = 2.34',800,850,m('equal'),58);}],
['fractions','Fractions on the same unit',m=>{const p=panel(0);iqTitle(p,'Compare −3/4 and −3/5','Both rows: the same unit from −1 to 0; shaded distance extends left from zero.');const model=iqFractionModel(p,m('points'));S.iqFraction=model;model.rows.forEach(r=>{put(r.g,{o:0});show(r.g,m('parts',-5.6))});iqMath(p,['−',F(3,4),' < −',F(3,5)],1100,845,m('points',2),64);}],
['repartition','Equal-sized twentieths',m=>{const p=panel(0);iqTitle(p,'Subdivide without changing either value','Each original fourth → 5 pieces · each original fifth → 4 pieces');S.iqFraction=iqFractionModel(p);S.iqCuts=iqSubdivide(S.iqFraction,m('cuts'));iqMath(p,['−',F(3,4),' = −',F(15,20)],800,230,m('labels'),54);iqMath(p,['−',F(3,5),' = −',F(12,20)],800,402,m('labels',1),54);iqMath(p,['−',F(15,20),' < −',F(12,20)],1100,845,m('compare'),64);}],
['q2','Quick check',()=>{const p=panel(0);iqTitle(p,'Choose the greater fraction','A point farther right has the greater value.');const l=iqLine(p,-1,0,1200,520,1400,.25,(_,v)=>v===-.75?'':num(v));S.iqChoices=[[-.8,['−',F(4,5)],'−4/5',-75],[-.75,['−',F(3,4)],'−3/4',75]].map(([v,label,name,dx],i)=>{const e=iqPoint(l,v,label,0,-120,64,'fraction-choice-'+i);put(e.g.querySelector('g'),{x:dx});path(l.g,`M${l.x(v)+dx*.6} 438L${l.x(v)} 505`,{stroke:iqColor(v),'stroke-width':2});return {el:e.g,box:[l.x(v)+dx-55,320,110,215],label:name};});},{ask:done=>quiz(BAND,[{id:'c-negative-fractions',prompt:'Choose the greater value: −4/5 or −3/4.',build:pickEls(S.iqChoices,1,'−3/4 is greater. Exactly, −15/20 > −16/20; its point is farther right.',()=> 'Four fifths is a larger distance from zero. On the negative side, that puts −4/5 farther left.')}],done)}],
['notEqual','Different values, not different writing',m=>{const p=panel(0);iqTitle(p,'≠ means “not equal”');const l=iqLine(p,-2,3,220,480,690);iqPoint(l,-1,'−1',0);iqPoint(l,2,'2',0);iqComparison(p,'−1','≠','2',m('different'),280);iqMath(p,'2 ≠ −1',1190,350,m('different',2),40);const low=iqLine(p,0,1,800,720,400,.25,(_,v)=>v===.5?'':num(v));const half=iqPoint(low,.5,[F(1,2)],m('equal'),-50,60,'equivalent-half');const dec=G(p,{x:1300,y:660,o:0});M(dec,['0.5'],{size:52,fill:POS,anchor:'middle'});show(dec,m('equal'));tw(dec,{x:800,y:790},m('equal',2),1.5);iqText(p,'same point, equal value',800,870,m('equal',4),32,COL.dim,'middle');S.iqEqual={low,half,dec};}],
['inclusive','At most two',m=>{const p=panel(0);iqTitle(p,'At most two','x stands for any number. Every number at most 2 fits.');const l=iqLine(p,-4,4,160,500);S.iqRegion=iqRegion(l,2,-1,true,m('region'),m('endpoint'));iqMath(p,'x ≤ 2',800,300,0,67);iqText(p,'2 is included',l.x(2),430,m('endpoint'),32,COL.task,'middle');for(const [v,s,dy,ly,ok] of [[-1,'−1',-65,385,1],[1.5,'1.5',95,650,1],[2.5,'2.5',95,650,0]]){const e=iqPoint(l,v,s,m('candidates'),dy,38);e.c.setAttribute('stroke',COL.board);e.c.setAttribute('stroke-width',3);iqText(p,ok?'qualifies':'does not',l.x(v),ly,m('candidates'),28,ok?COL.task:COL.dim,'middle');}iqText(p,'All points to the left, plus the boundary',800,815,m('candidates',2),35,COL.chalk,'middle');}],
['lower','At least negative one half',m=>{const p=panel(0);iqTitle(p,'At least negative one half','Every number at least −1/2 fits.');const l=iqLine(p,-2,2,300,540);S.iqRegion=iqRegion(l,-.5,1,true,m('region'),m('endpoint'));iqMath(p,['x ≥ −',F(1,2)],800,300,0,63);iqMath(p,['−',F(1,2),' is included'],l.x(-.5),395,m('endpoint'),52,COL.task);for(const v of [0,1]){const e=iqPoint(l,v,num(v),m('candidates'),-65,40);e.c.setAttribute('stroke',COL.board);e.c.setAttribute('stroke-width',3);}iqPoint(l,-.75,['−',F(3,4)],m('candidates'),115,60);iqText(p,'excluded',l.x(-.75),740,m('candidates'),30,COL.dim,'middle');iqText(p,'The numbers that fit go on to the right forever →',800,840,m('candidates',2),33,COL.chalk,'middle');}],
['strict','Does the boundary qualify?',m=>{const p=panel(0);iqTitle(p,'Same direction; different boundary');const a=iqLine(p,0,3,320,390,300);const b=iqLine(p,0,3,320,650,300);const ra=iqRegion(a,2,-1,false,m('open',-2.3),m('open')),rb=iqRegion(b,2,-1,true,m('open',-2.3),m('closed'));iqMath(p,'x < 2',220,290,0,50);iqMath(p,'x ≤ 2',220,550,0,50);iqText(p,'open: 2 excluded',1160,345,m('open'),31,COL.task,'middle');iqText(p,'filled: 2 included',1160,610,m('closed'),31,COL.task,'middle');iqText(p,'< and > exclude · ≤ and ≥ include',800,835,m('rule'),38,COL.chalk,'middle');S.iqStrict={a,b,ra,rb};}],
['q3','Quick check',()=>{const p=panel(0);iqTitle(p,'Which points fit?','The condition is x ≥ −1/2. The boundary counts.');const l=iqLine(p,-2,2,220,490,560);S.iqRegion=iqRegion(l,-.5,1,true,0);for(const [v,label,dy] of [[-1,'−1',-65],[-.5,['−',F(1,2)],120],[0,'0',-65],[1,'1',-65]]){const e=iqPoint(l,v,label,0,dy,v===-.5?60:46);e.c.setAttribute('stroke',COL.board);e.c.setAttribute('stroke-width',3);}},{ask:done=>quiz({x:1080,y:180,w:460,cls:'side'},[{id:'c-membership',prompt:['Does each value fit ',$m('x ≥ −',F(1,2)),'?'],build:grid([{parts:['−1'],ans:['n'],why:'−1 < −1/2: excluded.'},{parts:['−',F(1,2)],ans:['y'],why:'The ≥ boundary is included.'},{parts:['0'],ans:['y'],why:'0 > −1/2: included.'},{parts:['1'],ans:['y'],why:'1 > −1/2: included.'}],[['y','yes',COL.chalk],['n','no',COL.dim]],{multi:false})}],done)}],
['wrap','Read the symbols with a reason',m=>{const p=panel(0);iqTitle(p,'Inequalities describe order and possibilities');[['Left is smaller, right is greater; the open side faces the greater number','w1'],['Negatives too: farther left of zero means smaller','w2'],['≠ means different values; 1/2 = 0.5 are equal','w3'],['≤ and ≥ include the boundary; shade every number that fits','w4']].forEach(([s,k],i)=>{const g=G(p,{x:-16,y:290+i*165,o:0});mk('circle',{cx:130,cy:-12,r:32,fill:COL.task},g);T(g,String(i+1),{x:130,y:0,size:36,anchor:'middle',fill:COL.board});T(g,s,{x:200,size:38});tw(g,{x:0,o:1},m(k),.6);});}],
['final1','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[{id:'p-comparisons',prompt:'Choose the sign that makes each comparison true.',build:grid([{parts:['−18 ? 6'],ans:['l'],why:'A negative value is less than a positive value.'},{parts:['−11 ? −13'],ans:['g'],why:'−11 is farther right than −13.'},{parts:['0 ? −0.2'],ans:['g'],why:'Zero is greater than any negative number.'},{parts:['0.046 ? 0.047'],ans:['l'],why:'The thousandths decide: 6 < 7.'},{parts:[F(3,7),' ? ',F(5,7)],ans:['l'],why:'Three equal-sized sevenths are less than five.'},{parts:['−',F(5,6),' ? −',F(4,5)],ans:['l'],why:'−5/6 = −25/30 < −24/30 = −4/5.'}],iqOrderCols,{multi:false})}],done,'Chapter practice · set 1 of 3')}],
['final2','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[{id:'p-symbols',prompt:'Is each mathematical sentence true or false?',build:grid([{parts:['4 ≠ −4'],ans:['t'],why:'These have different signed values.'},{parts:[F(1,2),' ≠ 0.5'],ans:['f'],why:'1/2 and 0.5 are the same value.'},{parts:['−2 ≤ −2'],ans:['t'],why:'Less than OR equal to includes equality.'},{parts:['−',F(3,4),' ≥ −',F(1,2)],ans:['f'],why:'−3/4 lies left of −1/2, so it is smaller.'}],iqTruthCols,{multi:false})}],done,'Chapter practice · set 2 of 3')}],
['final3','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[{id:'p-distinct-sets',prompt:'Give three DIFFERENT values in each row. Whole numbers, decimals, and fractions all work.',build:iqTriplets([{parts:['y ≤ −2: '],answers:['-2','-3','-4'],bound:[-2,1],dir:-1,hint:'Every value must be ≤ −2, and the three values must be different. −2 and −4/2 count as the same value.',why:'Example only: −2, −3, −4. Any three different values at most −2 work.'},{parts:['Do NOT fit m ≥ 0: '],answers:['-1','-2','-3'],bound:[0,1],dir:1,hint:'A value that does not fit m ≥ 0 must be below zero. Zero fits, so it cannot be listed. Use three different values.',why:'Example only: −1, −2, −3. Any three different negative numbers do not fit m ≥ 0.'}])},{id:'p-warmer',prompt:'Which temperature is warmer: −6°C or −10°C?',build:choice(['−6°C','−10°C'],0,'−6°C is warmer because −6 > −10; it is closer to zero on the negative side.',['','A larger negative magnitude is farther left and colder.'])}],done,'Chapter practice · set 3 of 3')}],
['finish','Finished',()=>panel(0),{ask:finishCard}]
].map(([id,title,run,extra])=>({id,title,run,...extra}));
boot();
</script></body></html>