This is very nice and clean, I also like the use of an implication to capture the whole logic in a simple way.
Although isint
was added to solve this particular case, I think it fills a major gap that used to exist in clpBNR. Before, you could only specify integer constraints for variables by declaring them with ::integer
. It was very difficult to specify an integer constraint for an expression. So you had to do tricks like what I did in my first attempt, or somehow play with a mixture of boolean expressions and other constraints. This would lead to having extra helper variables that needed to be narrowed to find a solution, and in some cases (like leap/1
) it would make the system unusable.
Of course, it would be great to have failed reified constraints to become 0 or false
, but even if we had that, I think isint
would be needed to efficiently solve a subset of problems (all those types of problems for which a set of real equations mostly expresses the solution, but intermediate variables need to be constrained to an integer in order to further apply some of the remaining equations; this is common in real physical systems which impose integer constraints on some of the values).
So all things considered, I think isint
is a worthy addition to clpBNR and expands the usability surface of the library even though its need was found because of leap/1
.
By the way, I didnāt see isint
in the master branch, is it in some other branch?