How Can I Simplify An Inequality With A Floor Function?

72 Views Asked by At

I'm trying to convert between pagination by starting index $i$ & length $l$ and pagination by page number $p$ & page size $s$. I've gotten far enough to know that:

for given $i$ and $l$ such that $ i\gt l $: $$\frac {i+l}{1+\lfloor \frac is \rfloor} \le s$$

How can I find the minimum $s$ for that inequality?

EDIT: Also, $ \{i,l,p,s\} \in \Bbb N$

2

There are 2 best solutions below

0
On

$$i+l\le s-s\left\lfloor\frac is\right\rfloor=2s-i\bmod s.$$

Unfortunately, the function on the RHS is quite irregular. IMO exhaustive search is needed.

0
On

(Too long for a comment.) The following provides a lower bound for $\,s\,$, though not an actual minimum since it cannot always be attained.

The inequality is verified for $\,s=i\,$, so the minimum $\,s\,$ is $\,\le i\,$. Let $\,\dfrac{i}{k+1} \lt s \le \dfrac{i}{k}\,$ for some integer $\,k \ge 1\,$. Then $\,\left\lfloor \dfrac{i}{s}\right\rfloor = k\,$, and the inequality can be written as:

$$ i+l \le (k+1)s \tag{1} $$

By the definition of $\,k\,$, the RHS is $\,(k+1)s \le \left(1+\dfrac{1}{k}\right)i\,$, so for the equality to hold this implies:

$$\require{cancel} \bcancel{i}+l \le \left(\bcancel{1}+\dfrac{1}{k}\right)i \quad\implies\quad k \le \frac{i}{l} \quad\implies\quad k \le \left\lfloor \frac{i}{l} \right\rfloor \tag{2} $$

Substituting back in $\,(1)\,$ gives the lower bound:

$$ s \ge \frac{i+l}{k+1} \ge \frac{i+l}{1 + \left\lfloor \frac{i}{l} \right\rfloor} \quad\implies\quad s \ge \left\lceil\frac{i+l}{1 + \left\lfloor \frac{i}{l} \right\rfloor}\right\rceil \tag{3} $$

The lower-bound is not always attained, though. For example, with $\,i=5, l = 2\,$, $\,(3)\,$ gives $\,s \ge 3\,$, while the actual minimum is $\,s=4\,$.