simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

symbolicEqual.md (1862B)


      1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
      2 
      3 # Function symbolicEqual
      4 
      5 Attempts to determine if two expressions are symbolically equal, i.e.
      6 one is the result of valid algebraic manipulations on the other.
      7 Currently, this simply checks if the difference of the two expressions
      8 simplifies down to 0. So there are two important caveats:
      9 1. whether two expressions are symbolically equal depends on the
     10     manipulations allowed. Therefore, this function takes an optional
     11     third argument, which are the options that control the behavior
     12     as documented for the `simplify()` function.
     13 2. it is in general intractable to find the minimal simplification of
     14     an arbitrarily complicated expression. So while a `true` value
     15     of `symbolicEqual` ensures that the two expressions can be manipulated
     16     to match each other, a `false` value does not absolutely rule this out.
     17 
     18 
     19 ## Syntax
     20 
     21 ```js
     22 symbolicEqual(expr1, expr2)
     23 symbolicEqual(expr1, expr2, options)
     24 ```
     25 
     26 ### Parameters
     27 
     28 Parameter | Type | Description
     29 --------- | ---- | -----------
     30 `expr1` | Node &#124; string | The first expression to compare
     31 `expr2` | Node &#124; string | The second expression to compare
     32 `options` | Object | Optional option object, passed to simplify
     33 
     34 ### Returns
     35 
     36 Type | Description
     37 ---- | -----------
     38 boolean |  Returns true if a valid manipulation making the expressions equal is found.
     39 
     40 
     41 ### Throws
     42 
     43 Type | Description
     44 ---- | -----------
     45 
     46 
     47 ## Examples
     48 
     49 ```js
     50 symbolicEqual('x*y', 'y*x') // true
     51 symbolicEqual('x*y', 'y*x', {context: {multiply: {commutative: false}}})
     52     //false
     53 symbolicEqual('x/y', '(y*x^(-1))^(-1)') // true
     54 symbolicEqual('abs(x)','x') // false
     55 symbolicEqual('abs(x)','x', simplify.positiveContext) // true
     56 ```
     57 
     58 
     59 ## See also
     60 
     61 [simplify](simplify.md),
     62 [evaluate](evaluate.md)