math: improve how known logical operations are handled