Skip to main content

merge

Overloads

NameDescription
merge(ComplexOperatorSum input) -> ComplexOperatorSumSimplifies an OperatorSum by combining like terms (in-place).
merge(RealOperatorSum input) -> RealOperatorSumSimplifies an OperatorSum by combining like terms (in-place).

merge(ComplexOperatorSum input) -> ComplexOperatorSum

Simplifies an OperatorSum by combining like terms (in-place).

This function merges coefficients of identical operators in the sum, modifying the input directly. For example, terms like 2.0*X(0) and 3.0*X(0) are combined into 5.0*X(0). Near-zero coefficient terms are also removed, becoming an empty operator (), during the process.

Parameters

  • input: The input OperatorSum to be modified in-place.

Returns

Reference to the modified OperatorSum (allows method chaining)

Example

var my_sum = 2.0*X(0) + Y(1) + 3.0*X(0);
merge(my_sum); // Modifies my_sum to (5 * X(0) + 1 * Y(1))

// Alternative syntax:
my_sum.merge(); // Same result, member function style

// Method chaining example:
var result = merge(my_sum); // result refers to the same modified my_sum

merge(RealOperatorSum input) -> RealOperatorSum

Simplifies an OperatorSum by combining like terms (in-place).

This function merges coefficients of identical operators in the sum, modifying the input directly. For example, terms like 2.0*X(0) and 3.0*X(0) are combined into 5.0*X(0). Near-zero coefficient terms are also removed, becoming an empty operator (), during the process.

Parameters

  • input: The input OperatorSum to be modified in-place.

Returns

Reference to the modified OperatorSum (allows method chaining)

Example

var my_sum = 2.0*X(0) + Y(1) + 3.0*X(0);
merge(my_sum); // Modifies my_sum to (5 * X(0) + 1 * Y(1))

// Alternative syntax:
my_sum.merge(); // Same result, member function style

// Method chaining example:
var result = merge(my_sum); // result refers to the same modified my_sum