@classytic/labs 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (547) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +105 -0
  3. package/dist/biology/enzyme-rate/index.d.mts +1 -0
  4. package/dist/biology/enzyme-rate/preset.d.mts +25 -0
  5. package/dist/biology/enzyme-rate/preset.mjs +256 -0
  6. package/dist/biology/genetic-cross/core.d.mts +64 -0
  7. package/dist/biology/genetic-cross/core.mjs +147 -0
  8. package/dist/biology/genetic-cross/grid.mjs +239 -0
  9. package/dist/biology/genetic-cross/index.d.mts +3 -0
  10. package/dist/biology/genetic-cross/preset.d.mts +26 -0
  11. package/dist/biology/genetic-cross/preset.mjs +184 -0
  12. package/dist/biology/genetic-cross/sex-linked.d.mts +27 -0
  13. package/dist/biology/genetic-cross/sex-linked.mjs +226 -0
  14. package/dist/biology/index.d.mts +11 -0
  15. package/dist/biology/index.mjs +12 -0
  16. package/dist/biology/photosynthesis-factors/index.d.mts +1 -0
  17. package/dist/biology/photosynthesis-factors/preset.d.mts +25 -0
  18. package/dist/biology/photosynthesis-factors/preset.mjs +270 -0
  19. package/dist/biology/punnett-cross/index.d.mts +1 -0
  20. package/dist/biology/punnett-cross/preset.d.mts +27 -0
  21. package/dist/biology/punnett-cross/preset.mjs +21 -0
  22. package/dist/biology/respiration/index.d.mts +1 -0
  23. package/dist/biology/respiration/preset.d.mts +17 -0
  24. package/dist/biology/respiration/preset.mjs +179 -0
  25. package/dist/biology/sequence/central-dogma.d.mts +17 -0
  26. package/dist/biology/sequence/central-dogma.mjs +339 -0
  27. package/dist/biology/sequence/core.d.mts +38 -0
  28. package/dist/biology/sequence/core.mjs +178 -0
  29. package/dist/biology/sequence/index.d.mts +3 -0
  30. package/dist/biology/sequence/preset.d.mts +20 -0
  31. package/dist/biology/sequence/preset.mjs +235 -0
  32. package/dist/blocks/accounting.d.mts +142 -0
  33. package/dist/blocks/accounting.mjs +446 -0
  34. package/dist/blocks/authoring.d.mts +12 -0
  35. package/dist/blocks/authoring.mjs +705 -0
  36. package/dist/blocks/biology.d.mts +197 -0
  37. package/dist/blocks/biology.mjs +513 -0
  38. package/dist/blocks/chem.d.mts +128 -0
  39. package/dist/blocks/chem.mjs +486 -0
  40. package/dist/blocks/circuits.d.mts +86 -0
  41. package/dist/blocks/circuits.mjs +348 -0
  42. package/dist/blocks/discrete.d.mts +62 -0
  43. package/dist/blocks/discrete.mjs +314 -0
  44. package/dist/blocks/economics.d.mts +56 -0
  45. package/dist/blocks/economics.mjs +203 -0
  46. package/dist/blocks/geography.d.mts +58 -0
  47. package/dist/blocks/geography.mjs +115 -0
  48. package/dist/blocks/geometry.d.mts +28 -0
  49. package/dist/blocks/geometry.mjs +160 -0
  50. package/dist/blocks/ict.d.mts +65 -0
  51. package/dist/blocks/ict.mjs +197 -0
  52. package/dist/blocks/index.d.mts +4555 -0
  53. package/dist/blocks/index.mjs +120 -0
  54. package/dist/blocks/lab-block.d.mts +16 -0
  55. package/dist/blocks/lab-block.mjs +74 -0
  56. package/dist/blocks/lab-config.d.mts +23 -0
  57. package/dist/blocks/lab-config.mjs +200 -0
  58. package/dist/blocks/lab-gallery.d.mts +30 -0
  59. package/dist/blocks/lab-gallery.mjs +208 -0
  60. package/dist/blocks/language.d.mts +349 -0
  61. package/dist/blocks/language.mjs +750 -0
  62. package/dist/blocks/lesson.d.mts +43 -0
  63. package/dist/blocks/lesson.mjs +140 -0
  64. package/dist/blocks/math.d.mts +411 -0
  65. package/dist/blocks/math.mjs +1536 -0
  66. package/dist/blocks/ml.d.mts +84 -0
  67. package/dist/blocks/ml.mjs +146 -0
  68. package/dist/blocks/physics.d.mts +259 -0
  69. package/dist/blocks/physics.mjs +868 -0
  70. package/dist/blocks/statistics.d.mts +29 -0
  71. package/dist/blocks/statistics.mjs +123 -0
  72. package/dist/catalog/index.d.mts +3 -0
  73. package/dist/catalog/index.mjs +8 -0
  74. package/dist/catalog/registry.d.mts +46 -0
  75. package/dist/catalog/registry.mjs +56 -0
  76. package/dist/catalog/templates.d.mts +11 -0
  77. package/dist/catalog/templates.mjs +141 -0
  78. package/dist/chem/battery.d.mts +16 -0
  79. package/dist/chem/battery.mjs +311 -0
  80. package/dist/chem/bohr-atom.d.mts +16 -0
  81. package/dist/chem/bohr-atom.mjs +212 -0
  82. package/dist/chem/diffusion/asset.mjs +76 -0
  83. package/dist/chem/diffusion/index.d.mts +1 -0
  84. package/dist/chem/diffusion/preset.d.mts +15 -0
  85. package/dist/chem/diffusion/preset.mjs +188 -0
  86. package/dist/chem/electrochem/index.d.mts +1 -0
  87. package/dist/chem/electrochem/preset.d.mts +23 -0
  88. package/dist/chem/electrochem/preset.mjs +402 -0
  89. package/dist/chem/equilibrium/index.d.mts +1 -0
  90. package/dist/chem/equilibrium/preset.d.mts +36 -0
  91. package/dist/chem/equilibrium/preset.mjs +416 -0
  92. package/dist/chem/gas-box/index.d.mts +1 -0
  93. package/dist/chem/gas-box/preset.d.mts +27 -0
  94. package/dist/chem/gas-box/preset.mjs +395 -0
  95. package/dist/chem/index.d.mts +16 -0
  96. package/dist/chem/index.mjs +17 -0
  97. package/dist/chem/kinetics/index.d.mts +1 -0
  98. package/dist/chem/kinetics/preset.d.mts +31 -0
  99. package/dist/chem/kinetics/preset.mjs +478 -0
  100. package/dist/chem/periodic-trends/index.d.mts +1 -0
  101. package/dist/chem/periodic-trends/preset.d.mts +21 -0
  102. package/dist/chem/periodic-trends/preset.mjs +831 -0
  103. package/dist/chem/reaction-lab.d.mts +18 -0
  104. package/dist/chem/reaction-lab.mjs +165 -0
  105. package/dist/chem/reaction-profile.d.mts +21 -0
  106. package/dist/chem/reaction-profile.mjs +287 -0
  107. package/dist/chem/solution/dilution.d.mts +27 -0
  108. package/dist/chem/solution/dilution.mjs +199 -0
  109. package/dist/chem/solution/field.d.mts +30 -0
  110. package/dist/chem/solution/field.mjs +145 -0
  111. package/dist/chem/solution/index.d.mts +3 -0
  112. package/dist/chem/solution/solution-box.d.mts +28 -0
  113. package/dist/chem/solution/solution-box.mjs +140 -0
  114. package/dist/chem/stoichiometry/index.d.mts +1 -0
  115. package/dist/chem/stoichiometry/preset.d.mts +29 -0
  116. package/dist/chem/stoichiometry/preset.mjs +392 -0
  117. package/dist/chem/titration/index.d.mts +1 -0
  118. package/dist/chem/titration/preset.d.mts +29 -0
  119. package/dist/chem/titration/preset.mjs +436 -0
  120. package/dist/circuits/ac-dc/asset.mjs +295 -0
  121. package/dist/circuits/ac-dc/index.d.mts +1 -0
  122. package/dist/circuits/ac-dc/preset.d.mts +16 -0
  123. package/dist/circuits/ac-dc/preset.mjs +134 -0
  124. package/dist/circuits/capacitor-leak/index.d.mts +1 -0
  125. package/dist/circuits/capacitor-leak/preset.d.mts +32 -0
  126. package/dist/circuits/capacitor-leak/preset.mjs +271 -0
  127. package/dist/circuits/circuit/asset.d.mts +6 -0
  128. package/dist/circuits/circuit/asset.mjs +367 -0
  129. package/dist/circuits/circuit/index.d.mts +2 -0
  130. package/dist/circuits/circuit/preset.d.mts +46 -0
  131. package/dist/circuits/circuit/preset.mjs +235 -0
  132. package/dist/circuits/circuit-builder.d.mts +30 -0
  133. package/dist/circuits/circuit-builder.mjs +412 -0
  134. package/dist/circuits/circuit-lab.d.mts +20 -0
  135. package/dist/circuits/circuit-lab.mjs +400 -0
  136. package/dist/circuits/index.d.mts +7 -0
  137. package/dist/circuits/index.mjs +8 -0
  138. package/dist/commerce/accounting/core.d.mts +48 -0
  139. package/dist/commerce/accounting/core.mjs +57 -0
  140. package/dist/commerce/accounting/equation-balance.d.mts +35 -0
  141. package/dist/commerce/accounting/equation-balance.mjs +292 -0
  142. package/dist/commerce/accounting/index.d.mts +4 -0
  143. package/dist/commerce/accounting/journal-poster.d.mts +29 -0
  144. package/dist/commerce/accounting/journal-poster.mjs +472 -0
  145. package/dist/commerce/accounting/statement-sorter.d.mts +25 -0
  146. package/dist/commerce/accounting/statement-sorter.mjs +304 -0
  147. package/dist/commerce/economics/core.d.mts +33 -0
  148. package/dist/commerce/economics/core.mjs +26 -0
  149. package/dist/commerce/economics/demand-shift-vs-move.d.mts +35 -0
  150. package/dist/commerce/economics/demand-shift-vs-move.mjs +324 -0
  151. package/dist/commerce/economics/elasticity-revenue.d.mts +31 -0
  152. package/dist/commerce/economics/elasticity-revenue.mjs +253 -0
  153. package/dist/commerce/economics/index.d.mts +4 -0
  154. package/dist/commerce/economics/market-equilibrium.d.mts +33 -0
  155. package/dist/commerce/economics/market-equilibrium.mjs +340 -0
  156. package/dist/commerce/index.d.mts +9 -0
  157. package/dist/commerce/index.mjs +10 -0
  158. package/dist/core/easing.d.mts +28 -0
  159. package/dist/core/easing.mjs +66 -0
  160. package/dist/core/index.d.mts +10 -0
  161. package/dist/core/index.mjs +11 -0
  162. package/dist/core/numeric.d.mts +37 -0
  163. package/dist/core/numeric.mjs +75 -0
  164. package/dist/core/reactive.d.mts +24 -0
  165. package/dist/core/reactive.mjs +51 -0
  166. package/dist/core/rng.d.mts +21 -0
  167. package/dist/core/rng.mjs +39 -0
  168. package/dist/core/tex.d.mts +14 -0
  169. package/dist/core/tex.mjs +44 -0
  170. package/dist/core/timeline.d.mts +34 -0
  171. package/dist/core/timeline.mjs +77 -0
  172. package/dist/core/util.d.mts +19 -0
  173. package/dist/core/util.mjs +31 -0
  174. package/dist/discrete/arrangements/preset.d.mts +28 -0
  175. package/dist/discrete/arrangements/preset.mjs +304 -0
  176. package/dist/discrete/bayes/preset.d.mts +33 -0
  177. package/dist/discrete/bayes/preset.mjs +476 -0
  178. package/dist/discrete/binomial/preset.d.mts +25 -0
  179. package/dist/discrete/binomial/preset.mjs +333 -0
  180. package/dist/discrete/core/combinatorics.d.mts +23 -0
  181. package/dist/discrete/core/combinatorics.mjs +57 -0
  182. package/dist/discrete/core/inclusionExclusion.d.mts +19 -0
  183. package/dist/discrete/core/inclusionExclusion.mjs +30 -0
  184. package/dist/discrete/core/pigeonhole.d.mts +15 -0
  185. package/dist/discrete/core/pigeonhole.mjs +24 -0
  186. package/dist/discrete/core/probability.d.mts +29 -0
  187. package/dist/discrete/core/probability.mjs +43 -0
  188. package/dist/discrete/core/sets.d.mts +21 -0
  189. package/dist/discrete/core/sets.mjs +45 -0
  190. package/dist/discrete/counting-slots/preset.d.mts +30 -0
  191. package/dist/discrete/counting-slots/preset.mjs +553 -0
  192. package/dist/discrete/counting-tree/index.d.mts +1 -0
  193. package/dist/discrete/counting-tree/preset.d.mts +44 -0
  194. package/dist/discrete/counting-tree/preset.mjs +364 -0
  195. package/dist/discrete/expected-value/preset.d.mts +28 -0
  196. package/dist/discrete/expected-value/preset.mjs +352 -0
  197. package/dist/discrete/hypergeometric/preset.d.mts +25 -0
  198. package/dist/discrete/hypergeometric/preset.mjs +330 -0
  199. package/dist/discrete/index.d.mts +26 -0
  200. package/dist/discrete/index.mjs +27 -0
  201. package/dist/discrete/karnaugh/index.d.mts +1 -0
  202. package/dist/discrete/karnaugh/preset.d.mts +30 -0
  203. package/dist/discrete/karnaugh/preset.mjs +452 -0
  204. package/dist/discrete/lln/asset.mjs +206 -0
  205. package/dist/discrete/lln/index.d.mts +1 -0
  206. package/dist/discrete/lln/preset.d.mts +17 -0
  207. package/dist/discrete/lln/preset.mjs +152 -0
  208. package/dist/discrete/logic-circuit/index.d.mts +1 -0
  209. package/dist/discrete/logic-circuit/preset.d.mts +47 -0
  210. package/dist/discrete/logic-circuit/preset.mjs +307 -0
  211. package/dist/discrete/monte-carlo/index.d.mts +1 -0
  212. package/dist/discrete/monte-carlo/preset.d.mts +64 -0
  213. package/dist/discrete/monte-carlo/preset.mjs +446 -0
  214. package/dist/discrete/monty-hall/index.d.mts +1 -0
  215. package/dist/discrete/monty-hall/preset.d.mts +23 -0
  216. package/dist/discrete/monty-hall/preset.mjs +491 -0
  217. package/dist/discrete/outcome-builder/preset.d.mts +24 -0
  218. package/dist/discrete/outcome-builder/preset.mjs +283 -0
  219. package/dist/discrete/pascal/preset.d.mts +24 -0
  220. package/dist/discrete/pascal/preset.mjs +372 -0
  221. package/dist/discrete/sample-space/index.d.mts +1 -0
  222. package/dist/discrete/sample-space/preset.d.mts +42 -0
  223. package/dist/discrete/sample-space/preset.mjs +395 -0
  224. package/dist/discrete/selection/preset.d.mts +33 -0
  225. package/dist/discrete/selection/preset.mjs +406 -0
  226. package/dist/discrete/truth-table/index.d.mts +1 -0
  227. package/dist/discrete/truth-table/preset.d.mts +30 -0
  228. package/dist/discrete/truth-table/preset.mjs +456 -0
  229. package/dist/discrete/venn/index.d.mts +1 -0
  230. package/dist/discrete/venn/preset.d.mts +32 -0
  231. package/dist/discrete/venn/preset.mjs +461 -0
  232. package/dist/geography/cycle-lab/index.d.mts +1 -0
  233. package/dist/geography/cycle-lab/preset.d.mts +25 -0
  234. package/dist/geography/cycle-lab/preset.mjs +254 -0
  235. package/dist/geography/cycles.d.mts +21 -0
  236. package/dist/geography/cycles.mjs +205 -0
  237. package/dist/geography/index.d.mts +4 -0
  238. package/dist/geography/index.mjs +5 -0
  239. package/dist/geometry/board/index.d.mts +1 -0
  240. package/dist/geometry/board/preset.d.mts +71 -0
  241. package/dist/geometry/board/preset.mjs +148 -0
  242. package/dist/geometry/builder.d.mts +18 -0
  243. package/dist/geometry/builder.mjs +332 -0
  244. package/dist/geometry/index.d.mts +4 -0
  245. package/dist/geometry/index.mjs +5 -0
  246. package/dist/geometry/intersecting-circles.d.mts +17 -0
  247. package/dist/geometry/intersecting-circles.mjs +104 -0
  248. package/dist/ict/index.d.mts +5 -0
  249. package/dist/ict/index.mjs +6 -0
  250. package/dist/ict/number-systems/base-odometer.d.mts +34 -0
  251. package/dist/ict/number-systems/base-odometer.mjs +160 -0
  252. package/dist/ict/number-systems/bit-grouper.d.mts +32 -0
  253. package/dist/ict/number-systems/bit-grouper.mjs +190 -0
  254. package/dist/ict/number-systems/index.d.mts +4 -0
  255. package/dist/ict/number-systems/place-value-dial.d.mts +29 -0
  256. package/dist/ict/number-systems/place-value-dial.mjs +153 -0
  257. package/dist/ict/number-systems/wheel.d.mts +73 -0
  258. package/dist/ict/number-systems/wheel.mjs +279 -0
  259. package/dist/index.d.mts +10 -0
  260. package/dist/index.mjs +11 -0
  261. package/dist/kit/anim.mjs +52 -0
  262. package/dist/kit/annotate.mjs +116 -0
  263. package/dist/kit/answer-check.d.mts +38 -0
  264. package/dist/kit/answer-check.mjs +65 -0
  265. package/dist/kit/asset-util.mjs +15 -0
  266. package/dist/kit/controls.mjs +77 -0
  267. package/dist/kit/cycle.d.mts +44 -0
  268. package/dist/kit/cycle.mjs +188 -0
  269. package/dist/kit/diagram.mjs +176 -0
  270. package/dist/kit/electronics.mjs +357 -0
  271. package/dist/kit/expr-analysis.d.mts +37 -0
  272. package/dist/kit/expr-analysis.mjs +111 -0
  273. package/dist/kit/frame.d.mts +70 -0
  274. package/dist/kit/frame.mjs +205 -0
  275. package/dist/kit/freq-tree.mjs +99 -0
  276. package/dist/kit/gameshow.mjs +315 -0
  277. package/dist/kit/index.d.mts +5 -0
  278. package/dist/kit/index.mjs +6 -0
  279. package/dist/kit/logic-gates.d.mts +6 -0
  280. package/dist/kit/logic-gates.mjs +210 -0
  281. package/dist/kit/molecules.mjs +178 -0
  282. package/dist/kit/pedagogy.d.mts +126 -0
  283. package/dist/kit/pedagogy.mjs +331 -0
  284. package/dist/kit/play.d.mts +21 -0
  285. package/dist/kit/play.mjs +52 -0
  286. package/dist/kit/probability.mjs +141 -0
  287. package/dist/kit/proportion.mjs +112 -0
  288. package/dist/kit/reaction.mjs +102 -0
  289. package/dist/kit/rich.d.mts +10 -0
  290. package/dist/kit/rich.mjs +21 -0
  291. package/dist/kit/scale.mjs +230 -0
  292. package/dist/kit/space.mjs +326 -0
  293. package/dist/kit/steps.d.mts +24 -0
  294. package/dist/kit/steps.mjs +57 -0
  295. package/dist/kit/thermal.mjs +289 -0
  296. package/dist/language/agreement/index.d.mts +1 -0
  297. package/dist/language/agreement/preset.d.mts +27 -0
  298. package/dist/language/agreement/preset.mjs +113 -0
  299. package/dist/language/article-lens/index.d.mts +1 -0
  300. package/dist/language/article-lens/preset.d.mts +31 -0
  301. package/dist/language/article-lens/preset.mjs +125 -0
  302. package/dist/language/deck.d.mts +45 -0
  303. package/dist/language/deck.mjs +61 -0
  304. package/dist/language/icon.d.mts +40 -0
  305. package/dist/language/icon.mjs +73 -0
  306. package/dist/language/index.d.mts +10 -0
  307. package/dist/language/index.mjs +11 -0
  308. package/dist/language/preposition-scene/index.d.mts +1 -0
  309. package/dist/language/preposition-scene/preset.d.mts +34 -0
  310. package/dist/language/preposition-scene/preset.mjs +234 -0
  311. package/dist/language/sentence-builder/index.d.mts +1 -0
  312. package/dist/language/sentence-builder/preset.d.mts +32 -0
  313. package/dist/language/sentence-builder/preset.mjs +122 -0
  314. package/dist/language/transform/index.d.mts +1 -0
  315. package/dist/language/transform/preset.d.mts +31 -0
  316. package/dist/language/transform/preset.mjs +137 -0
  317. package/dist/language/ui.d.mts +53 -0
  318. package/dist/language/ui.mjs +88 -0
  319. package/dist/language/word-match/index.d.mts +1 -0
  320. package/dist/language/word-match/preset.d.mts +22 -0
  321. package/dist/language/word-match/preset.mjs +148 -0
  322. package/dist/math/area-model/asset.d.mts +6 -0
  323. package/dist/math/area-model/asset.mjs +270 -0
  324. package/dist/math/area-model/index.d.mts +2 -0
  325. package/dist/math/area-model/preset.d.mts +29 -0
  326. package/dist/math/area-model/preset.mjs +243 -0
  327. package/dist/math/balance-algebra/asset.d.mts +6 -0
  328. package/dist/math/balance-algebra/asset.mjs +150 -0
  329. package/dist/math/balance-algebra/index.d.mts +2 -0
  330. package/dist/math/balance-algebra/preset.d.mts +30 -0
  331. package/dist/math/balance-algebra/preset.mjs +228 -0
  332. package/dist/math/derivation.d.mts +22 -0
  333. package/dist/math/derivation.mjs +113 -0
  334. package/dist/math/derivative-explorer/index.d.mts +1 -0
  335. package/dist/math/derivative-explorer/preset.d.mts +19 -0
  336. package/dist/math/derivative-explorer/preset.mjs +227 -0
  337. package/dist/math/function-machine/index.d.mts +1 -0
  338. package/dist/math/function-machine/preset.d.mts +21 -0
  339. package/dist/math/function-machine/preset.mjs +177 -0
  340. package/dist/math/gradient-descent.d.mts +23 -0
  341. package/dist/math/gradient-descent.mjs +473 -0
  342. package/dist/math/grapher/index.d.mts +1 -0
  343. package/dist/math/grapher/preset.d.mts +40 -0
  344. package/dist/math/grapher/preset.mjs +313 -0
  345. package/dist/math/harmonic-form/index.d.mts +1 -0
  346. package/dist/math/harmonic-form/preset.d.mts +21 -0
  347. package/dist/math/harmonic-form/preset.mjs +387 -0
  348. package/dist/math/index.d.mts +25 -0
  349. package/dist/math/index.mjs +26 -0
  350. package/dist/math/integral-explorer/index.d.mts +1 -0
  351. package/dist/math/integral-explorer/preset.d.mts +23 -0
  352. package/dist/math/integral-explorer/preset.mjs +217 -0
  353. package/dist/math/interactive/index.d.mts +1 -0
  354. package/dist/math/interactive/preset.d.mts +72 -0
  355. package/dist/math/interactive/preset.mjs +202 -0
  356. package/dist/math/limit-explorer/index.d.mts +1 -0
  357. package/dist/math/limit-explorer/preset.d.mts +19 -0
  358. package/dist/math/limit-explorer/preset.mjs +216 -0
  359. package/dist/math/linear-system/index.d.mts +1 -0
  360. package/dist/math/linear-system/preset.d.mts +28 -0
  361. package/dist/math/linear-system/preset.mjs +164 -0
  362. package/dist/math/mystery-bucket/asset.d.mts +6 -0
  363. package/dist/math/mystery-bucket/asset.mjs +145 -0
  364. package/dist/math/mystery-bucket/index.d.mts +2 -0
  365. package/dist/math/mystery-bucket/preset.d.mts +36 -0
  366. package/dist/math/mystery-bucket/preset.mjs +116 -0
  367. package/dist/math/number-line/index.d.mts +1 -0
  368. package/dist/math/number-line/preset.d.mts +24 -0
  369. package/dist/math/number-line/preset.mjs +142 -0
  370. package/dist/math/parabola/index.d.mts +1 -0
  371. package/dist/math/parabola/preset.d.mts +13 -0
  372. package/dist/math/parabola/preset.mjs +79 -0
  373. package/dist/math/pattern/asset.d.mts +6 -0
  374. package/dist/math/pattern/asset.mjs +102 -0
  375. package/dist/math/pattern/index.d.mts +2 -0
  376. package/dist/math/pattern/preset.d.mts +32 -0
  377. package/dist/math/pattern/preset.mjs +294 -0
  378. package/dist/math/triangle-trig/index.d.mts +1 -0
  379. package/dist/math/triangle-trig/preset.d.mts +47 -0
  380. package/dist/math/triangle-trig/preset.mjs +245 -0
  381. package/dist/math/trig-explorer.d.mts +18 -0
  382. package/dist/math/trig-explorer.mjs +209 -0
  383. package/dist/ml/boundary/index.d.mts +1 -0
  384. package/dist/ml/boundary/preset.d.mts +24 -0
  385. package/dist/ml/boundary/preset.mjs +385 -0
  386. package/dist/ml/classifier/index.d.mts +1 -0
  387. package/dist/ml/classifier/preset.d.mts +25 -0
  388. package/dist/ml/classifier/preset.mjs +315 -0
  389. package/dist/ml/index.d.mts +6 -0
  390. package/dist/ml/index.mjs +7 -0
  391. package/dist/ml/kmeans/index.d.mts +1 -0
  392. package/dist/ml/kmeans/preset.d.mts +33 -0
  393. package/dist/ml/kmeans/preset.mjs +236 -0
  394. package/dist/ml/knn/index.d.mts +1 -0
  395. package/dist/ml/knn/preset.d.mts +28 -0
  396. package/dist/ml/knn/preset.mjs +279 -0
  397. package/dist/ml/regression/index.d.mts +1 -0
  398. package/dist/ml/regression/preset.d.mts +32 -0
  399. package/dist/ml/regression/preset.mjs +394 -0
  400. package/dist/physics/atwood/index.d.mts +1 -0
  401. package/dist/physics/atwood/preset.d.mts +23 -0
  402. package/dist/physics/atwood/preset.mjs +312 -0
  403. package/dist/physics/bullet-walls/index.d.mts +1 -0
  404. package/dist/physics/bullet-walls/preset.d.mts +28 -0
  405. package/dist/physics/bullet-walls/preset.mjs +373 -0
  406. package/dist/physics/carnot/index.d.mts +1 -0
  407. package/dist/physics/carnot/preset.d.mts +27 -0
  408. package/dist/physics/carnot/preset.mjs +427 -0
  409. package/dist/physics/circular-motion/index.d.mts +1 -0
  410. package/dist/physics/circular-motion/preset.d.mts +25 -0
  411. package/dist/physics/circular-motion/preset.mjs +293 -0
  412. package/dist/physics/collision-track/index.d.mts +1 -0
  413. package/dist/physics/collision-track/preset.d.mts +27 -0
  414. package/dist/physics/collision-track/preset.mjs +352 -0
  415. package/dist/physics/efficiency/index.d.mts +1 -0
  416. package/dist/physics/efficiency/preset.d.mts +33 -0
  417. package/dist/physics/efficiency/preset.mjs +343 -0
  418. package/dist/physics/electric-field/index.d.mts +1 -0
  419. package/dist/physics/electric-field/preset.d.mts +15 -0
  420. package/dist/physics/electric-field/preset.mjs +306 -0
  421. package/dist/physics/energy-skate/index.d.mts +1 -0
  422. package/dist/physics/energy-skate/preset.d.mts +25 -0
  423. package/dist/physics/energy-skate/preset.mjs +254 -0
  424. package/dist/physics/entropy/index.d.mts +1 -0
  425. package/dist/physics/entropy/preset.d.mts +18 -0
  426. package/dist/physics/entropy/preset.mjs +416 -0
  427. package/dist/physics/expansion/index.d.mts +1 -0
  428. package/dist/physics/expansion/preset.d.mts +26 -0
  429. package/dist/physics/expansion/preset.mjs +609 -0
  430. package/dist/physics/exponential/asset.mjs +221 -0
  431. package/dist/physics/exponential/index.d.mts +1 -0
  432. package/dist/physics/exponential/preset.d.mts +17 -0
  433. package/dist/physics/exponential/preset.mjs +182 -0
  434. package/dist/physics/gas-process/index.d.mts +1 -0
  435. package/dist/physics/gas-process/preset.d.mts +30 -0
  436. package/dist/physics/gas-process/preset.mjs +384 -0
  437. package/dist/physics/gravitation/index.d.mts +1 -0
  438. package/dist/physics/gravitation/preset.d.mts +24 -0
  439. package/dist/physics/gravitation/preset.mjs +345 -0
  440. package/dist/physics/gravity-drop.d.mts +9 -0
  441. package/dist/physics/gravity-drop.mjs +187 -0
  442. package/dist/physics/heat-transfer/index.d.mts +1 -0
  443. package/dist/physics/heat-transfer/preset.d.mts +27 -0
  444. package/dist/physics/heat-transfer/preset.mjs +626 -0
  445. package/dist/physics/impulse/index.d.mts +1 -0
  446. package/dist/physics/impulse/preset.d.mts +29 -0
  447. package/dist/physics/impulse/preset.mjs +453 -0
  448. package/dist/physics/index.d.mts +43 -0
  449. package/dist/physics/index.mjs +44 -0
  450. package/dist/physics/kepler/index.d.mts +1 -0
  451. package/dist/physics/kepler/preset.d.mts +27 -0
  452. package/dist/physics/kepler/preset.mjs +257 -0
  453. package/dist/physics/lever/asset.d.mts +6 -0
  454. package/dist/physics/lever/asset.mjs +220 -0
  455. package/dist/physics/lever/index.d.mts +2 -0
  456. package/dist/physics/lever/preset.d.mts +31 -0
  457. package/dist/physics/lever/preset.mjs +261 -0
  458. package/dist/physics/lorentz/index.d.mts +1 -0
  459. package/dist/physics/lorentz/preset.d.mts +29 -0
  460. package/dist/physics/lorentz/preset.mjs +367 -0
  461. package/dist/physics/magnetism/index.d.mts +1 -0
  462. package/dist/physics/magnetism/preset.d.mts +15 -0
  463. package/dist/physics/magnetism/preset.mjs +334 -0
  464. package/dist/physics/optics/asset.d.mts +6 -0
  465. package/dist/physics/optics/asset.mjs +234 -0
  466. package/dist/physics/optics/index.d.mts +2 -0
  467. package/dist/physics/optics/preset.d.mts +14 -0
  468. package/dist/physics/optics/preset.mjs +202 -0
  469. package/dist/physics/orbit-lab.d.mts +6 -0
  470. package/dist/physics/orbit-lab.mjs +222 -0
  471. package/dist/physics/projectile-lab.d.mts +10 -0
  472. package/dist/physics/projectile-lab.mjs +354 -0
  473. package/dist/physics/rain-relative/index.d.mts +1 -0
  474. package/dist/physics/rain-relative/preset.d.mts +19 -0
  475. package/dist/physics/rain-relative/preset.mjs +358 -0
  476. package/dist/physics/ramp-forces/index.d.mts +1 -0
  477. package/dist/physics/ramp-forces/preset.d.mts +36 -0
  478. package/dist/physics/ramp-forces/preset.mjs +550 -0
  479. package/dist/physics/river-boat.d.mts +22 -0
  480. package/dist/physics/river-boat.mjs +498 -0
  481. package/dist/physics/shm/index.d.mts +1 -0
  482. package/dist/physics/shm/preset.d.mts +33 -0
  483. package/dist/physics/shm/preset.mjs +554 -0
  484. package/dist/physics/stopping-distance/index.d.mts +1 -0
  485. package/dist/physics/stopping-distance/preset.d.mts +29 -0
  486. package/dist/physics/stopping-distance/preset.mjs +662 -0
  487. package/dist/physics/temperature-scales/index.d.mts +1 -0
  488. package/dist/physics/temperature-scales/preset.d.mts +15 -0
  489. package/dist/physics/temperature-scales/preset.mjs +353 -0
  490. package/dist/physics/terminal-velocity/index.d.mts +1 -0
  491. package/dist/physics/terminal-velocity/preset.d.mts +26 -0
  492. package/dist/physics/terminal-velocity/preset.mjs +404 -0
  493. package/dist/physics/thermal/index.d.mts +1 -0
  494. package/dist/physics/thermal/preset.d.mts +44 -0
  495. package/dist/physics/thermal/preset.mjs +373 -0
  496. package/dist/physics/vector-board/index.d.mts +1 -0
  497. package/dist/physics/vector-board/preset.d.mts +65 -0
  498. package/dist/physics/vector-board/preset.mjs +273 -0
  499. package/dist/physics/vector-board/view.d.mts +49 -0
  500. package/dist/physics/vector-board/view.mjs +58 -0
  501. package/dist/physics/vector-scene.d.mts +41 -0
  502. package/dist/physics/vector-scene.mjs +211 -0
  503. package/dist/physics/vector-types/index.d.mts +1 -0
  504. package/dist/physics/vector-types/preset.d.mts +27 -0
  505. package/dist/physics/vector-types/preset.mjs +192 -0
  506. package/dist/physics/water-density/index.d.mts +1 -0
  507. package/dist/physics/water-density/preset.d.mts +18 -0
  508. package/dist/physics/water-density/preset.mjs +439 -0
  509. package/dist/physics/waves/core.mjs +33 -0
  510. package/dist/physics/waves/doppler.d.mts +23 -0
  511. package/dist/physics/waves/doppler.mjs +260 -0
  512. package/dist/physics/waves/index.d.mts +4 -0
  513. package/dist/physics/waves/preset.d.mts +30 -0
  514. package/dist/physics/waves/preset.mjs +488 -0
  515. package/dist/physics/waves/ripple.d.mts +26 -0
  516. package/dist/physics/waves/ripple.mjs +234 -0
  517. package/dist/physics/waves/string.d.mts +29 -0
  518. package/dist/physics/waves/string.mjs +289 -0
  519. package/dist/physics/work-energy/index.d.mts +1 -0
  520. package/dist/physics/work-energy/preset.d.mts +17 -0
  521. package/dist/physics/work-energy/preset.mjs +341 -0
  522. package/dist/schemas/index.d.mts +235 -0
  523. package/dist/schemas/index.mjs +145 -0
  524. package/dist/statistics/center-spread/preset.d.mts +34 -0
  525. package/dist/statistics/center-spread/preset.mjs +323 -0
  526. package/dist/statistics/core/descriptive.d.mts +35 -0
  527. package/dist/statistics/core/descriptive.mjs +64 -0
  528. package/dist/statistics/core/normal.d.mts +21 -0
  529. package/dist/statistics/core/normal.mjs +37 -0
  530. package/dist/statistics/core/sequences.d.mts +27 -0
  531. package/dist/statistics/core/sequences.mjs +35 -0
  532. package/dist/statistics/galton/preset.d.mts +27 -0
  533. package/dist/statistics/galton/preset.mjs +331 -0
  534. package/dist/statistics/histogram/preset.d.mts +27 -0
  535. package/dist/statistics/histogram/preset.mjs +385 -0
  536. package/dist/statistics/index.d.mts +11 -0
  537. package/dist/statistics/index.mjs +12 -0
  538. package/dist/statistics/normal/preset.d.mts +30 -0
  539. package/dist/statistics/normal/preset.mjs +400 -0
  540. package/dist/statistics/sampling/preset.d.mts +32 -0
  541. package/dist/statistics/sampling/preset.mjs +406 -0
  542. package/dist/statistics/sequence/preset.d.mts +28 -0
  543. package/dist/statistics/sequence/preset.mjs +302 -0
  544. package/dist/statistics/z-table/preset.d.mts +28 -0
  545. package/dist/statistics/z-table/preset.mjs +348 -0
  546. package/package.json +266 -0
  547. package/styles.css +267 -0
