diff --git a/test/typescript-tests/testTypes.ts b/test/typescript-tests/testTypes.ts index c58e59ffb0..735ac1148b 100644 --- a/test/typescript-tests/testTypes.ts +++ b/test/typescript-tests/testTypes.ts @@ -539,6 +539,10 @@ Chaining examples true ) + // leafCount + assert.strictEqual(math.leafCount(math.parse('x*y')), 2) + assert.strictEqual(math.chain(math.parse('x*y')).leafCount().done(), 2) + // slu expectTypeOf( math diff --git a/types/index.d.ts b/types/index.d.ts index 13bbb46661..16f4d16192 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1041,6 +1041,15 @@ export interface MathJsInstance extends MathJsFactory { simplifyConstant(expr: MathNode | string, options?: SimplifyOptions): MathNode simplifyCore(expr: MathNode | string, options?: SimplifyOptions): MathNode + /** + * Gives the number of “leaf nodes” in the parse tree of the given + * expression. A leaf node is one that has no subexpressions, essentially + * either a symbol or a constant. Note that `5!` has just one leaf, the `5`; + * the unary factorial operator does not add a leaf. On the other hand, + * function symbols do add leaves, so `sin(x)/cos(x)` has four leaves. + */ + leafCount(expr: MathNode): number + /** * Replaces variable nodes with their scoped values * @param node Tree to replace variable nodes in @@ -4888,6 +4897,15 @@ export interface MathJsChain { options?: SimplifyOptions ): MathJsChain + /** + * Gives the number of “leaf nodes” in the parse tree of the given + * expression. A leaf node is one that has no subexpressions, essentially + * either a symbol or a constant. Note that `5!` has just one leaf, the `5`; + * the unary factorial operator does not add a leaf. On the other hand, + * function symbols do add leaves, so `sin(x)/cos(x)` has four leaves. + */ + leafCount(this: MathJsChain): MathJsChain + /** * Calculate the Sparse Matrix LU decomposition with full pivoting. * Sparse Matrix A is decomposed in two matrices (L, U) and two @@ -6985,6 +7003,7 @@ export const { simplifyConstant, simplifyCore, symbolicEqual, + leafCount, resolve, slu, usolve,