Currently, TVM uses the following way to define expression simplifying rules:
https://github.com/apache/tvm/blob/f5e0c102057641d88f06ad865d5a1d4e99bd70d7/src/arith/rewrite_simplify.cc

This approach is error-prone and not scalable:
1. The rewrite rules were added manually, the number of possible rewriting 
rules might be too large and not maintainable.
2. Lack verification of rewriting rules, we only have unittests: which can not 
cover all possible cases.
3. The order of rewrite matters, which is not considered here.

For 2, we can use existing SMT solvers such as Z3, for the issue introduced in 
https://github.com/apache/tvm/pull/10610, we can try finding a counter-example 
with Z3:
```python
>>> from z3 import *
>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> c1 = BitVec('c1', 32)
>>> c2 = BitVec('c2', 32)
>>> solve(x > 0, y > 0, c1 > 0, c2 > 0, c2 % c1 == 0, (x * c1 + y) % c2 != (x % 
>>> (c2 / c1)) * c1 + y, y < c1)
[y = 79521, x = 201523190, c1 = 1909062, c2 = 1956788550]
```
where `BitVec(..., 32)` means int32.

We can write tests for all these rewriting rules either on C++ side or Python 
side.

How to automatically generate rewrite rules remains a research problem, program 
synthesis ([rosette](https://github.com/emina/rosette)) and equality saturation 
([egg](https://github.com/egraphs-good/egg), 
[ruler](https://github.com/uwplse/ruler)) might help here. However, we need to 
define the optimization target of rewriting (make it simpler? can we formulate 
the level of "simple"? etc).





---
[Visit 
Topic](https://discuss.tvm.apache.org/t/rfc-verification-and-possibly-program-synthesis-of-expression-rewriting-rules/12319/1)
 to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.tvm.apache.org/email/unsubscribe/1114de82dd0594ed1801155d824f56da0ed2726d535e89a3a4a4a5bcf66a3d35).

Reply via email to