This page is supplementary to the paper entitled "A discrete variation of the Littlewood--Offord problem," which contains a Python code to check the correctness of Lemma 9. #--------------------------------------------------------- # Generating {0,1}^a, the set of lists (vectors) with 0,1 components of length a def Binary(a): for i in range(2**a): result = [] index = 0 while index < a: if i%2==0: result.append(0) i=i/2 else: result.append(1) i=(i-1)/2 index += 1 yield result #--------------------------------------------------------- # Generating {0,-1,1}^a, the set of vectors with 0,-1,1 components of length a def ternary(a): List = [] for i in range(3**a): result = [] index = 0 while index < a: if i%3==0: result.append(-1) i=i/3 elif i%3==1: result.append(0) i=(i-1)/3 else: result.append(1) i=(i-2)/3 index += 1 List.append(result) return (List) #--------------------------------------------------------- # Generating {0,-1,1}^n with increasing components def ternary_A(n): List = [] for i in range(3**n): result = [] index = 0 while index < n: if i%3==0: result.append(-1) i=i/3 elif i%3==1: result.append(0) i=(i-1)/3 else: result.append(1) i=(i-2)/3 index += 1 u = 0 for h in range(len(result)-1): if result[h] > result[h+1]: u = 1 if u == 0: List.append(result) return (List) #--------------------------------------------------------- # Weight function def weight(List): s = 0 for j in List: if j != 0: s += 1 return (s) #--------------------------------------------------------- # A function to check if the inner product of two vectors is 0 or 1 def Is_mult_two_lists(List1,List2): s = 0 for i in range(len(List1)): s += List1[i] * List2[i] if s == 1 or s == 0: return True else: return False #--------------------------------------------------------- # If the number of 1 components in a vector with -1,1 components is not "approximately" half of its length, # we are done by Lemma 6. The following procedure takes care of this. def Is_Lemma6(List): List = remove_zeros(List) l = len(List) s1,t1 = 0,0 for j in List: if j == 1: s1 += 1 for y in List: if y == -1: t1 += 1 if l % 2 == 1: if s1 == t1 + 1: return True else: if s1 == t1 or s1 == t1 + 2: return True return False #--------------------------------------------------------- # Removing zeros from a vector v to obtain v* #(for a vector v with s component 0, we have |Omega(v)|=2^s|Omega(v*)|, so it suffices to consider v*) def remove_zeros(List): while True: if 0 in List: List.remove(0) else: break return (List) #--------------------------------------------------------- # Verifying parts (i), (ii) and (iii) of Lemma 9. print("For 2-row matrices.\n") for n in [3,4,5,6,7]: gt = 0 print("---------->For t = ", n) if n % 2 == 0: AW = [n//2, n//2 +1] else: AW = [n//2 + 1] coefficient = [9/16,5/8,5/8,1/2,1/2] for q in AW: for i in ternary_A(n-q): for j in ternary_A(n): for r in ternary_A(q): if 1 < weight(i) + weight(j) + weight(r) < n+1 and Is_Lemma6(remove_zeros(i + j + r)): j1 = remove_zeros(j) row_2 = i + j1 + r row_1 = (n-q)*[-1] + len(j1)*[0] + q*[1] s2 = 0 for yy in Binary(len(row_2)): if Is_mult_two_lists(row_2,yy) and Is_mult_two_lists(row_1,yy) and row_1 !=row_2: s2 += 1 if n == 4 or n == 5: if s2 >= coefficient[n-3] * (2**len(row_2)): gt = 1 print("{}\n{}\n".format(row_1,row_2)) else: if s2 > coefficient[n-3] * (2**len(row_2)): gt = 1 print("{}\n{}\n".format(row_1,row_2)) if gt == 0 and (n == 4 or n == 5): print ("There is no matrix A with |omega(A)| >= {}.2^s\n".format(coefficient[n-3])) elif gt == 0: print ("There is no matrix A with |omega(A)| > {}.2^s\n".format(coefficient[n-3])) #--------------------------------------------------------- # Verifying parts (iv) and (v) of Lemma 9. print("For 3-row matrices.\n") MK = [3,4,5] TTT = [] for n in MK: if n % 2 == 0: AW = [n//2, n//2 +1] else: AW = [n//2 + 1] TT = [] coefficient = 0 for q in AW: for i in ternary_A(n-q): for j in ternary_A(n): for r in ternary_A(q): if 1 < weight(i) + weight(j) + weight(r) < n+1 and Is_Lemma6(remove_zeros(i+j+r)): j1 = remove_zeros(j) row_1 = (n-q)*[-1] + len(j1)*[0] + q*[1] s2 = 0 for yy in Binary(len(i + j1 + r)): if Is_mult_two_lists(i + j1 + r,yy) and Is_mult_two_lists(row_1,yy) and\ row_1 !=i + j1 + r: s2 += 1 if s2/(2**len(i + j1 + r)) > 1/2: row1 = (n-q)*[-1] + len(j1)*[0] + q*[1] row2 = i+j1+r TT.append([row1,row2]) TTT.append(TT) for u in [3,4,5]: print("For t = ", u) q = 0 for i in TTT[u-3]: row_1 = i[0] + u*[0] row_2 = i[1] + u*[0] rrr = len(row_1) for row_3 in ternary(rrr): if 1 < weight(row_3) < u+1: s = 0 for yyy in Binary(rrr): if Is_mult_two_lists(row_1,yyy) and Is_mult_two_lists(row_2,yyy) and Is_mult_two_lists(row_3,yyy)and\ row_3 !=row_1 and row_3 != row_2: s += 1 if s/(2**rrr) > 1/2: q = 1 print("{}\n{}\n{}\n".format(row_1,row_2,row_3)) if q == 0: print ("There is no matrix A with |omega(A)| > 2^(s-1)\n")