Join GitHub today
A fast zero-testing method is needed #10279
On occasion it is necessary to test if a symbolic expression is identically zero; for example in the row reduction algorithm
Quoting @asmeurer from the above issue:
'Zero equivalence is an impossible problem in general (see Richardson's Theorem). For restricted classes of functions it is computable (e.g., for rational functions). I my opinion the only completely right way to solve this is to have domains for matrices, e.g., a matrix over QQ(x) would only allow rational functions in x with rational number coefficients as its entries. This domain would know how to solve its own zero equivalence, and the most efficient way to do it (with the right representation, zero equivalence becomes trivial).'
This is one possible solution when one knows the domain, though this would be a large task to implement.
The other possible approach which would work less exactly but more generally and which should be easier to implement (and faster?) is to randomly evaluate the expression at several points. This is the approach Mathematica claims to use: 'Zero testing for various functions is done using symbolic transformations and interval-based numerical approximations after random numerical values have been substituted for variables.'
I envisage such a function first testing for obviously zero or non-zero expressions, then performing minimal simplification to get the expression in a form suitable for numerical evaluation at random values of the symbols involved, using chop=True or some cleverer method to tell if the function is zero. Obviously the issue would be with numerical stability, which is not a problem I have any experience with.
referenced this issue
Dec 18, 2015
# We need to know if this is always zero or not. We # assume that if there are free symbols that it is not # identically zero (or that there is more than one way # to make this zero). Otherwise, if there are none, this # is a constant and we assume that it does not simplify # to zero XXX are there better (fast) ways to test this? # The .equals(0) method could be used but that can be # slow; numerical testing is prone to errors of scaling.