I encountered something weird while programming in Python. I understand that (31//16)*4is 4 because 31//16 evaluates to 1 and 1*4 is 4. But if I try to simplify the expression by taking out 4 from numerator and denominator which results in 31//4. It is equal to 7. Why this simplification results in something different?
2026-04-06 08:08:22.1775462902
What are simplification rules for expressions involving floor division?
50 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
1
Let $N$ be the numerator and $D$ the denominator. Then, we have the general relation: $N = D \cdot (N // D) + N \% D$, where $N \% D$ simply indicates the congruence class modulo $D$ of $N$ (i.e., the reminder of the division $\frac{N}{D}$).
P.S. In your example, $N=31$ and $D=16$. Consequently, $\left \lfloor{\frac{31}{16}}\right \rfloor = 1$ and you have a reminder $31 \% 16$ equal to $15$, which is congruent to $-1 \pmod{16}$. Now, $\left \lfloor{\frac{31}{4}}\right \rfloor = 7$ and we have a reminder of $31-28 = 3$... and it would be quite obvious why, in general, we cannot simplify a multiplicative coefficient of $N$ with its congruence class modulo $D$. The integer part we get from $(N // D)$ is simply the floor (i.e., the integer part) of $\frac{N}{D}$ and it is the same one for $D$ different congruence classes.