ith of N natural number we put as ni. And if this number belongs to any groups we show this using
Zi. If ni belongs to group A, it is Zi=1. And if it belongs to group B it is Zi=0.
And then we create a hamiltonian of H that take the minimum value when the sum of each groups are the same.
H=(∑ni∗Zi)2
It will be H=0 when the sum of two groups are the same and takes H>0 if these are different.
Example
Let's try solve a simple example. Now we have a list of natural number
[3,6,5,6,5,2,6,8,5,8]
and we make two groups. The hamiltonian is very simple
#sum 38
num = [3,6,5,6,5,2,6,5]
from blueqat import vqe
from blueqat.pauli import Z
hamiltonian = (num[0]*Z(0)+num[1]*Z(1)+num[2]*Z(2)+num[3]*Z(3)+num[4]*Z(4)+num[5]*Z(5)+num[6]*Z(6)+num[7]*Z(7))**2
step = 2
result = vqe.Vqe(vqe.QaoaAnsatz(hamiltonian.simplify(), step)).run()
b = sum([x*y for (x,y) in zip(num, list(result.most_common(1)[0][0]))])
#answer 19
print(b)
result.most_common(12)