MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / flattenForm

Function flattenForm

src/compute-engine/boxed-expression/canonical.ts:94–125  ·  view source on GitHub ↗

* Apply the "Flatten" form to the expression: * - remove delimiters * - flatten associative functions * * This function is recursive.

(expr: Expression)

Source from the content-addressed store, hash-verified

92 expr = numberForm(expr);
93 break;
94 case 'Multiply':
95 expr = multiplyForm(expr);
96 break;
97 case 'Add':
98 expr = addForm(expr);
99 break;
100 case 'Power':
101 expr = powerForm(expr);
102 break;
103 case 'Divide':
104 expr = divideForm(expr);
105 break;
106 case 'Flatten':
107 // Flatten ops, delimiters and sequences
108 expr = flattenForm(expr);
109 break;
110 case 'Order':
111 expr = canonicalOrder(expr, { recursive: true });
112 break;
113 default:
114 throw Error('Invalid canonical form');
115 }
116 }
117
118 // Partial canonicalization produces a structural expression, not a fully
119 // canonical one. This allows subsequent .canonical calls to perform full
120 // canonicalization.
121 if (isFunction(expr) && expr.isCanonical) {
122 expr = expr.engine.function(expr.operator, [...expr.ops!], {
123 form: 'structural',
124 });
125 }
126
127 return expr;
128}

Callers 1

canonicalFormFunction · 0.85

Calls 6

isFunctionFunction · 0.90
isOperatorDefFunction · 0.90
flattenFunction · 0.90
lookupDefinitionMethod · 0.65
_fnMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected