IsMatch

IsMatch

IsMatch[ expr1, expr2, Method=>method ] checks if two expressions are equal, using a given comparison method.

Usages

IsMatch[ expr1, expr2, Method=>method ]

IsMatch returns True if expr1 and expr2 match according to method, and False otherwise. The option Method is required. In both methods, the order of terms and factors does not matter.

Example in out
The same expression in a different order. IsMatch[ x+1, 1+x, Method=>accuracy ] True
3.1415 is within the precision of 3.14 (2 decimals). IsMatch[ 1+PrecisionConstant[3.14,2], 1+3.1415, Method=>accuracy ] True
12/5 and 2.4 have the same value. IsMatch[ 12/5, 2.4, Method=>numerical ] True
With accuracy, a fraction and a decimal number do not match. IsMatch[ 12/5, 2.4, Method=>accuracy ] False
Options

Method (required)

Sets how the expressions are compared.

  • accuracy: the expressions must have the same structure. Numbers with a limited precision, such as PrecisionConstant[3.14,2], match a value within that precision.
  • numerical: like accuracy, but numbers that have the same value also match, such as 12/5 and 2.4.
Syntax Example
IsMatch[ expr1, expr2, Method=>accuracy ] IsMatch[ x+1, 1+x, Method=>accuracy ]
IsMatch[ expr1, expr2, Method=>numerical ] IsMatch[ 12/5, 2.4, Method=>numerical ]

Units

If set to optional, a quantity with a unit also matches the same value without a unit. This is the only allowed value.

Syntax Example out
IsMatch[ expr1, expr2, Method=>method, Units=>optional ] IsMatch[ Quantity[3,'m'], 3, Method=>accuracy, Units=>optional ] True
IsMatch[ Quantity[3,'m'], 3, Method=>accuracy ] False
Details
  • No algebra: IsMatch does not simplify expressions: IsMatch[ 2x, x+x, Method=>numerical ] is False.
Invalid input Result
IsMatch[ 2, 2 ] Error: Expected argument 'Method'
IsMatch[ 2, 2, Method=>foo ] Error: Unknown Method: foo
IsMatch[ 2, Method=>accuracy ] Error: Expected two arguments
IsMatch[ 2, 2, Method=>accuracy, Units=>required ] Error: Invalid value for arugment Units: allowed value: 'optional'

See also: EqualsEval, DifferenceI, Quantity