MSTD sets

explicit constructions of sets with more unique pairwise sums than differences


I was reading this interesting paper by Hegarty discussing Some explicit constructions of sets with more sums than differences and I found that the smallest set you could construct was $\{0,2,3,4,7,11,12,14\}$ and it is not possible to construct smaller sets (of course, you could create other sets from this one using affine transformations).

For example, take the set $\{2,5,6,8,11\},$ the sumset will be $\{4, 7, 8, 10, 11, 12, 13, 14, 16, 17, 19, 22\},$ and the difference set will be $\{-9, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 9\}.$ The sumset has 12 elements and the difference set has 15 elements, so this set is not an MSTD set.

For a set with $n$ numbers, the sumset will have an upper bound of $\displaystyle\frac{n(n+1)}{2}$ and the difference set will have an upper bound of $n(n-1)+1.$ We can understand this by drawing a matrix and seeing that for the sumset, we'll have a symmetric matrix and for the difference set, we'll have a skew-symmetric matrix. We just need to ignore the zeroes in the diagonal for the difference set. Because we lose half the numbers from the sum-set, we need to construct MSTD sets by having as many duplicate values in the difference matrix as possible. An example where both are equal is the set $\{k,k+1,k+2,\dots,k+l\}$ which has the sumset $\{2k,2k+1,2k+2,\dots,2k+2l\}$ and the difference set $\{-l,-l+1,-l+2,\dots,l\}.$ Both have a cardinality of $2l+1.$ Another example of a set where both are equal is the set $\{a, b\}$ where the sumset will have three elements, and the difference set will have three elements. The sumset will be $\{a+b, 2a, 2b\}$ and the difference set will be $\{a-b, b-a, 0\}.$


def sumdiffset(data):

    sumset = set()
    diffset = set()
    for num in data:
        for other_num in data:
            sumset.add(num + other_num)
            diffset.add(num - other_num)
    return {'sumset': sumset, 'diffset': diffset, 'set_counts': {'sumset': len(sumset), 'diffset': len(diffset)}}

data = [0, 2, 3, 4, 7, 11, 12, 14] # change this
result = sumdiffset(data)
print(f"Sumset: {result['sumset']}")
print(f"Diffset: {result['diffset']}")
print(f"Set Counts: {result['set_counts']}")