mathjs/docs/reference/functions/simplifyConstant.md
2023-06-13 12:21:04 +02:00

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-simplifyconstant">Function simplifyConstant <a href="#function-simplifyconstant" title="Permalink">#</a></h1>
simplifyConstant() takes a mathjs expression (either a Node representing
a parse tree or a string which it parses to produce a node), and replaces
any subexpression of it consisting entirely of constants with the computed
value of that subexpression.
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
math.simplifyConstant(expr)
math.simplifyConstant(expr, options)
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`node` | Node &#124; string | The expression to be simplified
`options` | Object | Simplification options, as per simplify()
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
Node | Returns expression with constant subexpressions evaluated
<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.simplifyConstant('x + 4*3/6') // Node "x + 2"
math.simplifyConstant('z cos(0)') // Node "z 1"
math.simplifyConstant('(5.2 + 1.08)t', {exactFractions: false}) // Node "6.28 t"
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[simplify](simplify.html),
[simplifyCore](simplifyCore.html),
[resolve](resolve.html),
[derivative](derivative.html)