@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,98 +1,98 @@
1
- # SimplificationEngine
2
-
3
- The `SimplificationEngine` is a static class that provides a collection of helper methods for creating, matching, and transforming expression nodes. It forms the backbone of the simplification rule system.
4
-
5
- ## Overview
6
-
7
- The engine is not instantiated. Instead, its static methods are used directly by the simplification rules to perform their logic. The methods can be grouped into several categories:
8
-
9
- - **Node Creation:** Helpers to build new `omdNode` instances (e.g., `createConstant`, `createBinaryOp`).
10
- - **Pattern Matching:** Helpers to check if a node matches a specific structure or value (e.g., `isBinaryOp`, `isConstantValue`).
11
- - **Monomial Helpers:** Specialized functions for working with monomials (terms like `2x^2`), which are essential for rules like combining like terms.
12
- - **Rule Definition:** The `SimplificationRule` inner class, which defines the structure for all simplification rules.
13
-
14
- ## Node Creation Helpers
15
-
16
- These methods simplify the process of creating new nodes, often by abstracting away the underlying AST structure.
17
-
18
- #### `createConstant(value, fontSize)`
19
- - Creates an `omdConstantNode`.
20
-
21
- #### `createBinaryOp(left, operator, right, ...)`
22
- - Creates an `omdBinaryExpressionNode` for operations like 'add', 'subtract', etc.
23
-
24
- #### `createMultiplication(leftConstantNode, rightNode, ...)`
25
- - A specialized version of `createBinaryOp` for multiplication.
26
-
27
- #### `createRational(numerator, denominator, fontSize)`
28
- - Creates an `omdRationalNode` (a fraction).
29
-
30
- #### `createMonomial(coefficient, variable, power, ...)`
31
- - Constructs a complete monomial term (e.g., `2x^3`) from its constituent parts.
32
-
33
- ## Pattern Matching Helpers
34
-
35
- These methods are used within the `match` function of a simplification rule to determine if the rule applies to a given node.
36
-
37
- #### `isType(node, typeName)`
38
- - Checks if a node is an instance of a specific class (e.g., `'omdConstantNode'`).
39
-
40
- #### `isBinaryOp(node, operator)`
41
- - Checks if a node is a binary operation, optionally matching a specific operator (e.g., `'add'`).
42
-
43
- #### `isConstantValue(node, value)`
44
- - Checks if a node is a constant, optionally matching a specific value.
45
-
46
- #### `hasConstantOperand(node)`
47
- - For a binary operation, checks if one of its operands is a constant and returns both the constant and the other operand.
48
-
49
- #### `unwrapParentheses(node)`
50
- - If the given node is an `omdParenthesisNode`, it returns the inner expression; otherwise, it returns the node itself.
51
-
52
- ## Monomial and Like Terms Helpers
53
-
54
- #### `isMonomial(node)`
55
- - A powerful helper that checks if a node represents a monomial (e.g., `x`, `2x`, `-5x^2`).
56
- - **Returns:** An object with `{ coefficient, variable, power, ... }` if it is a monomial, otherwise `null`.
57
-
58
- #### `areLikeTerms(monomial1, monomial2)`
59
- - Compares the output of two `isMonomial` calls to see if they have the same variable and power.
60
-
61
- ## `SimplificationRule` Class
62
-
63
- This is an inner class of `SimplificationEngine` that provides the blueprint for all simplification rules.
64
-
65
- ### Constructor
66
-
67
- `new SimplificationRule(name, matchFn, transformFn, messageFn, type)`
68
-
69
- - `name` {string}: The name of the rule (e.g., "Combine Constants").
70
- - `matchFn` {function}: A function that takes a node and returns `true` or a data object if the rule applies, `false` otherwise.
71
- - `transformFn` {function}: A function that takes the matched node and the data from `matchFn` and returns a new, transformed node.
72
- - `messageFn` {function} (optional): A function to generate a user-friendly description of the change.
73
-
74
- ### Key Methods
75
-
76
- - `canApply(node)`: Executes the `matchFn`.
77
- - `apply(node, ruleData, currentRoot)`: Executes the `transformFn` and handles replacing the old node with the new one in the expression tree.
78
-
79
- ## Rule Factory Functions
80
-
81
- These are static methods on `SimplificationEngine` that create common types of rules.
82
-
83
- #### `createRule(...)`
84
- - The base factory function for creating a `SimplificationRule` instance.
85
-
86
- #### `createConstantFoldRule(name, operator)`
87
- - Creates a rule that evaluates binary operations on two constants (e.g., `2 + 3` -> `5`).
88
-
89
- #### `createIdentityRule(name, operator, identityValue, side)`
90
- - Creates a rule for identity operations (e.g., `x + 0` -> `x` or `y * 1` -> `y`).
91
-
92
- #### `createZeroMultiplicationRule()`
93
- - Creates the rule for `x * 0` -> `0`.
94
-
95
- ### See Also
96
-
97
- - [`omdSimplification`](./omdSimplification.md): The top-level module that uses the engine.
1
+ # SimplificationEngine
2
+
3
+ The `SimplificationEngine` is a static class that provides a collection of helper methods for creating, matching, and transforming expression nodes. It forms the backbone of the simplification rule system.
4
+
5
+ ## Overview
6
+
7
+ The engine is not instantiated. Instead, its static methods are used directly by the simplification rules to perform their logic. The methods can be grouped into several categories:
8
+
9
+ - **Node Creation:** Helpers to build new `omdNode` instances (e.g., `createConstant`, `createBinaryOp`).
10
+ - **Pattern Matching:** Helpers to check if a node matches a specific structure or value (e.g., `isBinaryOp`, `isConstantValue`).
11
+ - **Monomial Helpers:** Specialized functions for working with monomials (terms like `2x^2`), which are essential for rules like combining like terms.
12
+ - **Rule Definition:** The `SimplificationRule` inner class, which defines the structure for all simplification rules.
13
+
14
+ ## Node Creation Helpers
15
+
16
+ These methods simplify the process of creating new nodes, often by abstracting away the underlying AST structure.
17
+
18
+ #### `createConstant(value, fontSize)`
19
+ - Creates an `omdConstantNode`.
20
+
21
+ #### `createBinaryOp(left, operator, right, ...)`
22
+ - Creates an `omdBinaryExpressionNode` for operations like 'add', 'subtract', etc.
23
+
24
+ #### `createMultiplication(leftConstantNode, rightNode, ...)`
25
+ - A specialized version of `createBinaryOp` for multiplication.
26
+
27
+ #### `createRational(numerator, denominator, fontSize)`
28
+ - Creates an `omdRationalNode` (a fraction).
29
+
30
+ #### `createMonomial(coefficient, variable, power, ...)`
31
+ - Constructs a complete monomial term (e.g., `2x^3`) from its constituent parts.
32
+
33
+ ## Pattern Matching Helpers
34
+
35
+ These methods are used within the `match` function of a simplification rule to determine if the rule applies to a given node.
36
+
37
+ #### `isType(node, typeName)`
38
+ - Checks if a node is an instance of a specific class (e.g., `'omdConstantNode'`).
39
+
40
+ #### `isBinaryOp(node, operator)`
41
+ - Checks if a node is a binary operation, optionally matching a specific operator (e.g., `'add'`).
42
+
43
+ #### `isConstantValue(node, value)`
44
+ - Checks if a node is a constant, optionally matching a specific value.
45
+
46
+ #### `hasConstantOperand(node)`
47
+ - For a binary operation, checks if one of its operands is a constant and returns both the constant and the other operand.
48
+
49
+ #### `unwrapParentheses(node)`
50
+ - If the given node is an `omdParenthesisNode`, it returns the inner expression; otherwise, it returns the node itself.
51
+
52
+ ## Monomial and Like Terms Helpers
53
+
54
+ #### `isMonomial(node)`
55
+ - A powerful helper that checks if a node represents a monomial (e.g., `x`, `2x`, `-5x^2`).
56
+ - **Returns:** An object with `{ coefficient, variable, power, ... }` if it is a monomial, otherwise `null`.
57
+
58
+ #### `areLikeTerms(monomial1, monomial2)`
59
+ - Compares the output of two `isMonomial` calls to see if they have the same variable and power.
60
+
61
+ ## `SimplificationRule` Class
62
+
63
+ This is an inner class of `SimplificationEngine` that provides the blueprint for all simplification rules.
64
+
65
+ ### Constructor
66
+
67
+ `new SimplificationRule(name, matchFn, transformFn, messageFn, type)`
68
+
69
+ - `name` {string}: The name of the rule (e.g., "Combine Constants").
70
+ - `matchFn` {function}: A function that takes a node and returns `true` or a data object if the rule applies, `false` otherwise.
71
+ - `transformFn` {function}: A function that takes the matched node and the data from `matchFn` and returns a new, transformed node.
72
+ - `messageFn` {function} (optional): A function to generate a user-friendly description of the change.
73
+
74
+ ### Key Methods
75
+
76
+ - `canApply(node)`: Executes the `matchFn`.
77
+ - `apply(node, ruleData, currentRoot)`: Executes the `transformFn` and handles replacing the old node with the new one in the expression tree.
78
+
79
+ ## Rule Factory Functions
80
+
81
+ These are static methods on `SimplificationEngine` that create common types of rules.
82
+
83
+ #### `createRule(...)`
84
+ - The base factory function for creating a `SimplificationRule` instance.
85
+
86
+ #### `createConstantFoldRule(name, operator)`
87
+ - Creates a rule that evaluates binary operations on two constants (e.g., `2 + 3` -> `5`).
88
+
89
+ #### `createIdentityRule(name, operator, identityValue, side)`
90
+ - Creates a rule for identity operations (e.g., `x + 0` -> `x` or `y * 1` -> `y`).
91
+
92
+ #### `createZeroMultiplicationRule()`
93
+ - Creates the rule for `x * 0` -> `0`.
94
+
95
+ ### See Also
96
+
97
+ - [`omdSimplification`](./omdSimplification.md): The top-level module that uses the engine.
98
98
  - [`simplificationRules`](./simplificationRules.md): The module where specific rules are defined using the engine's helpers.
