In reply to manav33:
That’s not how foreach works in a constraint.
constraint c_byte_array {
foreach(byte_array[ii]) if (ii!=0) // guard against out of bounds indexing
($countones(byte_array[ii]) - $countones(byte_array[ii-1])) inside {[-4:4]}
}