Skip to content

Commit

Permalink
fix: #3246 add type definitions for function leafCount
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Sep 4, 2024
1 parent 8d244d2 commit 4c64018
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/typescript-tests/testTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -4888,6 +4897,15 @@ export interface MathJsChain<TValue> {
options?: SimplifyOptions
): MathJsChain<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(this: MathJsChain<MathNode>): MathJsChain<number>

/**
* Calculate the Sparse Matrix LU decomposition with full pivoting.
* Sparse Matrix A is decomposed in two matrices (L, U) and two
Expand Down Expand Up @@ -6985,6 +7003,7 @@ export const {
simplifyConstant,
simplifyCore,
symbolicEqual,
leafCount,
resolve,
slu,
usolve,
Expand Down

0 comments on commit 4c64018

Please sign in to comment.