@@ -1,77 +1,77 @@
1
- # Simplification Rules
2
-
3
- This module defines the specific simplification rules used by the `SimplificationEngine`. The rules are organized into an object, keyed by the `omdNode` type they apply to.
4
-
5
- ## Rule Structure
6
-
7
- Each rule is an instance of `SimplificationEngine.SimplificationRule` and has three main parts:
8
-
9
- 1. **`match` function:** Determines if the rule can be applied to a given node.
10
- 2. **`transform` function:** Executes the simplification and returns a new, transformed node.
11
- 3. **`message` function:** Generates a human-readable description of the transformation.
12
-
13
- ## Available Rules
14
-
15
- The `rules` object contains arrays of rules for each of the following node types:
16
-
17
- ### `binary` (for `omdBinaryExpressionNode`)
18
-
19
- - **Same Term Cancellation:** `a - a` simplifies to `0`.
20
- - **Opposite Term Cancellation:** `a + (-a)` simplifies to `0`.
21
- - **Cancel Constants in Sums:** `x + 2 - 2` simplifies to `x + 0`.
22
- - **Constant Folding:** Evaluates operations on constants (e.g., `2 + 3` -> `5`). Includes rules for `add`, `subtract`, `multiply`, and `divide`.
23
- - **Identity Operations:** Simplifies operations with identity elements (e.g., `x + 0` -> `x`, `y * 1` -> `y`).
24
- - **Zero Multiplication:** `x * 0` simplifies to `0`.
25
- - **Combine Coefficients:** `2 * 3x` simplifies to `6x`.
26
- - **Distributive Property:** `2 * (x + 3)` expands to `2x + 6`.
27
- - **Expand Polynomial Multiplication:** `(x + 2)(x + 3)` expands to `x^2 + 5x + 6`.
28
- - **Multiply Monomials:** `2x * 3x` simplifies to `6x^2`.
29
- - **Combine Like Factors:** `x * x` simplifies to `x^2`.
30
- - **Combine Multiple Constants in Sums:** `x + 2 + 3` simplifies to `x + 5`.
31
- - **Combine Like Terms:** `2x + 3x` simplifies to `5x`.
32
-
33
- ### `rational` (for `omdRationalNode`)
34
-
35
- - **Variable Self Division:** `x / x` simplifies to `1`.
36
- - **Power Base Division:** `x^n / x` simplifies to `x^(n-1)`.
37
- - **Monomial Variable Division:** `cx / x` simplifies to `c`.
38
- - **Simplify Fraction:** Reduces constant fractions to their simplest form (e.g., `6/8` -> `3/4`).
39
- - **Simplify Multiplication in Rational:** `(4x)/3` restructures to `(4/3) * x`.
40
- - **Simplify Rational Division:** `(4x + 6) / 2` distributes the division to `2x + 3`.
41
-
42
- ### `parenthesis` (for `omdParenthesisNode`)
43
-
44
- - **Remove Redundant Parentheses:** `((x))` simplifies to `(x)`.
45
-
46
- ### `unary` (for `omdUnaryExpressionNode`)
47
-
48
- - **Simplify Double Negation:** `-(-x)` simplifies to `x`.
49
- - **Remove Unary Plus:** `+x` simplifies to `x`.
50
-
51
- ### `power` (for `omdPowerNode`)
52
-
53
- - **Calculate Powers:** Evaluates constant powers (e.g., `2^3` -> `8`).
54
- - **Power of Zero:** `x^0` simplifies to `1`.
55
- - **Power of One:** `x^1` simplifies to `x`.
56
- - **Expand Polynomial Power:** `(x - 2)^2` expands to `x^2 - 4x + 4`.
57
- - **Square of Square Root:** `(sqrt(x))^2` simplifies to `x`.
58
- - **Fractional Exponent to Square Root:** `x^(1/2)` converts to `sqrt(x)`.
59
-
60
- ### `sqrt` (for `omdSqrtNode`)
61
-
62
- - **Simplify Square Root of Constant:** `sqrt(9)` simplifies to `3`.
63
- - **Square Root of Square:** `sqrt(x^2)` simplifies to `x` (assuming `x >= 0`).
64
-
65
- ### `function` (for `omdFunctionNode`)
66
-
67
- - **Function Inverse Simplification:** `sin(arcsin(x))` simplifies to `x`.
68
- - **Function to Sqrt Node:** Converts `sqrt(x)` from a function representation to the dedicated `omdSqrtNode`.
69
-
70
- ## Rule Lookup
71
-
72
- The `getRulesForNode(node)` function is used by the simplification engine to retrieve the appropriate list of rules for a given node based on its type.
73
-
74
- ### See Also
75
-
76
- - [`omdSimplification`](./omdSimplification.md): The top-level module that uses these rules.
1
+ # Simplification Rules
2
+
3
+ This module defines the specific simplification rules used by the `SimplificationEngine`. The rules are organized into an object, keyed by the `omdNode` type they apply to.
4
+
5
+ ## Rule Structure
6
+
7
+ Each rule is an instance of `SimplificationEngine.SimplificationRule` and has three main parts:
8
+
9
+ 1. **`match` function:** Determines if the rule can be applied to a given node.
10
+ 2. **`transform` function:** Executes the simplification and returns a new, transformed node.
11
+ 3. **`message` function:** Generates a human-readable description of the transformation.
12
+
13
+ ## Available Rules
14
+
15
+ The `rules` object contains arrays of rules for each of the following node types:
16
+
17
+ ### `binary` (for `omdBinaryExpressionNode`)
18
+
19
+ - **Same Term Cancellation:** `a - a` simplifies to `0`.
20
+ - **Opposite Term Cancellation:** `a + (-a)` simplifies to `0`.
21
+ - **Cancel Constants in Sums:** `x + 2 - 2` simplifies to `x + 0`.
22
+ - **Constant Folding:** Evaluates operations on constants (e.g., `2 + 3` -> `5`). Includes rules for `add`, `subtract`, `multiply`, and `divide`.
23
+ - **Identity Operations:** Simplifies operations with identity elements (e.g., `x + 0` -> `x`, `y * 1` -> `y`).
24
+ - **Zero Multiplication:** `x * 0` simplifies to `0`.
25
+ - **Combine Coefficients:** `2 * 3x` simplifies to `6x`.
26
+ - **Distributive Property:** `2 * (x + 3)` expands to `2x + 6`.
27
+ - **Expand Polynomial Multiplication:** `(x + 2)(x + 3)` expands to `x^2 + 5x + 6`.
28
+ - **Multiply Monomials:** `2x * 3x` simplifies to `6x^2`.
29
+ - **Combine Like Factors:** `x * x` simplifies to `x^2`.
30
+ - **Combine Multiple Constants in Sums:** `x + 2 + 3` simplifies to `x + 5`.
31
+ - **Combine Like Terms:** `2x + 3x` simplifies to `5x`.
32
+
33
+ ### `rational` (for `omdRationalNode`)
34
+
35
+ - **Variable Self Division:** `x / x` simplifies to `1`.
36
+ - **Power Base Division:** `x^n / x` simplifies to `x^(n-1)`.
37
+ - **Monomial Variable Division:** `cx / x` simplifies to `c`.
38
+ - **Simplify Fraction:** Reduces constant fractions to their simplest form (e.g., `6/8` -> `3/4`).
39
+ - **Simplify Multiplication in Rational:** `(4x)/3` restructures to `(4/3) * x`.
40
+ - **Simplify Rational Division:** `(4x + 6) / 2` distributes the division to `2x + 3`.
41
+
42
+ ### `parenthesis` (for `omdParenthesisNode`)
43
+
44
+ - **Remove Redundant Parentheses:** `((x))` simplifies to `(x)`.
45
+
46
+ ### `unary` (for `omdUnaryExpressionNode`)
47
+
48
+ - **Simplify Double Negation:** `-(-x)` simplifies to `x`.
49
+ - **Remove Unary Plus:** `+x` simplifies to `x`.
50
+
51
+ ### `power` (for `omdPowerNode`)
52
+
53
+ - **Calculate Powers:** Evaluates constant powers (e.g., `2^3` -> `8`).
54
+ - **Power of Zero:** `x^0` simplifies to `1`.
55
+ - **Power of One:** `x^1` simplifies to `x`.
56
+ - **Expand Polynomial Power:** `(x - 2)^2` expands to `x^2 - 4x + 4`.
57
+ - **Square of Square Root:** `(sqrt(x))^2` simplifies to `x`.
58
+ - **Fractional Exponent to Square Root:** `x^(1/2)` converts to `sqrt(x)`.
59
+
60
+ ### `sqrt` (for `omdSqrtNode`)
61
+
62
+ - **Simplify Square Root of Constant:** `sqrt(9)` simplifies to `3`.
63
+ - **Square Root of Square:** `sqrt(x^2)` simplifies to `x` (assuming `x >= 0`).
64
+
65
+ ### `function` (for `omdFunctionNode`)
66
+
67
+ - **Function Inverse Simplification:** `sin(arcsin(x))` simplifies to `x`.
68
+ - **Function to Sqrt Node:** Converts `sqrt(x)` from a function representation to the dedicated `omdSqrtNode`.
69
+
70
+ ## Rule Lookup
71
+
72
+ The `getRulesForNode(node)` function is used by the simplification engine to retrieve the appropriate list of rules for a given node based on its type.
73
+
74
+ ### See Also
75
+
76
+ - [`omdSimplification`](./omdSimplification.md): The top-level module that uses these rules.
77
77
  - [`SimplificationEngine`](./simplificationEngine.md): The engine that provides the helpers to create and apply these rules.
