OMD Documentation

omdBinaryExpressionNode

Represents a binary operation in a mathematical expression, such as addition (a + b), subtraction, multiplication, or division. This node is a cornerstone of the expression tree, containing a left operand, a right operand, and an operator.

Class Definition

export class omdBinaryExpressionNode extends omdNode

Constructor

new omdBinaryExpressionNode(ast)

Creates a new omdBinaryExpressionNode instance.

During construction, the node automatically handles a critical piece of mathematical convention: implicit multiplication. Based on the configuration in omdConfigManager, it will:

  1. Reorder Operands: If it encounters an expression like x * 2, it will automatically reorder it to the conventional 2 * x by swapping the left and right child nodes.
  2. Determine Implicit Form: It checks if the combination of operands (e.g., a constant and a variable) should be represented implicitly. If so, it removes the visible operator (*) and marks the node as implicit.

Public Properties

Public Methods

clone()

Creates a deep, recursive clone of the node, including its children (left, right, op). The new node's provenance property will link back to the ID of this original node.

evaluate(variables)

Recursively evaluates the expression and returns the numerical result.

needsParentheses()

Determines if this expression needs to be wrapped in parentheses to maintain the correct order of operations when it is a child of another binary expression.

setHighlight(highlightOn, color)

Applies or removes a highlight from the node and all of its children (left, right, and operator).

clearProvenanceHighlights()

Recursively clears all provenance-related highlights from this node and its children.

toMathJSNode()

Converts the node back into a math.js-compatible AST format.

toString()

Converts the node into a human-readable string, automatically handling parentheses for precedence.

Internal Methods

↑ Top