I have unit field events
:
events:uint;
The values of events
not so interesting as the amount of set bits in it. I would like to constrain the ranges of the amount of set bits in the events
.
Is there a way to do it?
Thank you for your help.
There might be an easier way to do it, but you can use bit slicing to constrain a list of uints to equal the bits of your variable, and use
sum
to constrain their amount.The following example does what you need (limited to a 4 bit variable for brevity):
Writing all the constraints is probably a little ugly, but it can easily be done using a
define as computed
macro.