This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

On computing sets of integers with maximum number of pairs summing to powers of 2

Max A. Alekseyev The George Washington University, Washington, DC, USA. Email: maxal@gwu.edu
Abstract

We address the problem of finding sets of integers of a given size with maximum number of pairs summing to powers of 22. By fixing particular pairs this problem reduces to finding a labeling of the vertices of a given graph with pairwise distinct integers such that the endpoint labels for each edge sum to a power of 22. We propose an efficient algorithm for this problem, which we use to determine the maximum size of graphs of order nn that admit such a labeling for all n18n\leq 18. We also identify the minimal forbidden subgraphs of order 11\leq 11, whose presence prevents graphs from having such a labeling.

1 Introduction

In April 2021, Dan Ullman and Stan Wagon in the “Problem of the Week 1321” [3] defined a function f(A)f(A) of a finite set AA of integers as the number of 22-element subsets of AA that sum to a power of 22. They gave an example f({1,3,5})=3f\big{(}\{-1,3,5\}\big{)}=3 and further defined a function g(n)g(n) as the maximum of f(A)f(A) over all nn-element sets AA. The problem asked for a proof that g(10)14g(10)\geq 14, which was quickly improved to g(10)15g(10)\geq 15 by the readers.

It was noted that the problem has a natural interpretation as finding a maximal graph of order nn, where the vertices are labeled with pairwise distinct integers and the sum of the endpoint labels for each edge is a power of 22. In March 2022, M. S. Smith proved that such a graph cannot contain a cycle C4C_{4}, limiting the candidate graphs to well-studied squarefree graphs [2]. Smith’s result made it easy to establish the values of g(n)g(n) for all n9n\leq 9, and led to creation of the sequence A352178 to the Online Encyclopedia of Integer Sequences (OEIS) [8]. It further provided a nontrivial upper bound for g(n)g(n), namely the number of squarefree graphs of order nn (given by sequence A006855 in the OEIS).

The problem has received further attention after Neil Sloane presented it at the popular Numberphile Youtube channel in September 2022 [1]. This was followed by a few improvements, including the values g(10)=15g(10)=15 and g(11)=17g(11)=17 from Matthew Bolan [5] and Firas Melaih [4], respectively. These results were obtained via graph-theoretical treatment of the problem by manually analyzing a few candidate graphs.

At the same time, two methods were proposed for obtaining lower bounds for g(n)g(n), giving those at least for all n100n\leq 100, which are listed in sequences A347301 and A357574 in the OEIS.

In the present paper, we propose an algorithm for testing admissibility of a given graph, i.e., whether its vertices can be labeled with pairwise distinct integers such that the sum of the endpoint labels for each edge is a power of 22. We use our algorithm to bound g(n)g(n) from above, and together with the known lower bounds to establish the values of g(n)g(n) for nn in the interval [12,18][12,18]. Also, interpreting Smith’s result as saying that the cycle C4C_{4} is a minimal forbidden subgraph (MFS), we find larger MFSs and show that there are none on 55, 66, 88, or 99 vertices, while there are 22 MFSs on 77 vertices, 1515 MFSs on 1010 vertices, and 7777 MFSs on 1111 vertices. We have also enumerated all maximal admissible graphs of orders 1414, 1515, 1616 and established that there are 44, 2828, and 22 of them, respectively.

2 Algorithm for testing graph admissibility

A given graph GG on nn vertices with mm edges is admissible if and only if the following matrix equation is admissible:

ML=X,M\cdot L=X, (1)

where

  • MM is the m×nm\times n incidence matrix of GG with rows and columns indexed by the edges and vertices of GG, and so MM is a {0,1}\{0,1\}-matrix with each row containing exactly two 11’s;

  • L=(l1,l2,,ln)TL=(l_{1},l_{2},\dots,l_{n})^{T} is a column vector of pairwise distinct integer vertex labels;

  • X=(x1,x2,,xm)TX=(x_{1},x_{2},\dots,x_{m})^{T} is a column vector formed by powers of 22 representing the sums of edges’ endpoint labels.111The elements of XX are not required to be distinct.

Both LL and XX in this equation are unknown and have to be determined.

