0

Is there a solution for $x$ in

$$(x + (a<<s)-(b<<s))>>s = v$$

for $a,b,s,v$ positive integers? If not exact, is there an approximate solution?

I tried

$$(x+(a<<s)-(b<<s)) \approx v/s\implies x = v/s +(b<<s)-(a<<s)$$

but it won't work with numbers when I try.

Rafaelo
  • 103
  • 2
    What does << mean when between two numbers? Is it some kind of operation which combines two numbers to obtain a third? [If so please say how it gets calculated.] If it is only a relation similar to < then your question has no "exact" solution. – coffeemath Jun 30 '22 at 19:59
  • @coffeemath it´s the bit shift left, sorry – Rafaelo Jun 30 '22 at 20:02
  • Could you include a few examples of what "a << s" is, in a few cases of a and s? [Or does a<<s denote just the result of bit shift left applied to the single number a?] Anyway it suggests your numbers are in base 2 and also restricted to a certain length, neither of which you mention. – coffeemath Jun 30 '22 at 20:07
  • 1
    In general, you need to say what kind of rules exist for such calculations, since some on this site are not familiar with your notation. Reference?? – coffeemath Jun 30 '22 at 20:09
  • 1
    Assuming that the right bit shift operation returns integers and truncate any fractional part, it's not $(x+(a<<s)-(b<<s)) \approx v/s$, but instead the LHS can take many integer values

    $$v2^s \le x+(a<<s)-(b<<s) < (v+1)2^s$$

    – peterwhy Jun 30 '22 at 20:20
  • 1
    $a << s = a\cdot 2^s$. It's just C/C++ or Python speek. – emacs drives me nuts Jun 30 '22 at 20:23

1 Answers1

1

$\def\l{\ll}$ $\def\r{\gg}$We have $a \l s = 2^sa$. The lower $s$ bits of $x$ don't matter. Thus we can represent $x$ as $$x = 2^s x_1 + x_0$$ with $0\leqslant x_0 < 2^s$. The equation is then

$$\begin{align} v &= (x+(a\l s)-(b \l s)) \r s \\ &= (2^sx_1 + 2^s(a-b) + x_0) \r s \\ &= x_1 + a-b \\ \end{align}$$ and therefore all solutions in terms of $a$, $b$, $s$ and $v$ are:

$$\Bbb L (a, b, s, v) = \{ 2^s(v - a + b) + x_0 \in\Bbb Z \mid 0\leqslant x_0 < 2^s\}$$ i.e. there are $2^s$ different solutions.

emacs drives me nuts
  • 10,390
  • 2
  • 12
  • 31