11

I want to find an injection $F$ from binary strings length $n$ with $i$ bits turned on to $i+1$ bits turned on, with the condition that if $F(S)=S'$, then $S'$ can be obtained from $S$ by simply turning one additional bit on.

Naturally, it is guaranteed that $i<n/2$, otherwise such an injection cannot exist because there will be more strings with $i$ bits turned on than $i+1$.

Trying some lexicographic ordering injection doesn't work because the maximal/minimal strings will always be mapped to by more than $1$ item.

Parcly Taxel
  • 105,904
  • I've no idea whether this might be useful but the question suggests gray codes to me. Look that up. – Ethan Bolker Feb 19 '23 at 01:56
  • Consider the graph $G$ whose vertices are binary strings of length $n$ and edges are connect if one string's on-bits are a subset of the other string's on-bits. If $G_i$ denotes the strings in $G$ with $i$ on-bits, then what you're looking for is a maximal matching on the subgraph induced by $G_i \cup G_{i+1}$. Maybe that will help find some relevant resource. (It might talk about this lattice of binary strings or, perhaps more likely, the lattice of subsets of an $n$-element set.) – Greg Martin Feb 19 '23 at 05:46
  • 2
    If I understand correctly, Theorem 4 in https://homes.cs.washington.edu/~anuprao/pubs/CSE599sExtremal/lecture6.pdf shows that such a function exists. But it doesn't give an explicit construction of the function. – VTand Feb 19 '23 at 07:25
  • 2
    See also: https://math.stackexchange.com/questions/3562859/extending-k-element-subsets-of-an-n-element-set-to-k1-element-subsets – VTand Feb 19 '23 at 07:39
  • @VTand: Theorem $4$ doesn't, but its proof does. – joriki Feb 19 '23 at 08:20
  • 2
    Do you want a description of such an injection for general $n$ and $i$? (If you just need one for some particular values of $n$ and $i$, you could use the construction in the proof of Hall's marriage theorem to construct one.) – joriki Feb 19 '23 at 11:04
  • 2

2 Answers2

5

Assuming OP wants an actual explicit description of the injection, then Extending $k$-element subsets of an $n$-element set to $k+1$ element subsets would not be a satisfying duplicate target. I gave an explicit injection in this answer of mine, but since the question there is not a duplicate of this one, I will reproduce it here.


Let $[n]=\{1,\dots,n\}$, and let $\binom{[n]}k$ denote the set of size-$k$ subsets of $[n]$. Here is how we construct an injection $f:\binom{[n]}{k}\to \binom{[n]}{k+1}$, which satisfies $f(X)\supseteq X$, whenever $k<n/2$.

Given $X\subset [n]$ with $|X|=k$, represent $X$ as a sequence of $k$ ones and $n-k$ zeroes.

  1. Cross out any two entries which are a $1$ followed by a $0$ with only crossed out entries between. Repeat this step until no such entries remain.

  2. Now, the only entries which are not crossed out will consist of some number of zeroes, followed by some number of ones. (If not, we would not be done with step one).
    There must exist a zero which is not crossed out, because there were initially more zeroes than ones, and we crossed out an equal number of each. Find the rightmost such zero, and change it to a one. The resulting sequence is $f(X)$.

It should be clear that $f(X)$ has size $k+1$. To prove that $f$ is injective, imagine that every time a $1$ and a $0$ are crossed out, they are "paired" together. The point is that when you change the leftmost zero to a one, and repeat the crossing-out procedure, you get the same set of pairs, because the changed bit was not in the middle of any pairs. Furthermore, no new pairs are created with the uncrossed-out entries, because we picked the rightmost zero. Therefore, to undo $f$, you do the same crossing out procedure, and instead change the leftmost remaining one into a zero.

Example: Let $n=18,k=8$, and $X=\{1,5,6,8,12,14,15\}$. The zero one vector is $$ 1,0,0,0,1,1,0,1,0,0,0,1,0,1,1 $$ Crossing out all instance of $1$ followed by zero, we get $$ \not1,\not0,0,0,1,\not1,\not0,\not1,\not0,0,0,\not1,\not0,1,1 $$ We are not done, because crossing out these numbers has created another instance of a $1$ followed by a $0$ (with only crossed-out numbers between), so next we cross that out. $$ \not1,\not0,0,0,\not1,\not1,\not0,\not1,\not0,\not0,0,\not1,\not0,1,1 $$ Now, among the remaining numbers, each zero occurs to the left of each one, so we are done. We conclude by replacing the rightmost zero with a one. $$ \not1,\not0,0,0,\not1,\not1,\not0,\not1,\not0,\not0,\boxed{1},\not1,\not0,1,1 $$ Therefore, $f(X)=\{1,5,6,8,\boxed{11},12,14,15\}$

Mike Earnest
  • 84,902
3

I posed this question as a Code Golf SE challenge and got this answer (but at the time with no proof) from user1502040, before Mike's answer was posted. This injection uses the set formulation of the problem: find an injection $f$ from $k$-subsets of $R=\{0,\dots,n-1\}$ to $k+1$-subsets of the same such that $f(S)\supset S$.

To compute $f(S)$, sum all elements of $S$, negate the result and reduce modulo $n-k$ to get a number $i$ from $0$ to $n-k-1$. The element to add to $S$ to produce $f(S)$ is the $i$th smallest element of $R-S$ with zero-based indexing ($i+1$-th smallest with one-based indexing). If this element is $a$, we shall say that $\mathsf{rank}(R - S, a) = i$.

For example, with $n=11$ and $k=5$, the image of $\{1,2,5,7,10\}$ is computed as follows:

  • The sum of all elements is $25$, and $-25\equiv5\bmod6$.
  • The missing elements are $(0,3,4,6,8,9)$. The 6th smallest, i.e. largest, element of this is $9$, so the desired image is $\{1,2,5,7,9,10\}$.

Later on this proof that $f$ is injective was added to the answer over there. Suppose $f$ is not injective, then there exists a $k-1$-subset $C$ and elements $x,y\in R-C$ with $f$ adding $y$ given the input $C\cup\{x\}$ and adding $x$ given the input $C\cup\{y\}$. Assume without loss of generality that $x<y$, then modulo $n-k$: $$x+\sum C\equiv-\mathsf{rank}(R-(C\cup\{x\}), y)$$ $$y+\sum C\equiv-\mathsf{rank}(R-(C\cup\{y\}), x)$$ $$\implies y-x\equiv \mathsf{rank}(R-(C\cup\{x\}), y)-\mathsf{rank}(R-(C\cup\{y\}), x)$$ The right-hand side $g$ of the last congruence is also the number of integers between $x$ and $y$ not in $C$, since $y>x$. Let $m$ be the number of integers in $C$ between $x$ and $y$, then $$m=y-x-1-g\implies m\equiv-1\bmod n-k$$ Therefore $n-k-1\le m\le k-1$ and $k\ge n/2$, but this contradicts the initial assumption that $k<n/2$. Since we initially assumed $f$ was not injective, the truth must be that it is.

Parcly Taxel
  • 105,904
  • 1
    @MikeEarnest Yes, it should be $m = y - x - 1 - g$. E.g. $g = 0, y = x + 1 \implies m = 0$ – user1502040 Feb 24 '23 at 00:51
  • 1
    We can also construct an explicit inverse to $f$: Given a subset $T$ with $k+1$ elements, remove the $i$'th largest element, where $i \equiv \sum S$ taken modulo $n-k$. – xnor Mar 08 '23 at 06:39