symbrim.utilities.utilities.check_zero

symbrim.utilities.utilities.check_zero(expr: Expr, n_evaluations: int = 10, atol: float = 1e-08) bool

Check if an expression is zero based on random evaluations.

Explanation

This function evaluates the given expression with randomly generated values for the free symbols and checks if the result is zero. To minimize the chances of false positives, the evaluation is performed multiple times. However, it should be noted that false negatives can still occur. Examples are when values are close to zero or functions like the Dirac function are used, which is likely to evaluate to zero.

Parameters:
  • expr (Expr) – The expression to be checked.

  • n_evaluations (int, optional) – The number of evaluations to be performed. Default is 10.

  • atol (float, optional) – The absolute tolerance used for comparison. Default is 1e-8.

Returns:

Returns True if the expression evaluates to zero, and False otherwise.

Return type:

bool