@teachinglab/omd 0.6.1 → 0.6.2

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 (198) hide show
  1. package/README.md +257 -251
  2. package/README.old.md +137 -137
  3. package/canvas/core/canvasConfig.js +202 -202
  4. package/canvas/drawing/segment.js +167 -167
  5. package/canvas/drawing/stroke.js +385 -385
  6. package/canvas/events/eventManager.js +444 -444
  7. package/canvas/events/pointerEventHandler.js +262 -262
  8. package/canvas/index.js +48 -48
  9. package/canvas/tools/PointerTool.js +71 -71
  10. package/canvas/tools/tool.js +222 -222
  11. package/canvas/utils/boundingBox.js +377 -377
  12. package/canvas/utils/mathUtils.js +258 -258
  13. package/docs/api/configuration-options.md +198 -198
  14. package/docs/api/eventManager.md +82 -82
  15. package/docs/api/focusFrameManager.md +144 -144
  16. package/docs/api/index.md +105 -105
  17. package/docs/api/main.md +62 -62
  18. package/docs/api/omdBinaryExpressionNode.md +86 -86
  19. package/docs/api/omdCanvas.md +83 -83
  20. package/docs/api/omdConfigManager.md +112 -112
  21. package/docs/api/omdConstantNode.md +52 -52
  22. package/docs/api/omdDisplay.md +87 -87
  23. package/docs/api/omdEquationNode.md +174 -174
  24. package/docs/api/omdEquationSequenceNode.md +258 -258
  25. package/docs/api/omdEquationStack.md +192 -192
  26. package/docs/api/omdFunctionNode.md +82 -82
  27. package/docs/api/omdGroupNode.md +78 -78
  28. package/docs/api/omdHelpers.md +87 -87
  29. package/docs/api/omdLeafNode.md +85 -85
  30. package/docs/api/omdNode.md +201 -201
  31. package/docs/api/omdOperationDisplayNode.md +117 -117
  32. package/docs/api/omdOperatorNode.md +91 -91
  33. package/docs/api/omdParenthesisNode.md +133 -133
  34. package/docs/api/omdPopup.md +191 -191
  35. package/docs/api/omdPowerNode.md +131 -131
  36. package/docs/api/omdRationalNode.md +144 -144
  37. package/docs/api/omdSequenceNode.md +128 -128
  38. package/docs/api/omdSimplification.md +78 -78
  39. package/docs/api/omdSqrtNode.md +144 -144
  40. package/docs/api/omdStepVisualizer.md +146 -146
  41. package/docs/api/omdStepVisualizerHighlighting.md +65 -65
  42. package/docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
  43. package/docs/api/omdStepVisualizerLayout.md +70 -70
  44. package/docs/api/omdStepVisualizerNodeUtils.md +140 -140
  45. package/docs/api/omdStepVisualizerTextBoxes.md +76 -76
  46. package/docs/api/omdToolbar.md +130 -130
  47. package/docs/api/omdTranscriptionService.md +95 -95
  48. package/docs/api/omdTreeDiff.md +169 -169
  49. package/docs/api/omdUnaryExpressionNode.md +137 -137
  50. package/docs/api/omdUtilities.md +82 -82
  51. package/docs/api/omdVariableNode.md +123 -123
  52. package/docs/api/selectTool.md +74 -74
  53. package/docs/api/simplificationEngine.md +97 -97
  54. package/docs/api/simplificationRules.md +76 -76
  55. package/docs/api/simplificationUtils.md +64 -64
  56. package/docs/api/transcribe.md +43 -43
  57. package/docs/api-reference.md +85 -85
  58. package/docs/index.html +453 -453
  59. package/docs/index.md +38 -38
  60. package/docs/omd-objects.md +258 -258
  61. package/index.js +79 -79
  62. package/jsvg/index.js +3 -0
  63. package/jsvg/jsvg.js +898 -898
  64. package/jsvg/jsvgComponents.js +357 -358
  65. package/npm-docs/DOCUMENTATION_SUMMARY.md +220 -220
  66. package/npm-docs/README.md +251 -251
  67. package/npm-docs/api/api-reference.md +85 -85
  68. package/npm-docs/api/configuration-options.md +198 -198
  69. package/npm-docs/api/eventManager.md +82 -82
  70. package/npm-docs/api/expression-nodes.md +561 -561
  71. package/npm-docs/api/focusFrameManager.md +144 -144
  72. package/npm-docs/api/index.md +105 -105
  73. package/npm-docs/api/main.md +62 -62
  74. package/npm-docs/api/omdBinaryExpressionNode.md +86 -86
  75. package/npm-docs/api/omdCanvas.md +83 -83
  76. package/npm-docs/api/omdConfigManager.md +112 -112
  77. package/npm-docs/api/omdConstantNode.md +52 -52
  78. package/npm-docs/api/omdDisplay.md +87 -87
  79. package/npm-docs/api/omdEquationNode.md +174 -174
  80. package/npm-docs/api/omdEquationSequenceNode.md +258 -258
  81. package/npm-docs/api/omdEquationStack.md +192 -192
  82. package/npm-docs/api/omdFunctionNode.md +82 -82
  83. package/npm-docs/api/omdGroupNode.md +78 -78
  84. package/npm-docs/api/omdHelpers.md +87 -87
  85. package/npm-docs/api/omdLeafNode.md +85 -85
  86. package/npm-docs/api/omdNode.md +201 -201
  87. package/npm-docs/api/omdOperationDisplayNode.md +117 -117
  88. package/npm-docs/api/omdOperatorNode.md +91 -91
  89. package/npm-docs/api/omdParenthesisNode.md +133 -133
  90. package/npm-docs/api/omdPopup.md +191 -191
  91. package/npm-docs/api/omdPowerNode.md +131 -131
  92. package/npm-docs/api/omdRationalNode.md +144 -144
  93. package/npm-docs/api/omdSequenceNode.md +128 -128
  94. package/npm-docs/api/omdSimplification.md +78 -78
  95. package/npm-docs/api/omdSqrtNode.md +144 -144
  96. package/npm-docs/api/omdStepVisualizer.md +146 -146
  97. package/npm-docs/api/omdStepVisualizerHighlighting.md +65 -65
  98. package/npm-docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
  99. package/npm-docs/api/omdStepVisualizerLayout.md +70 -70
  100. package/npm-docs/api/omdStepVisualizerNodeUtils.md +140 -140
  101. package/npm-docs/api/omdStepVisualizerTextBoxes.md +76 -76
  102. package/npm-docs/api/omdToolbar.md +130 -130
  103. package/npm-docs/api/omdTranscriptionService.md +95 -95
  104. package/npm-docs/api/omdTreeDiff.md +169 -169
  105. package/npm-docs/api/omdUnaryExpressionNode.md +137 -137
  106. package/npm-docs/api/omdUtilities.md +82 -82
  107. package/npm-docs/api/omdVariableNode.md +123 -123
  108. package/npm-docs/api/selectTool.md +74 -74
  109. package/npm-docs/api/simplificationEngine.md +97 -97
  110. package/npm-docs/api/simplificationRules.md +76 -76
  111. package/npm-docs/api/simplificationUtils.md +64 -64
  112. package/npm-docs/api/transcribe.md +43 -43
  113. package/npm-docs/guides/equations.md +854 -854
  114. package/npm-docs/guides/factory-functions.md +354 -354
  115. package/npm-docs/guides/getting-started.md +318 -318
  116. package/npm-docs/guides/quick-examples.md +525 -525
  117. package/npm-docs/guides/visualizations.md +682 -682
  118. package/npm-docs/index.html +12 -0
  119. package/npm-docs/json-schemas.md +826 -826
  120. package/omd/config/omdConfigManager.js +279 -267
  121. package/omd/core/index.js +158 -158
  122. package/omd/core/omdEquationStack.js +546 -546
  123. package/omd/core/omdUtilities.js +113 -113
  124. package/omd/display/omdDisplay.js +969 -962
  125. package/omd/display/omdToolbar.js +501 -501
  126. package/omd/nodes/omdBinaryExpressionNode.js +459 -459
  127. package/omd/nodes/omdConstantNode.js +141 -141
  128. package/omd/nodes/omdEquationNode.js +1327 -1327
  129. package/omd/nodes/omdFunctionNode.js +351 -351
  130. package/omd/nodes/omdGroupNode.js +67 -67
  131. package/omd/nodes/omdLeafNode.js +76 -76
  132. package/omd/nodes/omdNode.js +556 -556
  133. package/omd/nodes/omdOperationDisplayNode.js +321 -321
  134. package/omd/nodes/omdOperatorNode.js +108 -108
  135. package/omd/nodes/omdParenthesisNode.js +292 -292
  136. package/omd/nodes/omdPowerNode.js +235 -235
  137. package/omd/nodes/omdRationalNode.js +295 -295
  138. package/omd/nodes/omdSqrtNode.js +307 -307
  139. package/omd/nodes/omdUnaryExpressionNode.js +227 -227
  140. package/omd/nodes/omdVariableNode.js +122 -122
  141. package/omd/simplification/omdSimplification.js +140 -140
  142. package/omd/simplification/omdSimplificationEngine.js +887 -887
  143. package/omd/simplification/package.json +5 -5
  144. package/omd/simplification/rules/binaryRules.js +1037 -1037
  145. package/omd/simplification/rules/functionRules.js +111 -111
  146. package/omd/simplification/rules/index.js +48 -48
  147. package/omd/simplification/rules/parenthesisRules.js +19 -19
  148. package/omd/simplification/rules/powerRules.js +143 -143
  149. package/omd/simplification/rules/rationalRules.js +725 -725
  150. package/omd/simplification/rules/sqrtRules.js +48 -48
  151. package/omd/simplification/rules/unaryRules.js +37 -37
  152. package/omd/simplification/simplificationRules.js +31 -31
  153. package/omd/simplification/simplificationUtils.js +1055 -1055
  154. package/omd/step-visualizer/omdStepVisualizer.js +947 -947
  155. package/omd/step-visualizer/omdStepVisualizerHighlighting.js +246 -246
  156. package/omd/step-visualizer/omdStepVisualizerLayout.js +892 -892
  157. package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +200 -200
  158. package/omd/utils/aiNextEquationStep.js +106 -106
  159. package/omd/utils/omdNodeOverlay.js +638 -638
  160. package/omd/utils/omdPopup.js +1203 -1203
  161. package/omd/utils/omdStepVisualizerInteractiveSteps.js +684 -684
  162. package/omd/utils/omdStepVisualizerNodeUtils.js +267 -267
  163. package/omd/utils/omdTranscriptionService.js +123 -123
  164. package/omd/utils/omdTreeDiff.js +733 -733
  165. package/package.json +59 -57
  166. package/readme.html +184 -120
  167. package/src/index.js +74 -74
  168. package/src/json-schemas.md +576 -576
  169. package/src/omd-json-samples.js +147 -147
  170. package/src/omdApp.js +391 -391
  171. package/src/omdAppCanvas.js +335 -335
  172. package/src/omdBalanceHanger.js +199 -199
  173. package/src/omdColor.js +13 -13
  174. package/src/omdCoordinatePlane.js +541 -541
  175. package/src/omdExpression.js +115 -115
  176. package/src/omdFactory.js +150 -150
  177. package/src/omdFunction.js +114 -114
  178. package/src/omdMetaExpression.js +290 -290
  179. package/src/omdNaturalExpression.js +563 -563
  180. package/src/omdNode.js +383 -383
  181. package/src/omdNumber.js +52 -52
  182. package/src/omdNumberLine.js +114 -112
  183. package/src/omdNumberTile.js +118 -118
  184. package/src/omdOperator.js +72 -72
  185. package/src/omdPowerExpression.js +91 -91
  186. package/src/omdProblem.js +259 -259
  187. package/src/omdRatioChart.js +251 -251
  188. package/src/omdRationalExpression.js +114 -114
  189. package/src/omdSampleData.js +215 -215
  190. package/src/omdShapes.js +512 -512
  191. package/src/omdSpinner.js +151 -151
  192. package/src/omdString.js +49 -49
  193. package/src/omdTable.js +498 -498
  194. package/src/omdTapeDiagram.js +244 -244
  195. package/src/omdTerm.js +91 -91
  196. package/src/omdTileEquation.js +349 -349
  197. package/src/omdUtils.js +84 -84
  198. package/src/omdVariable.js +51 -51
