In general, it is fairly easy to implement this type of invariant with rules. We do this a lot in `myrialang`. For instance, I prefer to write optimizations using GroupBy assuming everything is a "simple expression":

`SELECT x+y, SUM(z)+SUM(x) FROM R` as parsed in MyriaL turns into a single GroupBy operator with complex expressions, but I turn it into:

`Apply($0, $1+$2)[GroupBy($0, SUM($2), SUM($1))[Apply($0+$1, $0, $2)[...]]`

That should look like

`(x,y,z)` to `(x+y, x, z)` to `(x+y, sum(z), sum(x))` to `(x+1, sum(z)+sum(x))`.

See https://github.com/uwescience/raco/blob/master/raco/myrialang.py#L782