0

I have a bucket of elements, the amount of elements $E$ is given by this equation, with constraints on parameters $S_A$ and $S_B$:

$$ \begin{equation*} \left\{ \begin{alignedat}{3} E_0 = (4-S_{A}) + 4*N + S_{B} \\ S_{A} < 4 ; S_{A} \in N\\ S_{B} < 4 ; S_{B} \in N\\ S_A > S_B \end{alignedat} \right. \end{equation*} $$

I pick these elements 4 at a time, so that after $n$ times $E_n = E_0 - 4*n $ until I can't do it anymore because $E_{N} < 4$, after picking them N times.

How do I find an expression for the remaining elements $E_N$?

I know that the operation to do is the modulo one, but I can't come up with an expression:

$$ E_N = E_0 \mod 4 $$ $$ E_N = [ (4-S_{A}) + 4*N + S_{B}] \mod 4 $$ $$ E_N = ( 4 - S_A + S_B ) \mod 4 $$

And I can't simplify anymore. I would like to reach an expression that has not the modulo in it.

Is it possible?

Since I need to use it in code where calculating the modulo is not an option, I can create a lookup table which is doable because the $S_A,S_B$ are small values, however finding an expression would be beautiful.

LUT = lambda sa,sb:(4-sa+sb)%4
for sb in range(4):
     for sa in range(4):
             if(sa>sb): 
                     print(f"f({sa},{sb}) -> {LUT(sa,sb)}")
f(1,0) -> 3
f(2,0) -> 2
f(3,0) -> 1
f(2,1) -> 3
f(3,1) -> 2
f(3,2) -> 3

Thanks a lot!

Fra93
  • 161
  • Not sure what you are after. You want to know remainder of $E_0$ on division by $4$? But that's clearly $4-S_A+S_B$. Which, I think, is what you wrote. What else do you want? – lulu Oct 12 '22 at 15:58
  • Thanks @lulu, you are right, this is valid if the constrain $S_A > S_B$, and I thank you for that because that's exactly my case. If the constrain is lifted this is no longer true. How would I find an expression for that (without mod in the expression)? Is it possible? – Fra93 Oct 12 '22 at 16:03
  • @lulu if $S_A = 0, S_B=2$ then $(4-S_A+S_B) \neq [(4-S_A+S_B)\mod4]$ because $6 \neq 2$ – Fra93 Oct 12 '22 at 16:05
  • You can't have $S_A=0. S_B=2$. you specified that $S_A>S_B$. If you want to drop that condition, then of course the rule is different. – lulu Oct 12 '22 at 16:07
  • @lulu I addressed that, I asked what if the constrain is lifted. Also, how did you see that the modulo was already reduced? I am interested in your thought process. – Fra93 Oct 12 '22 at 16:08
  • Your expression, with the constraints is $4+(S_B-S_A)$. The constraints assure us that $-3≤S_B-S_A<0$ – lulu Oct 12 '22 at 16:10
  • @lulu this is eye opening. Thanks a million. – Fra93 Oct 12 '22 at 16:11
  • Absent the constraints, I don't think there's a lot to say. The answer is the least possible natural number congruent to $4-S_A+S_B$ but there's no universal way to know what that is. – lulu Oct 12 '22 at 16:11
  • @lulu thanks, I just wanted to know if there was a way to derive an expression. I am fine saying that there is not one. – Fra93 Oct 12 '22 at 16:12

0 Answers0