Static optimization of rules