We start with solving (1) for LL in terms of XX, that is we compute a (partial) solution of the form li=pi(x1,,xm)l_{i}=p_{i}(x_{1},\dots,x_{m}), where pip_{i} are linear polynomials with rational coefficients (i{1,2,,n}i\in\{1,2,\dots,n\}). Such a solution exists if and only if KlX=0K_{l}\cdot X=0, where KlK_{l} is the a matrix with rows forming a basis of the left kernel of MM. For better efficiency, we will assume that KlK_{l} has integer elements and is LLL-reduced. Let EE be the set of elements of KlXK_{l}X, which are linear homogeneous polynomials with integer coefficients representing linear equations in x1,,xmx_{1},\dots,x_{m}.

Let KrK_{r} be a matrix with columns form a basis of the right kernel of MM. For a connected graph GG, it is known that KrK_{r} has size n×tn\times t, where t=1t=1 or t=0t=0 depending on whether GG is bipartite [9]. We find it convenient to view an n×0n\times 0 matrix as composed of nn empty rows (and so all rows are equal). Adding a linear combination of the columns of KrK_{r} to a solution LL to equation (1) turns it into another solution LL^{\prime} (with the same XX), and furthermore all solutions can be obtained this way. The following theorem implies that for any set of pairwise distinct rows of KrK_{r}, we can find a linear combination of the of the columns of KrK_{r} such that the corresponding elements of LL^{\prime} will also be pairwise distinct.

Theorem 1.

Let vv be an integer column vector of size k0k\geq 0, and AA be a k×sk\times s matrix with pairwise distinct rows. Then there exists an integer linear combination of the columns of AA such that adding it to vv results in vector with pairwise distinct elements.

Proof.

If s=0s=0, then with necessity we have k=1k=1, and thus vv already has pairwise distinct elements.

Let us prove the statement for s=1s=1. In this case, AA represents a column vector with pairwise distinct elements. Let tt be the difference between the largest and the smallest elements of vv. It is easy to see that vector v+A(t+1)v+A\cdot(t+1) has pairwise distinct elements.

In the case of s>1s>1, let dd be the difference between the largest and the smallest elements of AA. Then the k×1k\times 1 matrix A:=A(1,(d+1),(d+1)2,,(d+1)s1)TA^{\prime}:=A\cdot(1,(d+1),(d+1)^{2},\dots,(d+1)^{s-1})^{T} has pairwise distinct elements, thus reducing the problem to the case s=1s=1 considered above. ∎

Theorem 1 implies that we need to take care only of the pairs of elements of LL corresponding to the equal rows of KrK_{r}. For any equal rows of KrK_{r} with indices i<ji<j, we compute q(x1,,xm):=(pi(x1,,xm)pj(x1,,xm))cq(x_{1},\dots,x_{m}):=(p_{i}(x_{1},\dots,x_{m})-p_{j}(x_{1},\dots,x_{m}))c, where cc is a positive integer factor making all coefficients of qq integer. If qq is zero polynomial, then the condition liljl_{i}\neq l_{j} is unattainable, and thus the graph GG is inadmissible. On the other hand, if qq consists of just a single term with a nonzero coefficient, then the condition liljl_{i}\neq l_{j} always holds, and we ignore such qq. In the remaining case, when qq contains two or more terms with nonzero coefficient, we add qq to the set NN.

Our next goal is to solve the system of equations EE and inequations222We deliberately use the term inequation to denote relationship p0p\neq 0 and to avoid confusion with inequalities traditionally denoting relationships \geq, \leq, >>, or <<. NN in powers of 22, which we describe in the next section. For each solution X=X0X=X_{0}, we substitute it in the system (1) turning it into a standard matrix equation, which we solve for LL composed of pairwise distinct integers lil_{i} (such a solution is guaranteed to exist). We outline the above description in Algorithm 1.

