I'm currently computing the weight of bitvectors using the python api for z3.
After searching through the python API for more straight forward method, I'm implementing the weight function for a bitvector st1
in the following manner:
Sum([( (st1 & (2**(i)))/(2**(i)) ) for i in range(bits)])
My question is relatively straight-forward, is there an easier/more efficient way?
I have problems which contain 1500+ of these weight constraints and would like to make sure I'm doing things as efficiently as possible.
Edit: I'll add the following clarification, what I'm attempting to calculate has a name (it's the Hamming Weight), I know there are ultra efficient ways of implementing the functionality in imperative languages, but ultimately what I'm looking for is if there are any underlying methods to access individual bits of a z3 bitvector.