SV contraint to repeat elements n time

In reply to ak_verifsj:

Hi,

(item == 1) ? 1:0 

will return either 1 or 0 depending on the values of each element in the array. If the item value is equal to 1, it will return 1, else, it will return 0. For example, if the array “a” contains elements like {1,6,1,4,1}, then,

(item == 1) ? 1:0 

will return {1,0,1,0,1}.

a.sum() with ((item == 1) ? 1:0) 

will calculate the sum of these 1’s and 0’s. And finally, the constraint

 a.sum() with ((item == 1) ? 1 :0) == 10; 

will make sure that, the sum of these 1’s and 0’s is 10. and thus, this constraint will ensure that, the no. of 1’s in this array is 10.

Hope this helps.

Putta Satish