leafCount.md (1202B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 2 3 # Function leafCount 4 5 Gives the number of "leaf nodes" in the parse tree of the given expression 6 A leaf node is one that has no subexpressions, essentially either a 7 symbol or a constant. Note that `5!` has just one leaf, the '5'; the 8 unary factorial operator does not add a leaf. On the other hand, 9 function symbols do add leaves, so `sin(x)/cos(x)` has four leaves. 10 11 The `simplify()` function should generally not increase the `leafCount()` 12 of an expression, although currently there is no guarantee that it never 13 does so. In many cases, `simplify()` reduces the leaf count. 14 15 16 ## Syntax 17 18 ```js 19 leafCount(expr) 20 ``` 21 22 ### Parameters 23 24 Parameter | Type | Description 25 --------- | ---- | ----------- 26 `expr` | Node | string | The expression to count the leaves of 27 28 ### Returns 29 30 Type | Description 31 ---- | ----------- 32 number | The number of leaves of `expr` 33 34 35 ### Throws 36 37 Type | Description 38 ---- | ----------- 39 40 41 ## Examples 42 43 ```js 44 math.leafCount('x') // 1 45 math.leafCount(math.parse('a*d-b*c')) // 4 46 math.leafCount('[a,b;c,d][0,1]') // 6 47 ``` 48 49 50 ## See also 51 52 [simplify](simplify.md)