TITLE: How to find a set $R$, such that $R+R=X$ for a given finite set of natural numbers $X$?
QUESTION [5 upvotes]: Given two finite sets of natural numbers $A$ and $B$, denote the set $\lbrace a+b \mid a \in A \text{ and } b \in B \rbrace$ as $A+B$.
What is the best known algorithm of finding a set of natural numbers $R$, such that $R+R=X$ for some finite set of natural numbers $X$?
A brief discussion of this problem is here.

REPLY [2 votes]: My first answer at this community, which I will post soon at existing RG discussion (mentioned by the person who asked this Q).
In below proposed Python recipe Set_C will be a nested dictionary...

solution = True
Set_C = {}
Set_MS = set([])
Set_R = set([])

# The truncate() function
def truncate(n, decimals=0) :
    multiplier = 10 ** decimals
    return int(int(n * multiplier) / multiplier)

# Start with some initial subset of the set of natural numbers (X ⊆ ℕ)
print("The initial subset of the set of natural numbers:")
Set_X = sorted(set([4,6,8,10,12]))
print("X = ", Set_X)
print("")

if not 0 in Set_X :
    # Obtaining a set C which will be the candidate for proposed numerical problem
    for x in Set_X :
        if (x%2 == 0) and (not int(x/2) in Set_C) :
            Set_C[int(x/2)] = {'source' : 0, 'destination' : 0}

        if (x%2 == 1) :
            if not truncate(int(x/2)) in Set_C :
                Set_C[truncate(int(x/2))] = {'source' : 0, 'destination' : 0}
            if not truncate(int(x/2))+1 in Set_C :
                Set_C[truncate(int(x/2))+1] = {'source' : 0, 'destination' : 0}

    # Computing the Minkowski sum of set C with itself, i.e. Set_MS = Set_C ⊕ Set_C
    for a in Set_C :
        for b in Set_C :
            Set_MS.add(a+b)

    if sorted(Set_MS) != sorted(Set_X) :
        solution = False
        Set_MS = set([])

    if solution == False :
        # Let perform a trick!
        for s in Set_C :
            for d in Set_C :
                if (s+d) in Set_X :
                    Set_C[s]['source'] = 1
                    Set_C[d]['destination'] = 1
                else :
                    Set_C[s]['source'] = 0
                    Set_C[d]['destination'] = 0

        # Obtaining a set R which will be another candidate for proposed numerical problem
        for c in Set_C :
            if (Set_C[c]['source'] == 1) and (Set_C[c]['destination'] == 1) :
                Set_R.add(c)

        # Computing the Minkowski sum of set R with itself
        for u in Set_R :
            for v in Set_R :
                Set_MS.add(u+v)

        if sorted(Set_MS) != sorted(Set_X) :
            print("There is NO solution for proposed numerical problem.")
        else :
            print("\nThe solution for proposed numerical problem:")
            print("R = ", sorted(Set_R))
    else :
        for c in Set_C :
            Set_R.add(c)
        print("\nThe solution for proposed numerical problem:")
        print("R = ", sorted(Set_R))
else :
    print('This recipe does not allow 0 in set X!')

input("\n\nPress Enter to continue...")