mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
57 lines
1.7 KiB
Markdown
57 lines
1.7 KiB
Markdown
---
|
|
layout: default
|
|
---
|
|
|
|
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|
|
|
|
<h1 id="function-leafcount">Function leafCount <a href="#function-leafcount" title="Permalink">#</a></h1>
|
|
|
|
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.
|
|
|
|
The `simplify()` function should generally not increase the `leafCount()`
|
|
of an expression, although currently there is no guarantee that it never
|
|
does so. In many cases, `simplify()` reduces the leaf count.
|
|
|
|
|
|
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
math.leafCount(expr)
|
|
```
|
|
|
|
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
|
|
|
|
Parameter | Type | Description
|
|
--------- | ---- | -----------
|
|
`expr` | Node | string | The expression to count the leaves of
|
|
|
|
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
number | The number of leaves of `expr`
|
|
|
|
|
|
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
|
|
|
|
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
math.leafCount('x') // 1
|
|
math.leafCount(math.parse('a*d-b*c')) // 4
|
|
math.leafCount('[a,b;c,d][0,1]') // 6
|
|
```
|
|
|
|
|
|
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
|
|
|
|
[simplify](simplify.html)
|