expr-lang / expr

Expression language and expression evaluation for Go
https://expr-lang.org
MIT License
6.16k stars 394 forks source link

Optimize boolean operations between all, any, none functions #626

Closed bizywizy closed 5 months ago

bizywizy commented 5 months ago

Seconds attempt at implementing this:

all(x, x > 1) && all(x, x < 10) -> all(x, x > 1 && x < 10)
any(x, x > 1) || any(x, x < 10) -> any(x, x > 1 || x < 10)
none(x, x > 1) && none(x, x < 10) -> none(x, x > 1 || x < 10)

Previous one (https://github.com/expr-lang/expr/pull/555) wasn't successful and unfortunately introduced a significant bug (https://github.com/expr-lang/expr/issues/624).

This time I focused only on 3 cases: all with and, any with or, none with and and included comprehensive tests for this optimization and logical operations between any/all/none/one

antonmedv commented 5 months ago

On my benchmarks this gives 8%-12% boost. Nice job! 👍🏻