Algorithm 1 An algorithm for solving system (1) for a given graph GG.
1:function GraphSolve(GG)
2:    Set E:=E:=\emptyset and N:=N:=\emptyset
3:    Construct the incidence matrix MM of GG with rows and columns indexed by edges and vertices of GG
4:    Compute a LLL-reduced basis KlK_{l} of the left kernel of MM. \triangleright We have KlM=0K_{l}\cdot M=0.
5:    for each row rr in KlK_{l} do
6:        Add polynomial rXr\cdot X to EE
7:    end for
8:    Solve ML=XML=X for LL in terms of XX, let (p1,,pn)(p_{1},\dots,p_{n}) be any particular solution.
9:    Compute KrK_{r} whose columns form a basis of the right kernel of MM. \triangleright We have MKr=0M\cdot K_{r}=0.
10:    for each {i,j}{1,2,,n}\{i,j\}\subset\{1,2,\dots,n\} do
11:        if iith and jjth rows of KrK_{r} are not equal then
12:           continue to next subset {i,j}\{i,j\} \triangleright Per Theorem 1.
13:        end if
14:        Set qq equal to a multiple of pipjp_{i}-p_{j} with integer coefficients
15:        if q=0q=0 then
16:           return \emptyset \triangleright No solutions with liljl_{i}\neq l_{j}.
17:        end if
18:        if qq contains two or more terms then
19:           Add qq to NN.
20:        end if
21:    end for
22:    S:=S:=\emptyset
23:    for each ss in SolveInPowers(E,NE,\ Ndo \triangleright ss is a map from YY to linear polynomials in YY
24:        Set xi:=2s[yi]x_{i}:=2^{s[y_{i}]} for each component xix_{i} in XX
25:        Solve ML=XML=X for LL composed of pairwise distinct integers, and add the solution to SS.
26:    end for
27:    return SS
28:end function

3 Solving a system of (in)equations in powers of 22

For given finite sets EE and NN of nonzero linear polynomials in x1,x2,,xmx_{1},x_{2},\dots,x_{m}, our goal is to find all nn-tuples of nonnegative integers (y1,y2,,ym)(y_{1},y_{2},\dots,y_{m}) such that

pE:p(2y1,2y2,,2ym)=0,pN:p(2y1,2y2,,2ym)0.\begin{split}\forall p\in E:&\quad p(2^{y_{1}},2^{y_{2}},\dots,2^{y_{m}})=0,\\ \forall p\in N:&\quad p(2^{y_{1}},2^{y_{2}},\dots,2^{y_{m}})\neq 0.\end{split}

As simple as it sounds, the following theorem provides a foundation for our algorithms.

Theorem 2.

In any multiset of nonzero integers that sum to 0, there exist two elements with equal 22-adic valuations.333Recall that the 22-adic valuation of an integer k0k\neq 0, denoted by ν2(k)\nu_{2}(k), is the exponent of 22 in the prime factorization of kk, while ν2(0)=\nu_{2}(0)=\infty.

Proof.

Let SS be a multiset of nonzero integers summing to 0, and let kk be an element of SS with the smallest 22-adic valuation, say q:=ν2(k)q:=\nu_{2}(k). If every other element of SS has valuation greater than qq, then the sum of all elements (which is 0) has valuation qq, which is impossible. Hence, there exist at least two elements in SS having 22-adic valuation equal qq. ∎

Applying Theorem 2 to an equation c1x1++cmxmEc_{1}x_{1}+\dots+c_{m}x_{m}\in E, we conclude that if only one of the coefficients c1,c2,,cmc_{1},c_{2},\dots,c_{m} is nonzero, then the system (E,N)(E,N) is inadmissible. Otherwise, if there are two or more nonzero coefficients among c1,c2,,cmc_{1},c_{2},\dots,c_{m}, then there exists a pair of indices i<ji<j such that ci0c_{i}\neq 0, cj0c_{j}\neq 0, and ν2(cixi)=ν2(cjxj)\nu_{2}(c_{i}x_{i})=\nu_{2}(c_{j}x_{j}), implying that we can make a substitution xi=2ν2(cj)ν2(ci)xjx_{i}=2^{\nu_{2}(c_{j})-\nu_{2}(c_{i})}x_{j} or xj=2ν2(ci)ν2(cj)xix_{j}=2^{\nu_{2}(c_{i})-\nu_{2}(c_{j})}x_{i} (we pick one with integer coefficients). Then we proceed with making this substitution in EE and NN reducing the number of indeterminates, and if it does not make any elements of NN evaluate to zero, we proceed with solving the reduced system recursively. After the pair (i,j)(i,j) is explored, we add a new inequation 2ν2(ci)xi2ν2(cj)xj2^{\nu_{2}(c_{i})}x_{i}-2^{\nu_{2}(c_{j})}x_{j} to NN (to prevent obtaining the same solutions again in future), and proceed to a next pair of indices.

We outline the above description in Algorithm 2. For given sets EE and NN of linear equations and inequations in x1,,xmx_{1},\dots,x_{m}, function SolveInPowers(E,N)(E,\ N) computes the set of their solutions in powers of 22. Each solution is given in the form of a map ss from the set of variables Y:={y1,y2,,ym}Y:=\{y_{1},y_{2},\dots,y_{m}\} to linear polynomials in these variables, representing the exponents in the powers of 22. Namely, ss sends every variable from YY either to itself (when it’s a free variable), or to a linear polynomial of the free varaibles. For example, the map {y1y2+1,y2y2,y3y2+y4+3,y4y4}\{y_{1}\to y_{2}+1,\ y_{2}\to y_{2},\ y_{3}\to y_{2}+y_{4}+3,y_{4}\to y_{4}\} corresponds to the solution (x1,x2,x3,x4)=(2y2+1,2y2,2y2+y4+3,2y4)(x_{1},x_{2},x_{3},x_{4})=(2^{y_{2}+1},2^{y_{2}},2^{y_{2}+y_{4}+3},2^{y_{4}}), where y2y_{2} and y4y_{4} are free variables taking nonnegative integer values.

Algorithm 2 An algorithm for solving a given system of linear equations EE and inequations NN for x1,,xmx_{1},\dots,x_{m} in powers of 22. It returns a set of maps ss from variables Y:={y1,y2,,ym}Y:=\{y_{1},y_{2},\dots,y_{m}\} to linear polynomials in these variables such that (x1,,xm)=(2s[y1],2s[y2],,2s[ym])(x_{1},\dots,x_{m})=(2^{s[y_{1}]},2^{s[y_{2}]},\dots,2^{s[y_{m}]}) is a solution.
1:function SolveInPowers(E,NE,\ N)
2:    if E=E=\emptyset then
3:        return {the identity map}\{\text{the identity map}\} \triangleright Every variable in YY is free.
4:    end if
5:    Pick c1x1++cmxmEc_{1}x_{1}+\dots+c_{m}x_{m}\in E with the smallest number of nonzero coefficients.
6:    Let I:={i1im,ci0}I:=\{i\mid 1\leq i\leq m,\ c_{i}\neq 0\} be the set of indices of nonzero coefficients.
7:    if |I|=1|I|=1 then
8:        return \emptyset \triangleright Such equation has no solutions.
9:    end if
10:    Set S:=S:=\emptyset \triangleright We accumulate solutions in SS.
11:    for each {i,j}I\{i,j\}\subseteq I do \triangleright We iterate over all 2-element subsets of II.
12:        Possibly exchanging the values of ii and jj, ensure that d:=ν2(ci)ν2(cj)0d:=\nu_{2}(c_{i})-\nu_{2}(c_{j})\geq 0.
13:        Construct NN^{\prime} from NN by substituting xj2dxix_{j}\leftarrow 2^{d}x_{i}.
14:        if 0N0\in N^{\prime} then
15:           continue to the next pair {i,j}\{i,j\}.
16:        end if
17:        Add xj2dxix_{j}-2^{d}x_{i} to NN. \triangleright For future we disallow the equality cjxj=cixic_{j}x_{j}=c_{i}x_{i}.
18:        Construct EE^{\prime} from EE by substituting xj2dxix_{j}\leftarrow 2^{d}x_{i} and excluding zero polynomials.
19:        for each ss in SolveInPowers(E,NE^{\prime},\ N^{\prime}do \triangleright ss is a map from YY to linear polynomials in YY.
20:           Redefine s[yj]:=s[yi]+ds[y_{j^{\prime}}]:=s[y_{i^{\prime}}]+d.
21:           Add ss to set SS.
22:        end for
23:    end for
24:    return SS
25:end function

4 Minimal forbidden subgraphs

We used the results of the previous sections to find minimal forbidden subgraphs (MFS) of small order, i.e., inadmissible graphs in which every proper subgraphs is admissible. It is easy to see that each MFS must be connected. It is further almost trivial task to verify that C4C_{4} is the smallest MFS and the only one on 44 vertices. Therefore, for n>4n>4 we can restrict our attention to connected squarefree graphs as candidates, which we generate in SageMath [7] with the function nauty_geng() based on nauty tool [6] supporting both connected (option -c) and squarefree (option -f) graphs. This significantly speeds up the algorithm and eliminates the need to test the presence of MFS C4C_{4} as a subgraph.

We look for MFSs, other than C4C_{4} iteratively increasing their order, accumulating found MFSs in a set SS (initially empty). For each candidate graph GG, we check if GG contains any graphs from SS as a subgraph using the SageMath function is_subgraph(). If GG contains any of the graphs from SS, we go to the next candidate graph GG. Otherwise, we test admissibility of GG by calling GraphSolve(G)\textsc{GraphSolve}(G). If GG is inadmissible, then it represents an MFS and we add it to SS. The described algorithm is outlined in Algorithm 3.

Algorithm 3 An algorithm for iterative computing minimal forbidden subgraphs, other than C4C_{4}, of order up to uu.
1:function FindMFS(uu)
2:    S:=S:=\emptyset
3:    for n=5,,un=5,\dots,u do
4:        for each connected squarefree graph GG of order nn do
5:           if GG contains any graph HH from SS as a subgraph then
6:               continue to next GG
7:           end if
8:           if GraphSolve(GG) is empty then
9:               Add GG to the set SS.
10:           end if
11:        end for
12:    end for
13:    return SS
14:end function

We confirmed that the smallest MFS is the cycle C4C_{4} as it was originally proved by Smith, and the next two have order 77 (Fig. 1). It happens that one of these graphs was previously proved to be inadmissible by Bolan while showing that g(10)=15g(10)=15 [5].

Refer to caption
Figure 1: Minimal forbidden subgraphs of order 77.

There are no MFSs of order 88 or 99, but there are 1515 of them of order 1010 (Fig. 2), and there are 7777 MFSs of order 1111. We use MFSs of order 10\leq 10 for quick filtering some inadmissible graphs.

Refer to caption
Figure 2: Minimal forbidden subgraphs of order 1010.

5 Computing values of g(n)g(n)

We also used the proposed algorithms for computing values of g(n)g(n) (sequence A352178 in the OEIS) for nn in [12,18][12,18] using the known lower and upper bounds:

nn 12 13 14 15 16 17 18
lower bound (A347301) 19 21 24 26 29 31 34
upper bound (A006855) 21 24 27 30 33 36 39

In all these cases, the value of g(n)g(n) happens to coincide with the lower bound, and thus the problem can be posed as verifying that larger values (up to the upper bound) are not possible. For values n13n\leq 13 this can be done directly by generating all larger connected squarefree graphs and testing them for admissibility. For example, there are only 957957 such graphs of order 1313 with 2222 or more edges.

We find the following statements helpful:

Theorem 3.

For any n>2n>2:

  • if an admissible graph of order nn with ee edges exists, then its vertices have degree is at least eg(n1)e-g(n-1);

  • g(n)ng(n1)n2.g(n)\leq\left\lfloor\frac{n\cdot g(n-1)}{n-2}\right\rfloor.
Proof.

Suppose that there exists an admissible graph GG of order nn with ee edges, and that it has a vertex vv of degree smaller than eg(n1)e-g(n-1). Then removing vv from GG results in an admissible graph of order n1n-1 with more than g(n1)g(n-1) edges. The contradiction proves that degree of any vertex of GG is at least eg(n1)e-g(n-1). This further implies that GG has at least n(eg(n1))2\tfrac{n(e-g(n-1))}{2} edges, that is en(eg(n1))2e\geq\tfrac{n(e-g(n-1))}{2}, implying that eng(n1)n2e\leq\big{\lfloor}\frac{n\cdot g(n-1)}{n-2}\big{\rfloor}. Taking an admissible graph of order nn with e=g(n)e=g(n) edges proves that g(n)ng(n1)n2g(n)\leq\big{\lfloor}\tfrac{n\cdot g(n-1)}{n-2}\big{\rfloor}. ∎

From g(13)=21g(13)=21, Theorem 3 implies that g(14)24g(14)\leq 24, which matches the lower bound. Hence, we obtain g(14)=24g(14)=24 without any computation.

For n=15n=15, Theorem 3 implies that g(15)27g(15)\leq 27. If an admissible graph with 2727 edges exists, the minimum degree should be at least 33. This can be enforced with the option -d3 of nauty_geng(), which generates 82808280 such candidate graphs, but our check shows that neither of them is admissible. Hence, g(15)=26g(15)=26.

For n=16n=16, Theorem 3 implies that g(16)29g(16)\leq 29 and thus g(16)=29g(16)=29.

For n=17n=17, Theorem 3 implies that g(17)32g(17)\leq 32. If an admissible graph with 3232 edges exists, the minimum degree should be at least 33. There are 10231001023100 such candidate graphs, which is possible to check directly although it would be quite time consuming. Instead, we approached this problem from another side—by constructing candidate graphs from the maximal admissible graphs of order 1616 as explained below. This way we established that there are no admissible graph of order 1717 with 3232 edges, thus proving that g(17)=31g(17)=31.

For n=18n=18, Theorem 3 implies that g(18)34g(18)\leq 34 and thus g(18)=34g(18)=34.

6 Maximal admissible graphs

Refer to caption Refer to caption
Refer to caption Refer to caption
Figure 3: Maximal admissible graphs of order 1414 with the corresponding vertex labelings.

The maximal admissible graphs of each order n14n\leq 14 can be obtained directly from the candidate graphs generated by nauty_geng(). In particular, for n=14n=14 we can restrict our attention to the 21842184 connected squarefree graphs with minimum degree 33, among which we identified only 44 admissible graphs (Fig. 3).

To construct maximal admissible graphs of order 1515, we noticed that either they contain a vertex of degree 22 whose removal results in a maximal admissible graph of order 1414, or their minimal degree is at least 33. We obtained 2020 maximal admissible graphs of the first type (by adding a vertex of degree 22 to the maximal admissible graphs of order 1414 in all possible ways, and testing admissibility of the resulting graphs), and 88 maximal admissible graphs of the second type by testing 3360833608 candidate graphs generated by nauty_geng().

Similarly, we further extended maximal admissible graphs of order 1515 to those of order 1616 by adding a vertex of degree 33, which resulted in just two maximal admissible graphs of order 1616 (Fig. 4). However, extending them to graphs of order 1717 with 3232 edges by adding a vertex of degree 33 produced no admissible graphs, thus proving that g(17)=31g(17)=31.

Refer to caption Refer to caption
Figure 4: Maximal admissible graphs of order 1616 with the corresponding vertex labelings.

Acknowledgements

The author thanks Neil Sloane for his nice introduction to the problem [1] and proofreading of the earlier version of this paper.

References

  • [1] Brady Haran and N. J. A. Sloane. Problems with Powers of Two. Numberphile Youtube Channel, September 2022. https://youtu.be/IPoh5C9CcI8.
  • [2] C. R. J. Clapham, A. Flockhart, and J. Sheehan. Graphs without four-cycles. Journal of Graph Theory, 13(1):29–47, 1989.
  • [3] Dan Ullman and Stan Wagon. Problem 1321: Powers of Two. Macalester College Problem of the Week, April 2021. Available electronically at https://oeis.org/A347301/a347301_1.pdf.
  • [4] Firas Melaih. On The OEIS Sequence A352178. Memo, September 2022. Available electronically at https://oeis.org/A352178/a352178_3.pdf.
  • [5] Matthew Bolan. Stan Wagon 1321 Solution. Memo, September 2022. Available electronically at https://oeis.org/A352178/a352178.pdf.
  • [6] Brendan D. McKay and Adolfo Piperno. Practical graph isomorphism, II. Journal of Symbolic Computation, 60:94–112, 2014.
  • [7] SageMath. version 9.7, 2022. https://www.sagemath.org/.
  • [8] The OEIS Foundation. The On-Line Encyclopedia of Integer Sequences. http://oeis.org, 2023.
  • [9] C. Van Nuffelen. On the incidence matrix of a graph. IEEE Transactions on Circuits and Systems, 23(9):572–572, 1976.