I have to partition a multiset into two sets who sums are equal. For example, given the multiset:
1 3 5 1 3 -1 2 0
I would output the two sets:
1) 1 3 3
2) 5 -1 2 1 0
both of which sum to 7.
I need to do this using Z3 (smt2 input format) and “Linear Arithmetic Logic”, which is defined as:
formula : formula /\ formula | (formula) | atom
atom : sum op sum
op : = | <= | <
sum : term | sum + term
term : identifier | constant | constant identifier
I honestly don’t know where to begin with this and any advice at all would be appreciated.
Regards.
Here is an idea:
1- Create a 0-1 integer variable
c_ifor each element. The idea isc_iis zero if element is in the first set, and 1 if it is in the second set. You can accomplish that by saying that0 <= c_iandc_i <= 1.2- The sum of the elements in the first set can be written as
1*(1 - c_1) + 3*(1 - c_2) + ... +3- The sum of the elements in the second set can be written as
1*c1 + 3*c2 + ...