@@ -0,0 +1,177 @@
1
+ 'use client';
2
+
3
+ import { CheckButton, Chip, LabStyles, StatusPill } from "../../kit/controls.mjs";
4
+ import { ControlBar, LabFrame, LiveRegion } from "../../kit/frame.mjs";
5
+ import { useCheckpoint } from "../../kit/pedagogy.mjs";
6
+ import { useState } from "react";
7
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
+ import { Label, Polygon, Segment, Stage } from "@classytic/stage";
9
+
10
+ //#region src/math/function-machine/preset.tsx
11
+ /**
12
+ * Function machine — a "predict the rule" interactive (Brilliant-style), built
13
+ * on @classytic/stage: inputs → outputs with index-matched connectors, a rule
14
+ * chip, multiple-choice rules, and a Check that reports to the learner seam. A
15
+ * GENERAL tool: a creator passes any inputs/outputs/choices/answer.
16
+ */
17
+ function rect(x0, y0, x1, y1) {
18
+ return [
19
+ {
20
+ x: x0,
21
+ y: y0
22
+ },
23
+ {
24
+ x: x1,
25
+ y: y0
26
+ },
27
+ {
28
+ x: x1,
29
+ y: y1
30
+ },
31
+ {
32
+ x: x0,
33
+ y: y1
34
+ }
35
+ ];
36
+ }
37
+ function FunctionMachineLab({ prompt = "Which rule produces these outputs?", inputs, outputs, choices, answer, height = 340 }) {
38
+ const [sel, setSel] = useState(null);
39
+ const [result, setResult] = useState(null);
40
+ useCheckpoint({
41
+ solved: result === "correct",
42
+ activity: `predict-rule-${answer}`,
43
+ response: sel ?? ""
44
+ });
45
+ const n = Math.max(inputs.length, outputs.length);
46
+ const ys = n === 1 ? [0] : Array.from({ length: n }, (_, i) => 2.3 - 4.6 * i / (n - 1));
47
+ const glow = result === "correct" ? "var(--stage-good)" : result === "wrong" ? "var(--stage-danger)" : "var(--stage-accent)";
48
+ const check = () => {
49
+ setResult(sel === answer ? "correct" : "wrong");
50
+ };
51
+ const figure = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(LabStyles, {}), /* @__PURE__ */ jsxs(Stage, {
52
+ view: {
53
+ xMin: -7,
54
+ xMax: 7,
55
+ yMin: -3.6,
56
+ yMax: 4.4
57
+ },
58
+ height,
59
+ ariaLabel: prompt,
60
+ children: [
61
+ /* @__PURE__ */ jsx(Polygon, {
62
+ points: rect(-3.2, -3, 3.2, 3),
63
+ color: "transparent",
64
+ fill: glow,
65
+ fillOpacity: .14,
66
+ weight: 0
67
+ }),
68
+ /* @__PURE__ */ jsx(Polygon, {
69
+ points: rect(-1.5, 3.3, 1.5, 4.2),
70
+ color: glow,
71
+ fill: glow,
72
+ fillOpacity: .28,
73
+ weight: 1.5
74
+ }),
75
+ /* @__PURE__ */ jsx(Label, {
76
+ x: 0,
77
+ y: 3.75,
78
+ text: sel ?? "?",
79
+ size: 14,
80
+ color: "var(--stage-fg)"
81
+ }),
82
+ /* @__PURE__ */ jsx(Polygon, {
83
+ points: rect(-6, -3, -3.4, 3),
84
+ color: "var(--stage-muted)",
85
+ fill: "var(--stage-bg)",
86
+ fillOpacity: .5,
87
+ weight: 1.5
88
+ }),
89
+ /* @__PURE__ */ jsx(Polygon, {
90
+ points: rect(3.4, -3, 6, 3),
91
+ color: "var(--stage-muted)",
92
+ fill: "var(--stage-bg)",
93
+ fillOpacity: .5,
94
+ weight: 1.5
95
+ }),
96
+ /* @__PURE__ */ jsx(Label, {
97
+ x: -4.7,
98
+ y: 3.35,
99
+ text: "inputs",
100
+ size: 11,
101
+ color: "var(--stage-muted)"
102
+ }),
103
+ /* @__PURE__ */ jsx(Label, {
104
+ x: 4.7,
105
+ y: 3.35,
106
+ text: "outputs",
107
+ size: 11,
108
+ color: "var(--stage-muted)"
109
+ }),
110
+ ys.map((y, i) => /* @__PURE__ */ jsxs("g", { children: [
111
+ inputs[i] != null && /* @__PURE__ */ jsx(Label, {
112
+ x: -4.7,
113
+ y,
114
+ text: String(inputs[i]),
115
+ size: 15
116
+ }),
117
+ outputs[i] != null && /* @__PURE__ */ jsx(Label, {
118
+ x: 4.7,
119
+ y,
120
+ text: String(outputs[i]),
121
+ size: 15
122
+ }),
123
+ inputs[i] != null && outputs[i] != null && /* @__PURE__ */ jsx(Segment, {
124
+ from: {
125
+ x: -3.4,
126
+ y
127
+ },
128
+ to: {
129
+ x: 3.4,
130
+ y
131
+ },
132
+ color: glow,
133
+ weight: 2,
134
+ dashed: true
135
+ })
136
+ ] }, i))
137
+ ]
138
+ })] });
139
+ return /* @__PURE__ */ jsx(LabFrame, {
140
+ prompt,
141
+ controls: /* @__PURE__ */ jsxs(ControlBar, { children: [
142
+ /* @__PURE__ */ jsx("div", {
143
+ style: {
144
+ display: "grid",
145
+ gridTemplateColumns: "1fr 1fr",
146
+ gap: 8
147
+ },
148
+ children: choices.map((ch) => /* @__PURE__ */ jsx(Chip, {
149
+ selected: sel === ch,
150
+ onClick: () => {
151
+ setSel(ch);
152
+ setResult(null);
153
+ },
154
+ children: ch
155
+ }, ch))
156
+ }),
157
+ /* @__PURE__ */ jsx(CheckButton, {
158
+ onClick: check,
159
+ disabled: !sel,
160
+ children: "Check"
161
+ }),
162
+ result === "correct" && /* @__PURE__ */ jsx(StatusPill, {
163
+ ok: true,
164
+ children: "✓ Correct!"
165
+ }),
166
+ result === "wrong" && /* @__PURE__ */ jsx(StatusPill, {
167
+ ok: false,
168
+ children: "Not quite — try another rule"
169
+ })
170
+ ] }),
171
+ footer: /* @__PURE__ */ jsx(LiveRegion, { children: result === "correct" ? "Correct." : result === "wrong" ? "Incorrect, try again." : "" }),
172
+ children: figure
173
+ });
174
+ }
175
+
176
+ //#endregion
177
+ export { FunctionMachineLab };
@@ -0,0 +1,23 @@
1
+ import { ReactNode } from "react";
2
+
3
+ //#region src/math/gradient-descent.d.ts
4
+ interface GradientDescentProps {
5
+ /** Loss surface f(x, y), e.g. `x^2 + 2*y^2` or `x^2 + y^2 - x*y`. */
6
+ equation?: string;
7
+ /** Visible square-ish region [min,max] for both axes. Default [-3, 3]. */
8
+ range?: [number, number];
9
+ start?: [number, number];
10
+ learningRate?: number;
11
+ title?: string;
12
+ height?: number;
13
+ }
14
+ declare function GradientDescent({
15
+ equation,
16
+ range,
17
+ start,
18
+ learningRate,
19
+ title,
20
+ height
21
+ }?: GradientDescentProps): ReactNode;
22
+ //#endregion
23
+ export { GradientDescent, GradientDescentProps };
@@ -0,0 +1,473 @@
1
+ 'use client';
2
+
3
+ import { clamp, lerp } from "../core/util.mjs";
4
+ import { Tex as Tex$1 } from "../core/tex.mjs";
5
+ import { CheckButton, Slider } from "../kit/controls.mjs";
6
+ import { ControlBar, Field, LabFrame } from "../kit/frame.mjs";
7
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ import { CanvasLayer, compileExpr, differentiate, evaluate, simplify, toLatex, useFrameLoop, useInView } from "@classytic/stage";
10
+
11
+ //#region src/math/gradient-descent.tsx
12
+ /**
13
+ * GradientDescent — the calculus that powers machine learning, made visible.
14
+ *
15
+ * Plots a 2-variable "loss surface" f(x, y) as a heatmap, then walks downhill by
16
+ * the rule that trains every neural net: step opposite the gradient,
17
+ * (x, y) ← (x, y) − lr · ∇f, ∇f = [∂f/∂x, ∂f/∂y].
18
+ *
19
+ * The gradient is the engine's EXACT symbolic differentiator —
20
+ * `differentiate(ast, 'x')` and `differentiate(ast, 'y')` — proving the scalar
21
+ * expr engine already does multivariable partials (numerical fallback otherwise).
22
+ *
23
+ * This is a genuine HIGH-ELEMENT-COUNT figure (a per-pixel-cell heatmap), so it
24
+ * renders on the engine's `<CanvasLayer>` (zero-dep raw Canvas2D, HiDPI, shares
25
+ * the coordinate system + clock) instead of one SVG node per cell — and instead
26
+ * of a heavy GPU dependency. Everything ELSE (controls, KaTeX, theming) is the
27
+ * same kit every other lab uses. Drag the start point, tune the rate, watch it
28
+ * converge — or diverge.
29
+ */
30
+ const VIRIDIS = [
31
+ [
32
+ 68,
33
+ 1,
34
+ 84
35
+ ],
36
+ [
37
+ 59,
38
+ 82,
39
+ 139
40
+ ],
41
+ [
42
+ 33,
43
+ 145,
44
+ 140
45
+ ],
46
+ [
47
+ 94,
48
+ 201,
49
+ 98
50
+ ],
51
+ [
52
+ 253,
53
+ 231,
54
+ 37
55
+ ]
56
+ ];
57
+ function viridis(t) {
58
+ const x = clamp(t, 0, 1) * (VIRIDIS.length - 1);
59
+ const i = Math.min(VIRIDIS.length - 2, Math.floor(x)), f = x - i;
60
+ const a = VIRIDIS[i], b = VIRIDIS[i + 1];
61
+ return `rgb(${Math.round(lerp(a[0], b[0], f))},${Math.round(lerp(a[1], b[1], f))},${Math.round(lerp(a[2], b[2], f))})`;
62
+ }
63
+ /** Iso-loss contour lines via marching squares on a lattice-sampled value grid. */
64
+ function contours(ctx, vals, cols, rows, cell, levels, color) {
65
+ ctx.save();
66
+ ctx.strokeStyle = color;
67
+ ctx.lineWidth = 1;
68
+ ctx.beginPath();
69
+ const px = (col) => col * cell, py = (r) => r * cell;
70
+ for (const L of levels) for (let r = 0; r < rows - 1; r++) for (let col = 0; col < cols - 1; col++) {
71
+ const tl = vals[r * cols + col], tr = vals[r * cols + col + 1], br = vals[(r + 1) * cols + col + 1], bl = vals[(r + 1) * cols + col];
72
+ if (!(Number.isFinite(tl) && Number.isFinite(tr) && Number.isFinite(br) && Number.isFinite(bl))) continue;
73
+ const code = (tl >= L ? 8 : 0) | (tr >= L ? 4 : 0) | (br >= L ? 2 : 0) | (bl >= L ? 1 : 0);
74
+ if (code === 0 || code === 15) continue;
75
+ const top = () => [px(col) + cell * ((L - tl) / (tr - tl)), py(r)];
76
+ const bot = () => [px(col) + cell * ((L - bl) / (br - bl)), py(r + 1)];
77
+ const lft = () => [px(col), py(r) + cell * ((L - tl) / (bl - tl))];
78
+ const rgt = () => [px(col + 1), py(r) + cell * ((L - tr) / (br - tr))];
79
+ const seg = (a, b) => {
80
+ ctx.moveTo(a[0], a[1]);
81
+ ctx.lineTo(b[0], b[1]);
82
+ };
83
+ switch (code) {
84
+ case 1:
85
+ case 14:
86
+ seg(lft(), bot());
87
+ break;
88
+ case 2:
89
+ case 13:
90
+ seg(bot(), rgt());
91
+ break;
92
+ case 3:
93
+ case 12:
94
+ seg(lft(), rgt());
95
+ break;
96
+ case 4:
97
+ case 11:
98
+ seg(top(), rgt());
99
+ break;
100
+ case 6:
101
+ case 9:
102
+ seg(top(), bot());
103
+ break;
104
+ case 7:
105
+ case 8:
106
+ seg(lft(), top());
107
+ break;
108
+ case 5:
109
+ seg(lft(), top());
110
+ seg(bot(), rgt());
111
+ break;
112
+ case 10:
113
+ seg(lft(), bot());
114
+ seg(top(), rgt());
115
+ break;
116
+ }
117
+ }
118
+ ctx.stroke();
119
+ ctx.restore();
120
+ }
121
+ /** A negative-gradient step arrow, in math coords, via raw ctx. */
122
+ function drawArrow(ctx, c, x0, y0, x1, y1, color) {
123
+ const [ax, ay] = c.toPx(x0, y0);
124
+ const [bx, by] = c.toPx(x1, y1);
125
+ ctx.strokeStyle = color;
126
+ ctx.fillStyle = color;
127
+ ctx.lineWidth = 2.5;
128
+ ctx.beginPath();
129
+ ctx.moveTo(ax, ay);
130
+ ctx.lineTo(bx, by);
131
+ ctx.stroke();
132
+ const ang = Math.atan2(by - ay, bx - ax), head = 8;
133
+ ctx.beginPath();
134
+ ctx.moveTo(bx, by);
135
+ ctx.lineTo(bx - head * Math.cos(ang - .4), by - head * Math.sin(ang - .4));
136
+ ctx.lineTo(bx - head * Math.cos(ang + .4), by - head * Math.sin(ang + .4));
137
+ ctx.closePath();
138
+ ctx.fill();
139
+ }
140
+ function GradientDescent({ equation = "x^2 + 2*y^2", range = [-3, 3], start = [2.4, 1.8], learningRate = .1, title = "Gradient descent", height = 360 } = {}) {
141
+ const [lo, hi] = range;
142
+ const [lr, setLr] = useState(learningRate);
143
+ const [start0, setStart0] = useState([clamp(start[0], lo, hi), clamp(start[1], lo, hi)]);
144
+ const [path, setPath] = useState([start0]);
145
+ const [running, setRunning] = useState(false);
146
+ const acc = useRef(0);
147
+ const { ref: viewRef, inView } = useInView();
148
+ const sx = clamp(start[0], lo, hi);
149
+ const sy = clamp(start[1], lo, hi);
150
+ useEffect(() => {
151
+ setStart0([sx, sy]);
152
+ setPath([[sx, sy]]);
153
+ setRunning(false);
154
+ }, [sx, sy]);
155
+ useEffect(() => {
156
+ setLr(learningRate);
157
+ }, [learningRate]);
158
+ const model = useMemo(() => {
159
+ const res = compileExpr(equation);
160
+ if (res.error || !res.ast) return {
161
+ ok: false,
162
+ error: res.error ?? "Invalid expression"
163
+ };
164
+ const ast = res.ast;
165
+ const f = (x, y) => evaluate(ast, {
166
+ x,
167
+ y
168
+ });
169
+ const partial = (vn) => {
170
+ let node = null;
171
+ try {
172
+ const d = differentiate(ast, vn);
173
+ node = d ? simplify(d) : null;
174
+ } catch {
175
+ node = null;
176
+ }
177
+ if (node) return (x, y) => evaluate(node, {
178
+ x,
179
+ y
180
+ });
181
+ const h = 1e-5;
182
+ return (x, y) => vn === "x" ? (f(x + h, y) - f(x - h, y)) / (2 * h) : (f(x, y + h) - f(x, y - h)) / (2 * h);
183
+ };
184
+ const dxNode = (() => {
185
+ try {
186
+ const d = differentiate(ast, "x");
187
+ return d ? simplify(d) : null;
188
+ } catch {
189
+ return null;
190
+ }
191
+ })();
192
+ const dyNode = (() => {
193
+ try {
194
+ const d = differentiate(ast, "y");
195
+ return d ? simplify(d) : null;
196
+ } catch {
197
+ return null;
198
+ }
199
+ })();
200
+ return {
201
+ ok: true,
202
+ f,
203
+ fx: partial("x"),
204
+ fy: partial("y"),
205
+ fLatex: toLatex(ast),
206
+ dxLatex: dxNode ? toLatex(dxNode) : null,
207
+ dyLatex: dyNode ? toLatex(dyNode) : null
208
+ };
209
+ }, [equation]);
210
+ const view = useMemo(() => ({
211
+ xMin: lo,
212
+ xMax: hi,
213
+ yMin: lo,
214
+ yMax: hi
215
+ }), [lo, hi]);
216
+ const coordsOptions = useMemo(() => ({ pad: 8 }), []);
217
+ const cur = path[path.length - 1] ?? start0;
218
+ const draw = useCallback((ctx, c) => {
219
+ if (!model.ok) return;
220
+ const { f } = model;
221
+ const accent = getComputedStyle(ctx.canvas).getPropertyValue("--stage-accent").trim() || "#5b8cff";
222
+ const cell = 6;
223
+ const cols = Math.ceil(c.width / cell) + 1;
224
+ const rows = Math.ceil(c.height / cell) + 1;
225
+ const vals = new Float64Array(cols * rows);
226
+ let vmin = Infinity, vmax = -Infinity;
227
+ for (let r = 0; r < rows; r++) for (let col = 0; col < cols; col++) {
228
+ const [mx, my] = c.toMath(col * cell, r * cell);
229
+ const v = f(mx, my);
230
+ vals[r * cols + col] = v;
231
+ if (Number.isFinite(v)) {
232
+ if (v < vmin) vmin = v;
233
+ if (v > vmax) vmax = v;
234
+ }
235
+ }
236
+ const span = vmax - vmin || 1;
237
+ for (let r = 0; r < rows - 1; r++) for (let col = 0; col < cols - 1; col++) {
238
+ const v = vals[r * cols + col];
239
+ ctx.fillStyle = viridis(Number.isFinite(v) ? clamp((v - vmin) / span, 0, 1) : 0);
240
+ ctx.fillRect(col * cell, r * cell, 7, 7);
241
+ }
242
+ contours(ctx, vals, cols, rows, cell, Array.from({ length: 11 }, (_, i) => vmin + (i + 1) / 12 * span), "rgba(0,0,0,0.32)");
243
+ ctx.save();
244
+ ctx.globalAlpha = .3;
245
+ ctx.strokeStyle = "rgba(255,255,255,0.7)";
246
+ ctx.lineWidth = 1;
247
+ const oy = c.toPx(0, 0)[1], ox = c.toPx(0, 0)[0];
248
+ ctx.beginPath();
249
+ ctx.moveTo(c.toPx(lo, 0)[0], oy);
250
+ ctx.lineTo(c.toPx(hi, 0)[0], oy);
251
+ ctx.moveTo(ox, c.toPx(0, lo)[1]);
252
+ ctx.lineTo(ox, c.toPx(0, hi)[1]);
253
+ ctx.stroke();
254
+ ctx.restore();
255
+ if (path.length > 1) {
256
+ ctx.lineJoin = "round";
257
+ ctx.lineCap = "round";
258
+ const trace = () => {
259
+ ctx.beginPath();
260
+ path.forEach((p, i) => {
261
+ const [px, py] = c.toPx(p[0], p[1]);
262
+ if (i === 0) ctx.moveTo(px, py);
263
+ else ctx.lineTo(px, py);
264
+ });
265
+ ctx.stroke();
266
+ };
267
+ ctx.strokeStyle = "rgba(0,0,0,0.55)";
268
+ ctx.lineWidth = 4.5;
269
+ trace();
270
+ ctx.strokeStyle = "rgba(255,255,255,0.95)";
271
+ ctx.lineWidth = 2;
272
+ trace();
273
+ }
274
+ for (const p of path) {
275
+ const [px, py] = c.toPx(p[0], p[1]);
276
+ ctx.beginPath();
277
+ ctx.arc(px, py, 2.4, 0, Math.PI * 2);
278
+ ctx.fillStyle = "rgba(255,255,255,0.92)";
279
+ ctx.fill();
280
+ ctx.lineWidth = 1;
281
+ ctx.strokeStyle = "rgba(0,0,0,0.45)";
282
+ ctx.stroke();
283
+ }
284
+ const [cxx, cyy] = cur;
285
+ const gx = model.fx(cxx, cyy), gy = model.fy(cxx, cyy), gmag = Math.hypot(gx, gy);
286
+ if (gmag > 1e-4) {
287
+ const scale = Math.min(.9, .9 * (hi - lo) / 6 / gmag);
288
+ ctx.save();
289
+ ctx.shadowColor = "rgba(0,0,0,0.65)";
290
+ ctx.shadowBlur = 4;
291
+ drawArrow(ctx, c, cxx, cyy, cxx - gx * scale, cyy - gy * scale, "#ffffff");
292
+ ctx.restore();
293
+ }
294
+ const [pcx, pcy] = c.toPx(cxx, cyy);
295
+ ctx.beginPath();
296
+ ctx.arc(pcx, pcy, 7.5, 0, Math.PI * 2);
297
+ ctx.fillStyle = "#fff";
298
+ ctx.fill();
299
+ ctx.beginPath();
300
+ ctx.arc(pcx, pcy, 5, 0, Math.PI * 2);
301
+ ctx.fillStyle = accent;
302
+ ctx.fill();
303
+ }, [
304
+ model,
305
+ path,
306
+ cur,
307
+ lo,
308
+ hi
309
+ ]);
310
+ useFrameLoop((frame) => {
311
+ if (!model.ok) return;
312
+ acc.current += frame.dtMs;
313
+ if (acc.current < 90) return;
314
+ acc.current = 0;
315
+ setPath((prev) => {
316
+ const last = prev[prev.length - 1];
317
+ if (!last || prev.length > 250) {
318
+ setRunning(false);
319
+ return prev;
320
+ }
321
+ const gx = model.fx(last[0], last[1]);
322
+ const gy = model.fy(last[0], last[1]);
323
+ if (Math.hypot(gx, gy) < .001) {
324
+ setRunning(false);
325
+ return prev;
326
+ }
327
+ const next = [last[0] - lr * gx, last[1] - lr * gy];
328
+ if (Math.abs(next[0]) > 1e3 || Math.abs(next[1]) > 1e3) {
329
+ setRunning(false);
330
+ return prev;
331
+ }
332
+ return [...prev, next];
333
+ });
334
+ }, { running: running && model.ok && inView });
335
+ const step = () => {
336
+ if (!model.ok) return;
337
+ setRunning(false);
338
+ setPath((prev) => {
339
+ const last = prev[prev.length - 1];
340
+ if (!last) return prev;
341
+ const gx = model.fx(last[0], last[1]);
342
+ const gy = model.fy(last[0], last[1]);
343
+ return [...prev, [last[0] - lr * gx, last[1] - lr * gy]];
344
+ });
345
+ };
346
+ if (!model.ok) return /* @__PURE__ */ jsxs("div", {
347
+ className: "not-prose",
348
+ children: [title && /* @__PURE__ */ jsx("p", {
349
+ style: {
350
+ fontWeight: 600,
351
+ marginBottom: 6
352
+ },
353
+ children: title
354
+ }), /* @__PURE__ */ jsxs("div", {
355
+ style: {
356
+ padding: "12px",
357
+ fontSize: 13,
358
+ color: "var(--stage-danger)"
359
+ },
360
+ children: [
361
+ "“",
362
+ equation,
363
+ "” — ",
364
+ model.error
365
+ ]
366
+ })]
367
+ });
368
+ const figure = /* @__PURE__ */ jsx("div", {
369
+ ref: viewRef,
370
+ className: "lab-playwrap",
371
+ children: /* @__PURE__ */ jsx(CanvasLayer, {
372
+ view,
373
+ height,
374
+ coordsOptions,
375
+ draw,
376
+ onPointerMath: (m) => {
377
+ setRunning(false);
378
+ const p = [clamp(m[0], lo, hi), clamp(m[1], lo, hi)];
379
+ setStart0(p);
380
+ setPath([p]);
381
+ },
382
+ ariaLabel: `Gradient descent on f(x,y) = ${equation}; drag to set the start point`
383
+ })
384
+ });
385
+ const controls = /* @__PURE__ */ jsxs(ControlBar, { children: [
386
+ /* @__PURE__ */ jsx(CheckButton, {
387
+ onClick: () => setRunning((r) => !r),
388
+ children: running ? "Pause" : "Run"
389
+ }),
390
+ /* @__PURE__ */ jsx("button", {
391
+ type: "button",
392
+ className: "lab-chip",
393
+ onClick: step,
394
+ children: "Step"
395
+ }),
396
+ /* @__PURE__ */ jsx("button", {
397
+ type: "button",
398
+ className: "lab-chip",
399
+ onClick: () => {
400
+ setRunning(false);
401
+ setPath([start0]);
402
+ },
403
+ children: "Reset"
404
+ }),
405
+ /* @__PURE__ */ jsx(Field, {
406
+ label: "learning rate",
407
+ value: /* @__PURE__ */ jsx("strong", {
408
+ style: { fontVariantNumeric: "tabular-nums" },
409
+ children: lr.toFixed(2)
410
+ }),
411
+ children: /* @__PURE__ */ jsx(Slider, {
412
+ value: lr,
413
+ min: .01,
414
+ max: .6,
415
+ step: .01,
416
+ onChange: setLr,
417
+ ariaLabel: "learning rate"
418
+ })
419
+ }),
420
+ /* @__PURE__ */ jsxs("span", {
421
+ style: {
422
+ marginLeft: "auto",
423
+ display: "inline-flex",
424
+ gap: 16,
425
+ fontVariantNumeric: "tabular-nums"
426
+ },
427
+ children: [
428
+ /* @__PURE__ */ jsxs("span", { children: ["x ", cur[0].toFixed(2)] }),
429
+ /* @__PURE__ */ jsxs("span", { children: ["y ", cur[1].toFixed(2)] }),
430
+ /* @__PURE__ */ jsxs("span", { children: ["f ", model.f(cur[0], cur[1]).toFixed(3)] }),
431
+ /* @__PURE__ */ jsxs("span", { children: ["steps ", path.length - 1] })
432
+ ]
433
+ })
434
+ ] });
435
+ const footer = /* @__PURE__ */ jsxs("div", {
436
+ style: {
437
+ display: "flex",
438
+ flexWrap: "wrap",
439
+ gap: "4px 16px",
440
+ padding: "6px 2px",
441
+ fontSize: 13
442
+ },
443
+ children: [
444
+ /* @__PURE__ */ jsxs("span", {
445
+ style: {
446
+ display: "inline-flex",
447
+ alignItems: "center",
448
+ gap: 6
449
+ },
450
+ children: [
451
+ /* @__PURE__ */ jsx("span", {
452
+ style: { opacity: .6 },
453
+ children: "f ="
454
+ }),
455
+ " ",
456
+ /* @__PURE__ */ jsx(Tex$1, { tex: model.fLatex })
457
+ ]
458
+ }),
459
+ model.dxLatex && /* @__PURE__ */ jsx(Tex$1, { tex: `\\frac{\\partial f}{\\partial x} = ${model.dxLatex}` }),
460
+ model.dyLatex && /* @__PURE__ */ jsx(Tex$1, { tex: `\\frac{\\partial f}{\\partial y} = ${model.dyLatex}` })
461
+ ]
462
+ });
463
+ return /* @__PURE__ */ jsx(LabFrame, {
464
+ title: title || void 0,
465
+ prompt: "Drag the start point, set the learning rate, and step downhill along −∇f. Too big a rate overshoots.",
466
+ controls,
467
+ footer,
468
+ children: figure
469
+ });
470
+ }
471
+
472
+ //#endregion
473
+ export { GradientDescent };
@@ -0,0 +1 @@
1
+ import { GraphEquation, GraphParam, Grapher, GrapherProps } from "./preset.mjs";
@@ -0,0 +1,40 @@
1
+ import { ReactNode } from "react";
2
+
3
+ //#region src/math/grapher/preset.d.ts
4
+ interface GraphEquation {
5
+ /** Formula in `x` and any params, e.g. `a*sin(b*x + c)`. */
6
+ expr: string;
7
+ color?: string;
8
+ }
9
+ interface GraphParam {
10
+ name: string;
11
+ min: number;
12
+ max: number;
13
+ step?: number;
14
+ value: number;
15
+ }
16
+ interface GrapherProps {
17
+ equations?: (GraphEquation | string)[] | string;
18
+ params?: GraphParam[];
19
+ xRange?: [number, number];
20
+ yRange?: [number, number] | 'auto';
21
+ /** `log` plots log₁₀(y) with decade ticks — for exponentials/rates. */
22
+ yScale?: 'linear' | 'log';
23
+ title?: string;
24
+ subtitle?: string;
25
+ height?: number;
26
+ grid?: boolean;
27
+ }
28
+ declare function Grapher({
29
+ equations,
30
+ params,
31
+ xRange,
32
+ yRange,
33
+ yScale,
34
+ title,
35
+ subtitle,
36
+ height,
37
+ grid
38
+ }?: GrapherProps): ReactNode;
39
+ //#endregion
40
+ export { GraphEquation, GraphParam, Grapher, GrapherProps };