-2

States A and B are represented by strings of n bits each; within the rightmost m bits, at least k bits of A must be 0 and the corresponding bits of B must be 1, and the Hamming distance between the rightmost m bits of A and the rightmost m bits of B must be at least h. Then a function f(n,m,k,h) that gives the number of possible pairs of states (A, B) that meet these constraints.

X (don't care states) is non-binary and can have 4 values.

Anything helps...

  • 1
    It's not moderators who downvote, it's visitors who don't think this is a good question. I agree with them (though I am not the downvoter). Set notation is not likely to help you find the count you want. There is probably no formula for the number of transitions. There is probably no algorithm that does better than the one you sketch that considers cases. Perhaps if you wrote good pseudocode someone could improve it, but I suspect not. – Ethan Bolker Oct 24 '21 at 00:30
  • Thank you. I am trying to use set notations to represent the solutions formally in a set in some way, not to find the count. Do you think at least that is possible? –  Oct 24 '21 at 00:38
  • 1
    It may be possible. If it is, the answer will probably be ugly and uninformative. I would not spend any time or energy looking for such a representation. – Ethan Bolker Oct 24 '21 at 00:42
  • 1
    You could summarize cases (i), (ii), (iii) by counting transitions in case (i) and then multiplying by $3$, since that is the number of distinct permutations of the bits $001.$ – David K Oct 24 '21 at 02:26
  • 1
    I don't understand why $A=0001,$ $B=0010$ is not counted among the transitions. Or $A=0000,$ $B=0011.$ Both transitions have Hamming distance $2$ in the last three bits. – David K Oct 24 '21 at 02:28
  • 1
    If I understood the rules for a possible transition then the counting can be simpler than your method and the total is much larger. Did you forget to tell us about some additional constraints? – David K Oct 24 '21 at 02:43
  • @DavidK These are the only rules. I hope I have not been mistaken and 28 is the correct total. –  Oct 24 '21 at 05:18
  • With the added restriction on $B$ it makes sense to treat case (iv) separately from the other three. You still have only three cases for two zeros in the last three bits of $A$ and they all have the same number of transitions, and this will continue to be true no matter how many total bits there are. If you want to treat a different set of transitions where, say, the last four bits have special rules, not just the last three bits, then you have a different structure which depends on how you extend your rules. – David K Oct 24 '21 at 14:53
  • At the very least, I want to be able to calculate one case (say (i)) in a more general way than calculating the number of Xs and equating to $2^x$. –  Oct 24 '21 at 20:01
  • Can you please help me to represent the solution set in a function in some way, even if it's ugly? That will help a lot. –  Oct 24 '21 at 20:04
  • 1
    I could try to generalize as follows: states $A$ and $B$ are represented by strings of $n$ bits each; within the rightmost $m$ bits, at least $k$ bits of $A$ must be $0$ and the corresponding bits of $B$ must be $1$; and the Hamming distance between the rightmost $m$ bits of $A$ and the rightmost $m$ bits of $B$ must be at least $h.$ Then you want a function $f(n,m,k,h)$ that gives the number of possible pairs of states $(A,B)$ that meet these constraints. Is that sufficiently general? – David K Oct 24 '21 at 21:46
  • This is exactly what I am looking for. Just need the notations for sets/functions. Can't thank you enough.. –  Oct 24 '21 at 22:00

1 Answers1

0

I will generalize the problem as follows:

States $A$ and $B$ are represented by strings of $n$ bits each; within the rightmost $m$ bits, at least $k$ bits of $A$ must be $0$ and the corresponding bits of $B$ must be $1$; and the Hamming distance between the rightmost $m$ bits of $A$ and the rightmost $m$ bits of $B$ must be at least $h.$

We want to find a formula to express a function $f(n,m,k,h)$ that gives the number of possible pairs of states $(A,B)$ that meet these constraints.

Initially, I'll just do the case $h\leq k$ since it's simpler than the general case; the conditions requiring $k$ zeros in $A$ and the corresponding $1$s in $B$ guarantee that the Hamming distance will always be at least $k.$

If exactly $r$ of the rightmost $m$ bits of $A$ are $1$s (that is, $m-r$ bits are $0$), there are $\binom mr$ possible choices of column to put them in. So there are $\binom mr$ ways for $A$ to have $r$ $1$s in its rightmost $m$ bits. For each of these choices of $A$, there are exactly $r$ don't-care (X) bits in the rightmost $r$ bits of $B$ (the others are forced to $1$), hence $2^r$ choices for the rightmost $m$ bits of $B.$ So just considering the rightmost $m$ bits of $A$ and $B$, and assuming those bits of $A$ include exactly $r$ $1$s, we have $\binom mr 2^r$ choices.

If we look at all the bits that are not the rightmost $m$ bits of $A$ or $B,$ we will always find $2(n - m)$ don't-care (X) bits there. So for each choice of the rightmost $m$ bits of $A$ and $B$ where exactly $r$ of the rightmost $m$ bits of $A$ are $1$s, we have $2^{2(n-m)}$ ways to fill in the remaining Xs.

That's $\binom mr 2^{r+2(n-m)}$ choices for exactly $r$ $1$s in the rightmost $m$ bits of $A.$ But $r$ can be anything from zero to $m-k$, so the total number of transitions is

$$ \sum_{r=0}^{m-k} \binom mr 2^{r+2(n-m)}. $$

I would pull a constant factor out of the sum as follows:

$$f(n,m,k,h) = 4^{n-m} \sum_{r=0}^{m-k} \binom mr 2^r \quad \text{when $h\leq k$}.$$

It's hard to get it simpler than that. Wolfram Alpha suggests there might be something involving a hypergeometric function, but I don't see that as an improvement.

For $h > k,$ instead of $r$ independent X bits in the rightmost bits of $B$ we have $r$ bits that must have at least $h - k$ zeros. That is, those $r$ bits of $B$ can contain some number of $1$s; the number of $1$s may be as few as $0$, but it cannot be more than $m-h$ and of course it cannot be more than $r$. Whichever is less, $r$ or $m-h,$ is the maximum number of $1$s. So instead of always having $2^r$ ways to fill in those $r$ bits we have $$\sum_{q=0}^{\min(r,m - h)} \binom rq.$$ Note that when $m - h \geq r,$ this comes out to $2^r,$ that is, the larger value of $h$ restricts the possibilities only in the cases where it is larger than the actual number of zeros in $A.$

Again it is possible to express this using a hypergeometric function but I do not see the advantage of that. The total number of possible transitions therefore is

$$f(n,m,k,h) = 4^{n-m} \sum_{r=0}^{m-k} \binom mr \sum_{q=0}^{\min(r,m - h)}\binom rq \quad \text{when $h>k$}.$$

If you want to write this without needing to write $\min(r,m-h)$, you can write it like this:

\begin{align} f(n,m,k,h) = 4^{n-m} \bigg( &\sum_{r=0}^{m-h} \binom mr \sum_{q=0}^r \binom rq \\ & + \sum_{r=m-h+1}^{m-k} \binom mr \sum_{q=0}^{m - h}\binom rq \bigg) \quad \text{when $h>k$}. \end{align}

(This is likely how I would do it if I were writing the function in software.)

David K
  • 98,388
  • Thank you very much. For $h \leq k$, (for cases (i), (ii), and (iii)), the equation becomes $4 \cdot \sum_{r=0}^{1} \binom{3}{r} \cdot 2^{r}$= 4[1+6]= 28 transitions. Shouldn't there be 24 total transitions? I feel I may have misinterpreted for which I apologize. –  Oct 25 '21 at 21:25
  • 1
    By summing over $\sum_{r=0}^1$ we get the $24$ transitions for the three $HD=2$ cases when $r=1$ and we get the $4$ transitions for the $HD=3$ case when $r=0.$ The $28$ cases total is for all cases (i) to (iv), same as your total for all four cases. – David K Oct 25 '21 at 22:20
  • Thanks a lot. Last question: about the case of $h>k$, this comes to 33*4 transitions which I feel is not the correct answer. Could you please check for the given example of $n=5$, $h=3$, $k=2$. I want to have HD=3 here. https://pasteboard.co/5GtdSb9akqzo.png –  Oct 26 '21 at 03:17
  • 1
    Good catch! The formula I initially posted for $h>k$ had not just one, but two errors: you only have $r$ places to put the $1$s, not always $m-k$ places, and when $r<m-h$ the number of $1$s that you can put there is only $r$, not always $m-h$. That makes the formula a bit uglier in my opinion, but I think this is a reflection of the complexity of the problem. – David K Oct 26 '21 at 12:03
  • OMG! I just realized X can have 4 values instead of 2 as it's not binary. Is it possible to reflect that in the equations? –  Oct 26 '21 at 20:05
  • The correct formula should be $8^{n-m}$ for all of them right? –  Oct 26 '21 at 20:23
  • 1
    You mean 4 possible values in each bit? What are the other two values? Is this all bits including all Xs and the bits we've been setting to $1$ in $A$, or just some bits? If it's 4 values but only in the bits to the left of the red line, change $4^{n-m}$ to $16^{n-m}$ (that is, from $2^{2(n-m)}$ change to $4^{2(n-m)}$ for 4 values in each of $2(n-m)$ bits). – David K Oct 27 '21 at 00:29
  • Thanks that's what I needed. 4 values for the left of the red line. You are amazing! –  Oct 27 '21 at 00:46