@@ -1,64 +1,64 @@
1
- # Simplification Utilities
2
-
3
- This module provides a collection of helper functions that are used throughout the simplification engine and rules. These utilities handle common tasks like creating nodes, manipulating expression trees, and formatting output.
4
-
5
- ## Core Functions
6
-
7
- #### `gcd(a, b)`
8
- - Calculates the greatest common divisor of two numbers.
9
-
10
- #### `createConstantNode(value, fontSize)`
11
- - Creates a new, fully initialized `omdConstantNode`.
12
-
13
- #### `createRationalNode(numerator, denominator, fontSize)`
14
- - Creates a new, fully initialized `omdRationalNode`, handling negative numerators and cases where the denominator is 1.
15
-
16
- #### `nodeToString(node)`
17
- - A robust function that converts any `omdNode` into a human-readable string, handling different node types and formatting them correctly.
18
-
19
- ## Expression Tree Manipulation
20
-
21
- #### `flattenSum(node, terms)`
22
- - A key utility that takes a nested tree of additions and subtractions (e.g., `a - (b + c)`) and flattens it into a linear list of terms, each with an associated sign.
23
- - **Parameters:**
24
- - `node`: The root of the expression to flatten.
25
- - `terms`: An array that will be populated with the term objects (`{ node, sign }`).
26
-
27
- #### `buildSumTree(terms, fontSize)`
28
- - The counterpart to `flattenSum`. It takes a list of terms (like the one produced by `flattenSum`) and reconstructs a valid, balanced `omdBinaryExpressionNode` tree from them.
29
-
30
- #### `_replaceNodeInTree(oldNode, newNode, currentRoot)`
31
- - An internal helper that safely replaces a node within the larger expression tree, handling parent-child connections and ensuring the tree remains valid.
32
-
33
- ## Polynomial and Monomial Helpers
34
-
35
- #### `expandPolynomialPower(terms, exponent, fontSize)`
36
- - Expands a polynomial raised to a power (e.g., `(a+b)^2`). It uses more specific helpers for common cases.
37
-
38
- #### `expandBinomialSquare(terms, fontSize)`
39
- - Expands `(a+b+...)^2`.
40
-
41
- #### `expandBinomialCube(terms, fontSize)`
42
- - Expands `(a+b)^3`.
43
-
44
- #### `expandBinomialFourth(terms, fontSize)`
45
- - Expands `(a+b)^4`.
46
-
47
- #### `multiplyTermArrays(terms1, terms2, fontSize)`
48
- - Performs polynomial multiplication by multiplying each term from the first array by each term from the second.
49
-
50
- ## Provenance Helpers
51
-
52
- #### `extractLeafNodes(node)`
53
- - Traverses an expression and returns an array of all its leaf nodes (constants and variables). This is used for detailed provenance tracking.
54
-
55
- #### `extractMonomialProvenance(termNode)`
56
- - A specialized function that separates the leaf nodes of a monomial into `coefficientNodes` and `variableNodes` for highly granular highlighting.
57
-
58
- #### `createMonomialWithGranularProvenance(...)`
59
- - Creates a monomial while assigning separate provenance chains to its coefficient and variable parts.
60
-
61
- ### See Also
62
-
63
- - [`omdSimplification`](./omdSimplification.md)
64
- - [`simplificationRules`](./simplificationRules.md)
1
+ # Simplification Utilities
2
+
3
+ This module provides a collection of helper functions that are used throughout the simplification engine and rules. These utilities handle common tasks like creating nodes, manipulating expression trees, and formatting output.
4
+
5
+ ## Core Functions
6
+
7
+ #### `gcd(a, b)`
8
+ - Calculates the greatest common divisor of two numbers.
9
+
10
+ #### `createConstantNode(value, fontSize)`
11
+ - Creates a new, fully initialized `omdConstantNode`.
12
+
13
+ #### `createRationalNode(numerator, denominator, fontSize)`
14
+ - Creates a new, fully initialized `omdRationalNode`, handling negative numerators and cases where the denominator is 1.
15
+
16
+ #### `nodeToString(node)`
17
+ - A robust function that converts any `omdNode` into a human-readable string, handling different node types and formatting them correctly.
18
+
19
+ ## Expression Tree Manipulation
20
+
21
+ #### `flattenSum(node, terms)`
22
+ - A key utility that takes a nested tree of additions and subtractions (e.g., `a - (b + c)`) and flattens it into a linear list of terms, each with an associated sign.
23
+ - **Parameters:**
24
+ - `node`: The root of the expression to flatten.
25
+ - `terms`: An array that will be populated with the term objects (`{ node, sign }`).
26
+
27
+ #### `buildSumTree(terms, fontSize)`
28
+ - The counterpart to `flattenSum`. It takes a list of terms (like the one produced by `flattenSum`) and reconstructs a valid, balanced `omdBinaryExpressionNode` tree from them.
29
+
30
+ #### `_replaceNodeInTree(oldNode, newNode, currentRoot)`
31
+ - An internal helper that safely replaces a node within the larger expression tree, handling parent-child connections and ensuring the tree remains valid.
32
+
33
+ ## Polynomial and Monomial Helpers
34
+
35
+ #### `expandPolynomialPower(terms, exponent, fontSize)`
36
+ - Expands a polynomial raised to a power (e.g., `(a+b)^2`). It uses more specific helpers for common cases.
37
+
38
+ #### `expandBinomialSquare(terms, fontSize)`
39
+ - Expands `(a+b+...)^2`.
40
+
41
+ #### `expandBinomialCube(terms, fontSize)`
42
+ - Expands `(a+b)^3`.
43
+
44
+ #### `expandBinomialFourth(terms, fontSize)`
45
+ - Expands `(a+b)^4`.
46
+
47
+ #### `multiplyTermArrays(terms1, terms2, fontSize)`
48
+ - Performs polynomial multiplication by multiplying each term from the first array by each term from the second.
49
+
50
+ ## Provenance Helpers
51
+
52
+ #### `extractLeafNodes(node)`
53
+ - Traverses an expression and returns an array of all its leaf nodes (constants and variables). This is used for detailed provenance tracking.
54
+
55
+ #### `extractMonomialProvenance(termNode)`
56
+ - A specialized function that separates the leaf nodes of a monomial into `coefficientNodes` and `variableNodes` for highly granular highlighting.
57
+
58
+ #### `createMonomialWithGranularProvenance(...)`
59
+ - Creates a monomial while assigning separate provenance chains to its coefficient and variable parts.
60
+
61
+ ### See Also
62
+
63
+ - [`omdSimplification`](./omdSimplification.md)
64
+ - [`simplificationRules`](./simplificationRules.md)
@@ -1,43 +1,43 @@
1
- # Netlify Function: transcribe
2
-
3
- This Netlify serverless function provides a backend for the `omdTranscriptionService`. It receives an image, sends it to the Gemini API for transcription, and returns the result.
4
-
5
- ## Endpoint
6
-
7
- `/.netlify/functions/transcribe`
8
-
9
- ## Method
10
-
11
- `POST`
12
-
13
- ## Request Body
14
-
15
- The request body should be a JSON object with the following properties:
16
-
17
- * **imageBase64** (`string`, required): The base64 encoded image data (without the `data:image/png;base64,` prefix).
18
- * **prompt** (`string`, optional): A custom prompt to guide the transcription. If not provided, a default prompt for mathematical expressions is used.
19
-
20
- ## Responses
21
-
22
- ### Success Response (200 OK)
23
-
24
- A successful response will be a JSON object with the following properties:
25
-
26
- * **text** (`string`): The transcribed text.
27
- * **provider** (`string`): The transcription provider used (always `'gemini'`).
28
- * **confidence** (`number`): The confidence score of the transcription (currently hardcoded to `1.0`).
29
-
30
- ### Error Responses
31
-
32
- * **400 Bad Request**: This error is returned if the `imageBase64` property is missing from the request body.
33
- * **500 Internal Server Error**: This error is returned if there is an issue with the transcription process on the server, such as an error from the Gemini API.
34
-
35
- ## Environment Variables
36
-
37
- This function requires the following environment variable to be set in your Netlify environment:
38
-
39
- * `GEMINI_API_KEY`: Your API key for the Gemini service.
40
-
41
- ## CORS
42
-
43
- The function is configured to allow cross-origin requests from any origin.
1
+ # Netlify Function: transcribe
2
+
3
+ This Netlify serverless function provides a backend for the `omdTranscriptionService`. It receives an image, sends it to the Gemini API for transcription, and returns the result.
4
+
5
+ ## Endpoint
6
+
7
+ `/.netlify/functions/transcribe`
8
+
9
+ ## Method
10
+
11
+ `POST`
12
+
13
+ ## Request Body
14
+
15
+ The request body should be a JSON object with the following properties:
16
+
17
+ * **imageBase64** (`string`, required): The base64 encoded image data (without the `data:image/png;base64,` prefix).
18
+ * **prompt** (`string`, optional): A custom prompt to guide the transcription. If not provided, a default prompt for mathematical expressions is used.
19
+
20
+ ## Responses
21
+
22
+ ### Success Response (200 OK)
23
+
24
+ A successful response will be a JSON object with the following properties:
25
+
26
+ * **text** (`string`): The transcribed text.
27
+ * **provider** (`string`): The transcription provider used (always `'gemini'`).
28
+ * **confidence** (`number`): The confidence score of the transcription (currently hardcoded to `1.0`).
29
+
30
+ ### Error Responses
31
+
32
+ * **400 Bad Request**: This error is returned if the `imageBase64` property is missing from the request body.
33
+ * **500 Internal Server Error**: This error is returned if there is an issue with the transcription process on the server, such as an error from the Gemini API.
34
+
35
+ ## Environment Variables
36
+
37
+ This function requires the following environment variable to be set in your Netlify environment:
38
+
39
+ * `GEMINI_API_KEY`: Your API key for the Gemini service.
40
+
41
+ ## CORS
42
+
43
+ The function is configured to allow cross-origin requests from any origin.