@@ -1,854 +1,854 @@
1
- # Equations & Expressions Guide
2
-
3
- This guide covers all equation and expression components in OMD, from basic numbers and variables to complex step-by-step solutions.
4
-
5
- ## Table of Contents
6
-
7
- 1. [Core Components](#core-components)
8
- 2. [Advanced Expressions](#advanced-expressions)
9
- 3. [Step-by-Step Solutions](#step-by-step-solutions)
10
- 4. [Expression Parsing](#expression-parsing)
11
-
12
- ---
13
-
14
- ## Core Components
15
-
16
- ### Numbers
17
-
18
- `omdNumber` represents numeric constants.
19
-
20
- #### Basic Usage
21
-
22
- ```javascript
23
- import { omdNumber } from '@teachinglab/omd';
24
-
25
- const num = new omdNumber();
26
- num.loadFromJSON({ value: 42 });
27
- ```
28
-
29
- #### JSON Format
30
-
31
- ```json
32
- {
33
- "omdType": "number",
34
- "value": 42
35
- }
36
- ```
37
-
38
- ---
39
-
40
- ### Variables
41
-
42
- `omdVariable` represents algebraic variables.
43
-
44
- #### Basic Usage
45
-
46
- ```javascript
47
- import { omdVariable } from '@teachinglab/omd';
48
-
49
- const variable = new omdVariable();
50
- variable.loadFromJSON({ name: "x" });
51
- ```
52
-
53
- #### JSON Format
54
-
55
- ```json
56
- {
57
- "omdType": "variable",
58
- "name": "x"
59
- }
60
- ```
61
-
62
- ---
63
-
64
- ### Operators
65
-
66
- `omdOperator` represents mathematical operators.
67
-
68
- #### Basic Usage
69
-
70
- ```javascript
71
- import { omdOperator } from '@teachinglab/omd';
72
-
73
- const operator = new omdOperator();
74
- operator.loadFromJSON({ operator: "+" });
75
- ```
76
-
77
- #### Supported Operators
78
-
79
- - Addition: `+`
80
- - Subtraction: `-`
81
- - Multiplication: `*`, `×`, `•`, `x`
82
- - Division: `/`, `÷`
83
- - Equals: `=`
84
-
85
- #### JSON Format
86
-
87
- ```json
88
- {
89
- "omdType": "operator",
90
- "operator": "+"
91
- }
92
- ```
93
-
94
- ---
95
-
96
- ### Terms
97
-
98
- `omdTerm` represents algebraic terms like `3x²`.
99
-
100
- #### Basic Usage
101
-
102
- ```javascript
103
- import { omdTerm } from '@teachinglab/omd';
104
-
105
- const term = new omdTerm();
106
- term.loadFromJSON({
107
- coefficient: 3,
108
- variable: "x",
109
- exponent: 2
110
- });
111
- ```
112
-
113
- #### Properties
114
-
115
- | Property | Type | Default | Description |
116
- |----------|------|---------|-------------|
117
- | `coefficient` | number | required | Numeric coefficient |
118
- | `variable` | string | optional | Variable letter |
119
- | `exponent` | number | 1 | Power of the variable |
120
-
121
- #### Examples
122
-
123
- **Constant term:**
124
- ```json
125
- {
126
- "omdType": "term",
127
- "coefficient": 5
128
- }
129
- ```
130
-
131
- **Linear term:**
132
- ```json
133
- {
134
- "omdType": "term",
135
- "coefficient": 3,
136
- "variable": "x"
137
- }
138
- ```
139
-
140
- **Quadratic term:**
141
- ```json
142
- {
143
- "omdType": "term",
144
- "coefficient": 2,
145
- "variable": "x",
146
- "exponent": 2
147
- }
148
- ```
149
-
150
- ---
151
-
152
- ### Expressions
153
-
154
- `omdExpression` represents mathematical expressions composed of terms and operators.
155
-
156
- #### Basic Usage
157
-
158
- ```javascript
159
- import { omdExpression } from '@teachinglab/omd';
160
-
161
- // String form (simplest)
162
- const expr = new omdExpression();
163
- expr.loadFromJSON("3x^2 + 5x - 2");
164
-
165
- // Structured form (programmatic)
166
- expr.loadFromJSON({
167
- termsAndOpers: [
168
- { omdType: "term", coefficient: 3, variable: "x", exponent: 2 },
169
- { omdType: "operator", operator: "+" },
170
- { omdType: "term", coefficient: 5, variable: "x" },
171
- { omdType: "operator", operator: "-" },
172
- { omdType: "number", value: 2 }
173
- ]
174
- });
175
- ```
176
-
177
- #### String Parsing
178
-
179
- OMD automatically parses mathematical expressions:
180
-
181
- ```javascript
182
- expr.loadFromJSON("2x + 3"); // Linear
183
- expr.loadFromJSON("x^2 - 4x + 4"); // Quadratic
184
- expr.loadFromJSON("3x^3 + 2x^2 - x"); // Cubic
185
- ```
186
-
187
- #### Structured Format
188
-
189
- For programmatic creation:
190
-
191
- ```json
192
- {
193
- "termsAndOpers": [
194
- { "omdType": "term", "coefficient": 2, "variable": "x" },
195
- { "omdType": "operator", "operator": "+" },
196
- { "omdType": "number", "value": 3 }
197
- ]
198
- }
199
- ```
200
-
201
- #### Examples
202
-
203
- **Simple polynomial:**
204
- ```javascript
205
- expr.loadFromJSON("x^2 + 2x + 1");
206
- ```
207
-
208
- **Multi-variable:**
209
- ```javascript
210
- expr.loadFromJSON("3x + 2y - 5");
211
- ```
212
-
213
- **Complex expression:**
214
- ```javascript
215
- expr.loadFromJSON({
216
- termsAndOpers: [
217
- { omdType: "term", coefficient: 1, variable: "x", exponent: 3 },
218
- { omdType: "operator", operator: "-" },
219
- { omdType: "term", coefficient: 4, variable: "x", exponent: 2 },
220
- { omdType: "operator", operator: "+" },
221
- { omdType: "term", coefficient: 5, variable: "x" },
222
- { omdType: "operator", operator: "-" },
223
- { omdType: "number", value: 6 }
224
- ]
225
- });
226
- ```
227
-
228
- ---
229
-
230
- ### Equations
231
-
232
- `omdEquation` represents complete equations with left and right sides.
233
-
234
- #### Basic Usage
235
-
236
- ```javascript
237
- import { omdEquation, omdEquationNode } from '@teachinglab/omd';
238
-
239
- // Simple string form
240
- const eq = new omdEquation();
241
- eq.loadFromJSON({ equation: "2x + 3 = 11" });
242
-
243
- // Or using static method
244
- const eqNode = omdEquationNode.fromString("2x + 3 = 11");
245
- ```
246
-
247
- #### Properties
248
-
249
- | Property | Type | Description |
250
- |----------|------|-------------|
251
- | `equation` | string | String representation of equation |
252
- | `leftExpression` | Expression | Left side expression |
253
- | `rightExpression` | Expression | Right side expression |
254
-
255
- #### Examples
256
-
257
- **Linear equation:**
258
- ```javascript
259
- eq.loadFromJSON({ equation: "2x + 3 = 11" });
260
- ```
261
-
262
- **Quadratic equation:**
263
- ```javascript
264
- eq.loadFromJSON({ equation: "x^2 - 5x + 6 = 0" });
265
- ```
266
-
267
- **Structured form:**
268
- ```javascript
269
- eq.loadFromJSON({
270
- leftExpression: {
271
- termsAndOpers: [
272
- { omdType: "term", coefficient: 2, variable: "x" },
273
- { omdType: "operator", operator: "+" },
274
- { omdType: "number", value: 3 }
275
- ]
276
- },
277
- rightExpression: {
278
- omdType: "number",
279
- value: 11
280
- }
281
- });
282
- ```
283
-
284
- **Multi-step:**
285
- ```javascript
286
- // Step 1
287
- eq.loadFromJSON({ equation: "2x + 3 = 11" });
288
-
289
- // Step 2
290
- eq.loadFromJSON({ equation: "2x = 8" });
291
-
292
- // Step 3
293
- eq.loadFromJSON({ equation: "x = 4" });
294
- ```
295
-
296
- ---
297
-
298
- ## Advanced Expressions
299
-
300
- ### Power Expressions
301
-
302
- `omdPowerExpression` represents expressions raised to a power.
303
-
304
- #### Basic Usage
305
-
306
- ```javascript
307
- import { omdPowerExpression } from '@teachinglab/omd';
308
-
309
- const power = new omdPowerExpression();
310
- power.loadFromJSON({
311
- baseExpression: "x + 1",
312
- exponentExpression: "2"
313
- });
314
- ```
315
-
316
- #### Examples
317
-
318
- **Simple power:**
319
- ```json
320
- {
321
- "baseExpression": { "omdType": "variable", "name": "x" },
322
- "exponentExpression": { "omdType": "number", "value": 2 }
323
- }
324
- ```
325
- Renders as: `x²`
326
-
327
- **Complex base:**
328
- ```json
329
- {
330
- "baseExpression": {
331
- "termsAndOpers": [
332
- { "omdType": "variable", "name": "x" },
333
- { "omdType": "operator", "operator": "+" },
334
- { "omdType": "number", "value": 1 }
335
- ]
336
- },
337
- "exponentExpression": { "omdType": "number", "value": 2 }
338
- }
339
- ```
340
- Renders as: `(x + 1)²`
341
-
342
- **Variable exponent:**
343
- ```json
344
- {
345
- "baseExpression": { "omdType": "number", "value": 2 },
346
- "exponentExpression": { "omdType": "variable", "name": "n" }
347
- }
348
- ```
349
- Renders as: `2ⁿ`
350
-
351
- ---
352
-
353
- ### Rational Expressions
354
-
355
- `omdRationalExpression` represents fractions and rational expressions.
356
-
357
- #### Basic Usage
358
-
359
- ```javascript
360
- import { omdRationalExpression } from '@teachinglab/omd';
361
-
362
- const rational = new omdRationalExpression();
363
- rational.loadFromJSON({
364
- numeratorExpression: "x + 1",
365
- denominatorExpression: "x - 1"
366
- });
367
- ```
368
-
369
- #### Examples
370
-
371
- **Simple fraction:**
372
- ```json
373
- {
374
- "numeratorExpression": { "omdType": "number", "value": 3 },
375
- "denominatorExpression": { "omdType": "number", "value": 4 }
376
- }
377
- ```
378
- Renders as: `¾`
379
-
380
- **Algebraic fraction:**
381
- ```json
382
- {
383
- "numeratorExpression": { "omdType": "variable", "name": "x" },
384
- "denominatorExpression": { "omdType": "number", "value": 2 }
385
- }
386
- ```
387
- Renders as: `x/2`
388
-
389
- **Complex rational expression:**
390
- ```json
391
- {
392
- "numeratorExpression": {
393
- "termsAndOpers": [
394
- { "omdType": "variable", "name": "x" },
395
- { "omdType": "operator", "operator": "+" },
396
- { "omdType": "number", "value": 1 }
397
- ]
398
- },
399
- "denominatorExpression": {
400
- "termsAndOpers": [
401
- { "omdType": "term", "coefficient": 1, "variable": "x", "exponent": 2 },
402
- { "omdType": "operator", "operator": "-" },
403
- { "omdType": "number", "value": 1 }
404
- ]
405
- }
406
- }
407
- ```
408
- Renders as: `(x + 1)/(x² - 1)`
409
-
410
- ---
411
-
412
- ### Functions
413
-
414
- `omdFunction` represents mathematical functions.
415
-
416
- #### Basic Usage
417
-
418
- ```javascript
419
- import { omdFunction } from '@teachinglab/omd';
420
-
421
- const func = new omdFunction();
422
- func.loadFromJSON({
423
- name: "f",
424
- inputVariables: ["x"],
425
- expression: "2x + 1"
426
- });
427
- ```
428
-
429
- #### Properties
430
-
431
- | Property | Type | Description |
432
- |----------|------|-------------|
433
- | `name` | string | Function name (e.g., "f", "g", "h") |
434
- | `inputVariables` | string[] | Input variable names |
435
- | `expression` | Expression | Function definition |
436
-
437
- #### Examples
438
-
439
- **Linear function:**
440
- ```json
441
- {
442
- "name": "f",
443
- "inputVariables": ["x"],
444
- "expression": "2x + 1"
445
- }
446
- ```
447
- Renders as: `f(x) = 2x + 1`
448
-
449
- **Quadratic function:**
450
- ```json
451
- {
452
- "name": "g",
453
- "inputVariables": ["x"],
454
- "expression": "x^2 - 4"
455
- }
456
- ```
457
- Renders as: `g(x) = x² - 4`
458
-
459
- **Multi-variable function:**
460
- ```json
461
- {
462
- "name": "h",
463
- "inputVariables": ["x", "y"],
464
- "expression": "x + 2y"
465
- }
466
- ```
467
- Renders as: `h(x, y) = x + 2y`
468
-
469
- **Structured expression:**
470
- ```json
471
- {
472
- "name": "f",
473
- "inputVariables": ["x"],
474
- "expression": {
475
- "termsAndOpers": [
476
- { "omdType": "term", "coefficient": 3, "variable": "x", "exponent": 2 },
477
- { "omdType": "operator", "operator": "-" },
478
- { "omdType": "term", "coefficient": 2, "variable": "x" },
479
- { "omdType": "operator", "operator": "+" },
480
- { "omdType": "number", "value": 5 }
481
- ]
482
- }
483
- }
484
- ```
485
-
486
- ---
487
-
488
- ### Tile Equations
489
-
490
- `omdTileEquation` provides visual tile-based representations of equations.
491
-
492
- #### Basic Usage
493
-
494
- ```javascript
495
- import { omdTileEquation } from '@teachinglab/omd';
496
-
497
- const tileEq = new omdTileEquation();
498
- tileEq.loadFromJSON({
499
- left: ["x", "x", 3],
500
- right: [11],
501
- equation: "2x + 3 = 11"
502
- });
503
- ```
504
-
505
- #### Properties
506
-
507
- | Property | Type | Default | Description |
508
- |----------|------|---------|-------------|
509
- | `left` | Array | required | Left side tiles |
510
- | `right` | Array | required | Right side tiles |
511
- | `equation` | string | optional | Equation string |
512
- | `tileSize` | number | 28 | Tile size in pixels |
513
- | `tileGap` | number | 6 | Gap between tiles |
514
- | `showLabels` | boolean | true | Show tile labels |
515
- | `fontSize` | number | 16 | Label font size |
516
-
517
- #### Examples
518
-
519
- **Simple equation:**
520
- ```json
521
- {
522
- "left": ["x", 5],
523
- "right": [10],
524
- "equation": "x + 5 = 10"
525
- }
526
- ```
527
-
528
- **Multiple variables:**
529
- ```json
530
- {
531
- "left": ["x", "x", "y", 3],
532
- "right": ["x", "y", "y", 8],
533
- "tileSize": 30,
534
- "showLabels": true
535
- }
536
- ```
537
-
538
- **Custom styling:**
539
- ```json
540
- {
541
- "left": ["x", "x", 4],
542
- "right": [12],
543
- "tileSize": 32,
544
- "tileGap": 8,
545
- "fontSize": 18,
546
- "fontFamily": "Georgia",
547
- "xPillColor": "#4ECDC4"
548
- }
549
- ```
550
-
551
- ---
552
-
553
- ## Step-by-Step Solutions
554
-
555
- ### Equation Stack
556
-
557
- `omdEquationStack` manages sequences of equation steps.
558
-
559
- #### Basic Usage
560
-
561
- ```javascript
562
- import { omdEquationStack, omdEquationNode } from '@teachinglab/omd';
563
-
564
- const steps = [
565
- omdEquationNode.fromString('2x + 3 = 11'),
566
- omdEquationNode.fromString('2x = 8'),
567
- omdEquationNode.fromString('x = 4')
568
- ];
569
-
570
- const stack = new omdEquationStack(steps, {
571
- toolbar: true,
572
- stepVisualizer: true
573
- });
574
-
575
- display.render(stack);
576
- ```
577
-
578
- #### Options
579
-
580
- | Option | Type | Default | Description |
581
- |--------|------|---------|-------------|
582
- | `toolbar` | boolean | false | Show editing toolbar |
583
- | `stepVisualizer` | boolean | false | Enable step visualization |
584
- | `interactive` | boolean | true | Allow user interaction |
585
-
586
- #### Examples
587
-
588
- **Linear equation solution:**
589
- ```javascript
590
- const linearSteps = [
591
- omdEquationNode.fromString('3x + 5 = 20'),
592
- omdEquationNode.fromString('3x = 15'),
593
- omdEquationNode.fromString('x = 5')
594
- ];
595
-
596
- const stack = new omdEquationStack(linearSteps);
597
- ```
598
-
599
- **Quadratic factoring:**
600
- ```javascript
601
- const quadraticSteps = [
602
- omdEquationNode.fromString('x^2 + 5x + 6 = 0'),
603
- omdEquationNode.fromString('(x + 2)(x + 3) = 0'),
604
- omdEquationNode.fromString('x = -2 or x = -3')
605
- ];
606
-
607
- const stack = new omdEquationStack(quadraticSteps, {
608
- stepVisualizer: true
609
- });
610
- ```
611
-
612
- **With explanations:**
613
- ```javascript
614
- const stepsWithExplanations = [
615
- {
616
- equation: omdEquationNode.fromString('2x + 3 = 11'),
617
- explanation: 'Original equation'
618
- },
619
- {
620
- equation: omdEquationNode.fromString('2x = 8'),
621
- explanation: 'Subtract 3 from both sides'
622
- },
623
- {
624
- equation: omdEquationNode.fromString('x = 4'),
625
- explanation: 'Divide both sides by 2'
626
- }
627
- ];
628
- ```
629
-
630
- ---
631
-
632
- ### Step Visualizer
633
-
634
- `omdStepVisualizer` provides interactive step-by-step visualization.
635
-
636
- #### Basic Usage
637
-
638
- ```javascript
639
- import { omdStepVisualizer } from '@teachinglab/omd';
640
-
641
- const visualizer = new omdStepVisualizer();
642
- visualizer.setSteps([
643
- { equation: '2x + 3 = 11', explanation: 'Start' },
644
- { equation: '2x = 8', explanation: 'Subtract 3' },
645
- { equation: 'x = 4', explanation: 'Divide by 2' }
646
- ]);
647
- ```
648
-
649
- #### Features
650
-
651
- - **Highlighting**: Automatically highlights changed elements
652
- - **Explanations**: Text boxes for step explanations
653
- - **Navigation**: Step forward/backward controls
654
- - **Provenance**: Visual tracking of element relationships
655
-
656
- #### Example with highlighting:
657
-
658
- ```javascript
659
- visualizer.setSteps([
660
- {
661
- equation: omdEquationNode.fromString('2x + 3 = 11'),
662
- explanation: 'Original equation',
663
- highlights: []
664
- },
665
- {
666
- equation: omdEquationNode.fromString('2x = 8'),
667
- explanation: 'Subtract 3 from both sides',
668
- highlights: ['3', '11', '8'] // Highlight changed terms
669
- },
670
- {
671
- equation: omdEquationNode.fromString('x = 4'),
672
- explanation: 'Divide both sides by 2',
673
- highlights: ['2x', 'x', '8', '4']
674
- }
675
- ]);
676
- ```
677
-
678
- ---
679
-
680
- ### Simplification Engine
681
-
682
- `omdSimplification` provides rule-based expression simplification.
683
-
684
- #### Basic Usage
685
-
686
- ```javascript
687
- import { omdSimplification } from '@teachinglab/omd';
688
-
689
- const simplifier = new omdSimplification();
690
- const result = simplifier.simplify('2x + 3x');
691
- // Returns: '5x'
692
- ```
693
-
694
- #### Available Rules
695
-
696
- - **Combine like terms**: `2x + 3x` → `5x`
697
- - **Add constants**: `3 + 5` → `8`
698
- - **Multiply constants**: `2 * 3` → `6`
699
- - **Distribute**: `2(x + 3)` → `2x + 6`
700
- - **Factor**: `x^2 + 5x + 6` → `(x + 2)(x + 3)`
701
-
702
- #### Examples
703
-
704
- **Combine like terms:**
705
- ```javascript
706
- simplifier.simplify('3x + 2x + 5');
707
- // '5x + 5'
708
- ```
709
-
710
- **Distribute:**
711
- ```javascript
712
- simplifier.simplify('3(x + 2)');
713
- // '3x + 6'
714
- ```
715
-
716
- **Multi-step:**
717
- ```javascript
718
- const steps = simplifier.simplifyWithSteps('2(x + 3) + 4x');
719
- // Returns array of intermediate steps
720
- ```
721
-
722
- ---
723
-
724
- ## Expression Parsing
725
-
726
- OMD includes a powerful expression parser that handles various mathematical notations.
727
-
728
- ### Supported Formats
729
-
730
- #### Exponents
731
- - Caret notation: `x^2`
732
- - Superscript: `x²`
733
-
734
- #### Multiplication
735
- - Asterisk: `2*x`
736
- - Times symbol: `2×x`
737
- - Dot: `2•x`
738
- - Implicit: `2x`
739
-
740
- #### Division
741
- - Slash: `x/2`
742
- - Division symbol: `x÷2`
743
-
744
- #### Parentheses
745
- - Standard: `(x + 1)`
746
- - Nested: `((x + 1) * 2)`
747
-
748
- ### Parsing Examples
749
-
750
- ```javascript
751
- import { omdExpression } from '@teachinglab/omd';
752
-
753
- const expr = new omdExpression();
754
-
755
- // All of these are parsed correctly
756
- expr.loadFromJSON("x^2 + 2x + 1");
757
- expr.loadFromJSON("x² + 2x + 1");
758
- expr.loadFromJSON("2*x*3");
759
- expr.loadFromJSON("2×x×3");
760
- expr.loadFromJSON("x/2 + 3");
761
- expr.loadFromJSON("(x+1)(x-1)");
762
- ```
763
-
764
- ### Custom Parsing
765
-
766
- For complex expressions, use the structured format:
767
-
768
- ```javascript
769
- expr.loadFromJSON({
770
- termsAndOpers: [
771
- // Build expression programmatically
772
- ]
773
- });
774
- ```
775
-
776
- ---
777
-
778
- ## Best Practices
779
-
780
- ### Use String Format When Possible
781
-
782
- For simple expressions, string format is clearest:
783
-
784
- ```javascript
785
- // Good
786
- eq.loadFromJSON({ equation: "2x + 3 = 11" });
787
-
788
- // Also works, but more verbose
789
- eq.loadFromJSON({
790
- leftExpression: { termsAndOpers: [...] },
791
- rightExpression: { omdType: "number", value: 11 }
792
- });
793
- ```
794
-
795
- ### Programmatic Generation
796
-
797
- Use structured format for dynamic expression building:
798
-
799
- ```javascript
800
- function createPolynomial(coefficients) {
801
- const termsAndOpers = [];
802
-
803
- coefficients.forEach((coef, index) => {
804
- const exponent = coefficients.length - index - 1;
805
-
806
- if (index > 0) {
807
- termsAndOpers.push({ omdType: "operator", operator: "+" });
808
- }
809
-
810
- termsAndOpers.push({
811
- omdType: "term",
812
- coefficient: coef,
813
- variable: "x",
814
- exponent: exponent
815
- });
816
- });
817
-
818
- return { termsAndOpers };
819
- }
820
-
821
- // Usage
822
- const quadratic = createPolynomial([1, -5, 6]);
823
- // Generates: x² - 5x + 6
824
- ```
825
-
826
- ### Step-by-Step Solutions
827
-
828
- Always provide clear explanations:
829
-
830
- ```javascript
831
- const steps = [
832
- {
833
- equation: omdEquationNode.fromString('2x + 3 = 11'),
834
- explanation: 'Given equation'
835
- },
836
- {
837
- equation: omdEquationNode.fromString('2x = 8'),
838
- explanation: 'Subtract 3 from both sides'
839
- },
840
- {
841
- equation: omdEquationNode.fromString('x = 4'),
842
- explanation: 'Divide both sides by 2'
843
- }
844
- ];
845
- ```
846
-
847
- ---
848
-
849
- ## Next Steps
850
-
851
- - **[Visualizations Guide](./visualizations.md)** - Explore visual components
852
- - **[JSON Schemas](../json-schemas.md)** - Complete reference
853
- - **[API Reference](../api/api-reference.md)** - Detailed documentation
854
- - **[Simplification Rules](../api/simplificationRules.md)** - Learn about available rules
1
+ # Equations & Expressions Guide
2
+
3
+ This guide covers all equation and expression components in OMD, from basic numbers and variables to complex step-by-step solutions.
4
+
5
+ ## Table of Contents
6
+
7
+ 1. [Core Components](#core-components)
8
+ 2. [Advanced Expressions](#advanced-expressions)
9
+ 3. [Step-by-Step Solutions](#step-by-step-solutions)
10
+ 4. [Expression Parsing](#expression-parsing)
11
+
12
+ ---
13
+
14
+ ## Core Components
15
+
16
+ ### Numbers
17
+
18
+ `omdNumber` represents numeric constants.
19
+
20
+ #### Basic Usage
21
+
22
+ ```javascript
23
+ import { omdNumber } from '@teachinglab/omd';
24
+
25
+ const num = new omdNumber();
26
+ num.loadFromJSON({ value: 42 });
27
+ ```
28
+
29
+ #### JSON Format
30
+
31
+ ```json
32
+ {
33
+ "omdType": "number",
34
+ "value": 42
35
+ }
36
+ ```
37
+
38
+ ---
39
+
40
+ ### Variables
41
+
42
+ `omdVariable` represents algebraic variables.
43
+
44
+ #### Basic Usage
45
+
46
+ ```javascript
47
+ import { omdVariable } from '@teachinglab/omd';
48
+
49
+ const variable = new omdVariable();
50
+ variable.loadFromJSON({ name: "x" });
51
+ ```
52
+
53
+ #### JSON Format
54
+
55
+ ```json
56
+ {
57
+ "omdType": "variable",
58
+ "name": "x"
59
+ }
60
+ ```
61
+
62
+ ---
63
+
64
+ ### Operators
65
+
66
+ `omdOperator` represents mathematical operators.
67
+
68
+ #### Basic Usage
69
+
70
+ ```javascript
71
+ import { omdOperator } from '@teachinglab/omd';
72
+
73
+ const operator = new omdOperator();
74
+ operator.loadFromJSON({ operator: "+" });
75
+ ```
76
+
77
+ #### Supported Operators
78
+
79
+ - Addition: `+`
80
+ - Subtraction: `-`
81
+ - Multiplication: `*`, `×`, `•`, `x`
82
+ - Division: `/`, `÷`
83
+ - Equals: `=`
84
+
85
+ #### JSON Format
86
+
87
+ ```json
88
+ {
89
+ "omdType": "operator",
90
+ "operator": "+"
91
+ }
92
+ ```
93
+
94
+ ---
95
+
96
+ ### Terms
97
+
98
+ `omdTerm` represents algebraic terms like `3x²`.
99
+
100
+ #### Basic Usage
101
+
102
+ ```javascript
103
+ import { omdTerm } from '@teachinglab/omd';
104
+
105
+ const term = new omdTerm();
106
+ term.loadFromJSON({
107
+ coefficient: 3,
108
+ variable: "x",
109
+ exponent: 2
110
+ });
111
+ ```
112
+
113
+ #### Properties
114
+
115
+ | Property | Type | Default | Description |
116
+ |----------|------|---------|-------------|
117
+ | `coefficient` | number | required | Numeric coefficient |
118
+ | `variable` | string | optional | Variable letter |
119
+ | `exponent` | number | 1 | Power of the variable |
120
+
121
+ #### Examples
122
+
123
+ **Constant term:**
124
+ ```json
125
+ {
126
+ "omdType": "term",
127
+ "coefficient": 5
128
+ }
129
+ ```
130
+
131
+ **Linear term:**
132
+ ```json
133
+ {
134
+ "omdType": "term",
135
+ "coefficient": 3,
136
+ "variable": "x"
137
+ }
138
+ ```
139
+
140
+ **Quadratic term:**
141
+ ```json
142
+ {
143
+ "omdType": "term",
144
+ "coefficient": 2,
145
+ "variable": "x",
146
+ "exponent": 2
147
+ }
148
+ ```
149
+
150
+ ---
151
+
152
+ ### Expressions
153
+
154
+ `omdExpression` represents mathematical expressions composed of terms and operators.
155
+
156
+ #### Basic Usage
157
+
158
+ ```javascript
159
+ import { omdExpression } from '@teachinglab/omd';
160
+
161
+ // String form (simplest)
162
+ const expr = new omdExpression();
163
+ expr.loadFromJSON("3x^2 + 5x - 2");
164
+
165
+ // Structured form (programmatic)
166
+ expr.loadFromJSON({
167
+ termsAndOpers: [
168
+ { omdType: "term", coefficient: 3, variable: "x", exponent: 2 },
169
+ { omdType: "operator", operator: "+" },
170
+ { omdType: "term", coefficient: 5, variable: "x" },
171
+ { omdType: "operator", operator: "-" },
172
+ { omdType: "number", value: 2 }
173
+ ]
174
+ });
175
+ ```
176
+
177
+ #### String Parsing
178
+
179
+ OMD automatically parses mathematical expressions:
180
+
181
+ ```javascript
182
+ expr.loadFromJSON("2x + 3"); // Linear
183
+ expr.loadFromJSON("x^2 - 4x + 4"); // Quadratic
184
+ expr.loadFromJSON("3x^3 + 2x^2 - x"); // Cubic
185
+ ```
186
+
187
+ #### Structured Format
188
+
189
+ For programmatic creation:
190
+
191
+ ```json
192
+ {
193
+ "termsAndOpers": [
194
+ { "omdType": "term", "coefficient": 2, "variable": "x" },
195
+ { "omdType": "operator", "operator": "+" },
196
+ { "omdType": "number", "value": 3 }
197
+ ]
198
+ }
199
+ ```
200
+
201
+ #### Examples
202
+
203
+ **Simple polynomial:**
204
+ ```javascript
205
+ expr.loadFromJSON("x^2 + 2x + 1");
206
+ ```
207
+
208
+ **Multi-variable:**
209
+ ```javascript
210
+ expr.loadFromJSON("3x + 2y - 5");
211
+ ```
212
+
213
+ **Complex expression:**
214
+ ```javascript
215
+ expr.loadFromJSON({
216
+ termsAndOpers: [
217
+ { omdType: "term", coefficient: 1, variable: "x", exponent: 3 },
218
+ { omdType: "operator", operator: "-" },
219
+ { omdType: "term", coefficient: 4, variable: "x", exponent: 2 },
220
+ { omdType: "operator", operator: "+" },
221
+ { omdType: "term", coefficient: 5, variable: "x" },
222
+ { omdType: "operator", operator: "-" },
223
+ { omdType: "number", value: 6 }
224
+ ]
225
+ });
226
+ ```
227
+
228
+ ---
229
+
230
+ ### Equations
231
+
232
+ `omdEquation` represents complete equations with left and right sides.
233
+
234
+ #### Basic Usage
235
+
236
+ ```javascript
237
+ import { omdEquation, omdEquationNode } from '@teachinglab/omd';
238
+
239
+ // Simple string form
240
+ const eq = new omdEquation();
241
+ eq.loadFromJSON({ equation: "2x + 3 = 11" });
242
+
243
+ // Or using static method
244
+ const eqNode = omdEquationNode.fromString("2x + 3 = 11");
245
+ ```
246
+
247
+ #### Properties
248
+
249
+ | Property | Type | Description |
250
+ |----------|------|-------------|
251
+ | `equation` | string | String representation of equation |
252
+ | `leftExpression` | Expression | Left side expression |
253
+ | `rightExpression` | Expression | Right side expression |
254
+
255
+ #### Examples
256
+
257
+ **Linear equation:**
258
+ ```javascript
259
+ eq.loadFromJSON({ equation: "2x + 3 = 11" });
260
+ ```
261
+
262
+ **Quadratic equation:**
263
+ ```javascript
264
+ eq.loadFromJSON({ equation: "x^2 - 5x + 6 = 0" });
265
+ ```
266
+
267
+ **Structured form:**
268
+ ```javascript
269
+ eq.loadFromJSON({
270
+ leftExpression: {
271
+ termsAndOpers: [
272
+ { omdType: "term", coefficient: 2, variable: "x" },
273
+ { omdType: "operator", operator: "+" },
274
+ { omdType: "number", value: 3 }
275
+ ]
276
+ },
277
+ rightExpression: {
278
+ omdType: "number",
279
+ value: 11
280
+ }
281
+ });
282
+ ```
283
+
284
+ **Multi-step:**
285
+ ```javascript
286
+ // Step 1
287
+ eq.loadFromJSON({ equation: "2x + 3 = 11" });
288
+
289
+ // Step 2
290
+ eq.loadFromJSON({ equation: "2x = 8" });
291
+
292
+ // Step 3
293
+ eq.loadFromJSON({ equation: "x = 4" });
294
+ ```
295
+
296
+ ---
297
+
298
+ ## Advanced Expressions
299
+
300
+ ### Power Expressions
301
+
302
+ `omdPowerExpression` represents expressions raised to a power.
303
+
304
+ #### Basic Usage
305
+
306
+ ```javascript
307
+ import { omdPowerExpression } from '@teachinglab/omd';
308
+
309
+ const power = new omdPowerExpression();
310
+ power.loadFromJSON({
311
+ baseExpression: "x + 1",
312
+ exponentExpression: "2"
313
+ });
314
+ ```
315
+
316
+ #### Examples
317
+
318
+ **Simple power:**
319
+ ```json
320
+ {
321
+ "baseExpression": { "omdType": "variable", "name": "x" },
322
+ "exponentExpression": { "omdType": "number", "value": 2 }
323
+ }
324
+ ```
325
+ Renders as: `x²`
326
+
327
+ **Complex base:**
328
+ ```json
329
+ {
330
+ "baseExpression": {
331
+ "termsAndOpers": [
332
+ { "omdType": "variable", "name": "x" },
333
+ { "omdType": "operator", "operator": "+" },
334
+ { "omdType": "number", "value": 1 }
335
+ ]
336
+ },
337
+ "exponentExpression": { "omdType": "number", "value": 2 }
338
+ }
339
+ ```
340
+ Renders as: `(x + 1)²`
341
+
342
+ **Variable exponent:**
343
+ ```json
344
+ {
345
+ "baseExpression": { "omdType": "number", "value": 2 },
346
+ "exponentExpression": { "omdType": "variable", "name": "n" }
347
+ }
348
+ ```
349
+ Renders as: `2ⁿ`
350
+
351
+ ---
352
+
353
+ ### Rational Expressions
354
+
355
+ `omdRationalExpression` represents fractions and rational expressions.
356
+
357
+ #### Basic Usage
358
+
359
+ ```javascript
360
+ import { omdRationalExpression } from '@teachinglab/omd';
361
+
362
+ const rational = new omdRationalExpression();
363
+ rational.loadFromJSON({
364
+ numeratorExpression: "x + 1",
365
+ denominatorExpression: "x - 1"
366
+ });
367
+ ```
368
+
369
+ #### Examples
370
+
371
+ **Simple fraction:**
372
+ ```json
373
+ {
374
+ "numeratorExpression": { "omdType": "number", "value": 3 },
375
+ "denominatorExpression": { "omdType": "number", "value": 4 }
376
+ }
377
+ ```
378
+ Renders as: `¾`
379
+
380
+ **Algebraic fraction:**
381
+ ```json
382
+ {
383
+ "numeratorExpression": { "omdType": "variable", "name": "x" },
384
+ "denominatorExpression": { "omdType": "number", "value": 2 }
385
+ }
386
+ ```
387
+ Renders as: `x/2`
388
+
389
+ **Complex rational expression:**
390
+ ```json
391
+ {
392
+ "numeratorExpression": {
393
+ "termsAndOpers": [
394
+ { "omdType": "variable", "name": "x" },
395
+ { "omdType": "operator", "operator": "+" },
396
+ { "omdType": "number", "value": 1 }
397
+ ]
398
+ },
399
+ "denominatorExpression": {
400
+ "termsAndOpers": [
401
+ { "omdType": "term", "coefficient": 1, "variable": "x", "exponent": 2 },
402
+ { "omdType": "operator", "operator": "-" },
403
+ { "omdType": "number", "value": 1 }
404
+ ]
405
+ }
406
+ }
407
+ ```
408
+ Renders as: `(x + 1)/(x² - 1)`
409
+
410
+ ---
411
+
412
+ ### Functions
413
+
414
+ `omdFunction` represents mathematical functions.
415
+
416
+ #### Basic Usage
417
+
418
+ ```javascript
419
+ import { omdFunction } from '@teachinglab/omd';
420
+
421
+ const func = new omdFunction();
422
+ func.loadFromJSON({
423
+ name: "f",
424
+ inputVariables: ["x"],
425
+ expression: "2x + 1"
426
+ });
427
+ ```
428
+
429
+ #### Properties
430
+
431
+ | Property | Type | Description |
432
+ |----------|------|-------------|
433
+ | `name` | string | Function name (e.g., "f", "g", "h") |
434
+ | `inputVariables` | string[] | Input variable names |
435
+ | `expression` | Expression | Function definition |
436
+
437
+ #### Examples
438
+
439
+ **Linear function:**
440
+ ```json
441
+ {
442
+ "name": "f",
443
+ "inputVariables": ["x"],
444
+ "expression": "2x + 1"
445
+ }
446
+ ```
447
+ Renders as: `f(x) = 2x + 1`
448
+
449
+ **Quadratic function:**
450
+ ```json
451
+ {
452
+ "name": "g",
453
+ "inputVariables": ["x"],
454
+ "expression": "x^2 - 4"
455
+ }
456
+ ```
457
+ Renders as: `g(x) = x² - 4`
458
+
459
+ **Multi-variable function:**
460
+ ```json
461
+ {
462
+ "name": "h",
463
+ "inputVariables": ["x", "y"],
464
+ "expression": "x + 2y"
465
+ }
466
+ ```
467
+ Renders as: `h(x, y) = x + 2y`
468
+
469
+ **Structured expression:**
470
+ ```json
471
+ {
472
+ "name": "f",
473
+ "inputVariables": ["x"],
474
+ "expression": {
475
+ "termsAndOpers": [
476
+ { "omdType": "term", "coefficient": 3, "variable": "x", "exponent": 2 },
477
+ { "omdType": "operator", "operator": "-" },
478
+ { "omdType": "term", "coefficient": 2, "variable": "x" },
479
+ { "omdType": "operator", "operator": "+" },
480
+ { "omdType": "number", "value": 5 }
481
+ ]
482
+ }
483
+ }
484
+ ```
485
+
486
+ ---
487
+
488
+ ### Tile Equations
489
+
490
+ `omdTileEquation` provides visual tile-based representations of equations.
491
+
492
+ #### Basic Usage
493
+
494
+ ```javascript
495
+ import { omdTileEquation } from '@teachinglab/omd';
496
+
497
+ const tileEq = new omdTileEquation();
498
+ tileEq.loadFromJSON({
499
+ left: ["x", "x", 3],
500
+ right: [11],
501
+ equation: "2x + 3 = 11"
502
+ });
503
+ ```
504
+
505
+ #### Properties
506
+
507
+ | Property | Type | Default | Description |
508
+ |----------|------|---------|-------------|
509
+ | `left` | Array | required | Left side tiles |
510
+ | `right` | Array | required | Right side tiles |
511
+ | `equation` | string | optional | Equation string |
512
+ | `tileSize` | number | 28 | Tile size in pixels |
513
+ | `tileGap` | number | 6 | Gap between tiles |
514
+ | `showLabels` | boolean | true | Show tile labels |
515
+ | `fontSize` | number | 16 | Label font size |
516
+
517
+ #### Examples
518
+
519
+ **Simple equation:**
520
+ ```json
521
+ {
522
+ "left": ["x", 5],
523
+ "right": [10],
524
+ "equation": "x + 5 = 10"
525
+ }
526
+ ```
527
+
528
+ **Multiple variables:**
529
+ ```json
530
+ {
531
+ "left": ["x", "x", "y", 3],
532
+ "right": ["x", "y", "y", 8],
533
+ "tileSize": 30,
534
+ "showLabels": true
535
+ }
536
+ ```
537
+
538
+ **Custom styling:**
539
+ ```json
540
+ {
541
+ "left": ["x", "x", 4],
542
+ "right": [12],
543
+ "tileSize": 32,
544
+ "tileGap": 8,
545
+ "fontSize": 18,
546
+ "fontFamily": "Georgia",
547
+ "xPillColor": "#4ECDC4"
548
+ }
549
+ ```
550
+
551
+ ---
552
+
553
+ ## Step-by-Step Solutions
554
+
555
+ ### Equation Stack
556
+
557
+ `omdEquationStack` manages sequences of equation steps.
558
+
559
+ #### Basic Usage
560
+
561
+ ```javascript
562
+ import { omdEquationStack, omdEquationNode } from '@teachinglab/omd';
563
+
564
+ const steps = [
565
+ omdEquationNode.fromString('2x + 3 = 11'),
566
+ omdEquationNode.fromString('2x = 8'),
567
+ omdEquationNode.fromString('x = 4')
568
+ ];
569
+
570
+ const stack = new omdEquationStack(steps, {
571
+ toolbar: true,
572
+ stepVisualizer: true
573
+ });
574
+
575
+ display.render(stack);
576
+ ```
577
+
578
+ #### Options
579
+
580
+ | Option | Type | Default | Description |
581
+ |--------|------|---------|-------------|
582
+ | `toolbar` | boolean | false | Show editing toolbar |
583
+ | `stepVisualizer` | boolean | false | Enable step visualization |
584
+ | `interactive` | boolean | true | Allow user interaction |
585
+
586
+ #### Examples
587
+
588
+ **Linear equation solution:**
589
+ ```javascript
590
+ const linearSteps = [
591
+ omdEquationNode.fromString('3x + 5 = 20'),
592
+ omdEquationNode.fromString('3x = 15'),
593
+ omdEquationNode.fromString('x = 5')
594
+ ];
595
+
596
+ const stack = new omdEquationStack(linearSteps);
597
+ ```
598
+
599
+ **Quadratic factoring:**
600
+ ```javascript
601
+ const quadraticSteps = [
602
+ omdEquationNode.fromString('x^2 + 5x + 6 = 0'),
603
+ omdEquationNode.fromString('(x + 2)(x + 3) = 0'),
604
+ omdEquationNode.fromString('x = -2 or x = -3')
605
+ ];
606
+
607
+ const stack = new omdEquationStack(quadraticSteps, {
608
+ stepVisualizer: true
609
+ });
610
+ ```
611
+
612
+ **With explanations:**
613
+ ```javascript
614
+ const stepsWithExplanations = [
615
+ {
616
+ equation: omdEquationNode.fromString('2x + 3 = 11'),
617
+ explanation: 'Original equation'
618
+ },
619
+ {
620
+ equation: omdEquationNode.fromString('2x = 8'),
621
+ explanation: 'Subtract 3 from both sides'
622
+ },
623
+ {
624
+ equation: omdEquationNode.fromString('x = 4'),
625
+ explanation: 'Divide both sides by 2'
626
+ }
627
+ ];
628
+ ```
629
+
630
+ ---
631
+
632
+ ### Step Visualizer
633
+
634
+ `omdStepVisualizer` provides interactive step-by-step visualization.
635
+
636
+ #### Basic Usage
637
+
638
+ ```javascript
639
+ import { omdStepVisualizer } from '@teachinglab/omd';
640
+
641
+ const visualizer = new omdStepVisualizer();
642
+ visualizer.setSteps([
643
+ { equation: '2x + 3 = 11', explanation: 'Start' },
644
+ { equation: '2x = 8', explanation: 'Subtract 3' },
645
+ { equation: 'x = 4', explanation: 'Divide by 2' }
646
+ ]);
647
+ ```
648
+
649
+ #### Features
650
+
651
+ - **Highlighting**: Automatically highlights changed elements
652
+ - **Explanations**: Text boxes for step explanations
653
+ - **Navigation**: Step forward/backward controls
654
+ - **Provenance**: Visual tracking of element relationships
655
+
656
+ #### Example with highlighting:
657
+
658
+ ```javascript
659
+ visualizer.setSteps([
660
+ {
661
+ equation: omdEquationNode.fromString('2x + 3 = 11'),
662
+ explanation: 'Original equation',
663
+ highlights: []
664
+ },
665
+ {
666
+ equation: omdEquationNode.fromString('2x = 8'),
667
+ explanation: 'Subtract 3 from both sides',
668
+ highlights: ['3', '11', '8'] // Highlight changed terms
669
+ },
670
+ {
671
+ equation: omdEquationNode.fromString('x = 4'),
672
+ explanation: 'Divide both sides by 2',
673
+ highlights: ['2x', 'x', '8', '4']
674
+ }
675
+ ]);
676
+ ```
677
+
678
+ ---
679
+
680
+ ### Simplification Engine
681
+
682
+ `omdSimplification` provides rule-based expression simplification.
683
+
684
+ #### Basic Usage
685
+
686
+ ```javascript
687
+ import { omdSimplification } from '@teachinglab/omd';
688
+
689
+ const simplifier = new omdSimplification();
690
+ const result = simplifier.simplify('2x + 3x');
691
+ // Returns: '5x'
692
+ ```
693
+
694
+ #### Available Rules
695
+
696
+ - **Combine like terms**: `2x + 3x` → `5x`
697
+ - **Add constants**: `3 + 5` → `8`
698
+ - **Multiply constants**: `2 * 3` → `6`
699
+ - **Distribute**: `2(x + 3)` → `2x + 6`
700
+ - **Factor**: `x^2 + 5x + 6` → `(x + 2)(x + 3)`
701
+
702
+ #### Examples
703
+
704
+ **Combine like terms:**
705
+ ```javascript
706
+ simplifier.simplify('3x + 2x + 5');
707
+ // '5x + 5'
708
+ ```
709
+
710
+ **Distribute:**
711
+ ```javascript
712
+ simplifier.simplify('3(x + 2)');
713
+ // '3x + 6'
714
+ ```
715
+
716
+ **Multi-step:**
717
+ ```javascript
718
+ const steps = simplifier.simplifyWithSteps('2(x + 3) + 4x');
719
+ // Returns array of intermediate steps
720
+ ```
721
+
722
+ ---
723
+
724
+ ## Expression Parsing
725
+
726
+ OMD includes a powerful expression parser that handles various mathematical notations.
727
+
728
+ ### Supported Formats
729
+
730
+ #### Exponents
731
+ - Caret notation: `x^2`
732
+ - Superscript: `x²`
733
+
734
+ #### Multiplication
735
+ - Asterisk: `2*x`
736
+ - Times symbol: `2×x`
737
+ - Dot: `2•x`
738
+ - Implicit: `2x`
739
+
740
+ #### Division
741
+ - Slash: `x/2`
742
+ - Division symbol: `x÷2`
743
+
744
+ #### Parentheses
745
+ - Standard: `(x + 1)`
746
+ - Nested: `((x + 1) * 2)`
747
+
748
+ ### Parsing Examples
749
+
750
+ ```javascript
751
+ import { omdExpression } from '@teachinglab/omd';
752
+
753
+ const expr = new omdExpression();
754
+
755
+ // All of these are parsed correctly
756
+ expr.loadFromJSON("x^2 + 2x + 1");
757
+ expr.loadFromJSON("x² + 2x + 1");
758
+ expr.loadFromJSON("2*x*3");
759
+ expr.loadFromJSON("2×x×3");
760
+ expr.loadFromJSON("x/2 + 3");
761
+ expr.loadFromJSON("(x+1)(x-1)");
762
+ ```
763
+
764
+ ### Custom Parsing
765
+
766
+ For complex expressions, use the structured format:
767
+
768
+ ```javascript
769
+ expr.loadFromJSON({
770
+ termsAndOpers: [
771
+ // Build expression programmatically
772
+ ]
773
+ });
774
+ ```
775
+
776
+ ---
777
+
778
+ ## Best Practices
779
+
780
+ ### Use String Format When Possible
781
+
782
+ For simple expressions, string format is clearest:
783
+
784
+ ```javascript
785
+ // Good
786
+ eq.loadFromJSON({ equation: "2x + 3 = 11" });
787
+
788
+ // Also works, but more verbose
789
+ eq.loadFromJSON({
790
+ leftExpression: { termsAndOpers: [...] },
791
+ rightExpression: { omdType: "number", value: 11 }
792
+ });
793
+ ```
794
+
795
+ ### Programmatic Generation
796
+
797
+ Use structured format for dynamic expression building:
798
+
799
+ ```javascript
800
+ function createPolynomial(coefficients) {
801
+ const termsAndOpers = [];
802
+
803
+ coefficients.forEach((coef, index) => {
804
+ const exponent = coefficients.length - index - 1;
805
+
806
+ if (index > 0) {
807
+ termsAndOpers.push({ omdType: "operator", operator: "+" });
808
+ }
809
+
810
+ termsAndOpers.push({
811
+ omdType: "term",
812
+ coefficient: coef,
813
+ variable: "x",
814
+ exponent: exponent
815
+ });
816
+ });
817
+
818
+ return { termsAndOpers };
819
+ }
820
+
821
+ // Usage
822
+ const quadratic = createPolynomial([1, -5, 6]);
823
+ // Generates: x² - 5x + 6
824
+ ```
825
+
826
+ ### Step-by-Step Solutions
827
+
828
+ Always provide clear explanations:
829
+
830
+ ```javascript
831
+ const steps = [
832
+ {
833
+ equation: omdEquationNode.fromString('2x + 3 = 11'),
834
+ explanation: 'Given equation'
835
+ },
836
+ {
837
+ equation: omdEquationNode.fromString('2x = 8'),
838
+ explanation: 'Subtract 3 from both sides'
839
+ },
840
+ {
841
+ equation: omdEquationNode.fromString('x = 4'),
842
+ explanation: 'Divide both sides by 2'
843
+ }
844
+ ];
845
+ ```
846
+
847
+ ---
848
+
849
+ ## Next Steps
850
+
851
+ - **[Visualizations Guide](./visualizations.md)** - Explore visual components
852
+ - **[JSON Schemas](../json-schemas.md)** - Complete reference
853
+ - **[API Reference](../api/api-reference.md)** - Detailed documentation
854
+ - **[Simplification Rules](../api/simplificationRules.md)** - Learn about available rules