mathjs
Version:
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif
63 lines (44 loc) • 1.86 kB
Markdown
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
Attempts to determine if two expressions are symbolically equal, i.e.
one is the result of valid algebraic manipulations on the other.
Currently, this simply checks if the difference of the two expressions
simplifies down to 0. So there are two important caveats:
1. whether two expressions are symbolically equal depends on the
manipulations allowed. Therefore, this function takes an optional
third argument, which are the options that control the behavior
as documented for the `simplify()` function.
2. it is in general intractable to find the minimal simplification of
an arbitrarily complicated expression. So while a `true` value
of `symbolicEqual` ensures that the two expressions can be manipulated
to match each other, a `false` value does not absolutely rule this out.
```js
symbolicEqual(expr1, expr2)
symbolicEqual(expr1, expr2, options)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`expr1` | Node | string | The first expression to compare
`expr2` | Node &
`options` | Object | Optional option object, passed to simplify
Type | Description
---- | -----------
boolean | Returns true if a valid manipulation making the expressions equal is found.
Type | Description
---- | -----------
```js
symbolicEqual('x*y', 'y*x') // true
symbolicEqual('x*y', 'y*x', {context: {multiply: {commutative: false}}})
//false
symbolicEqual('x/y', '(y*x^(-1))^(-1)') // true
symbolicEqual('abs(x)','x') // false
symbolicEqual('abs(x)','x', simplify.positiveContext) // true
```
## See also
[simplify](simplify.md),
[evaluate](evaluate.md)