Looking for a formula to compute $\left\lceil \frac{x+1}{2} \right\rceil$

64 Views Asked by At

I'm looking for a formula to easily compute: $$ \left\lceil \frac{x+1}{2} \right\rceil $$ The formula shouldn't use any floor, ceil or round function. I'm looking for something "simple".

2

There are 2 best solutions below

1
On BEST ANSWER

No closed-form expression with $+,-,\times,\div$ can "emulate" the ceiling function (in particular because these operators are continuous; all they allow are rational fractions). With these basic operators, you would need an expression of infinite size.

Periodic functions and their inverses, like

$$\frac1\pi\arctan(\tan(\pi x))$$ give you access to the fractional part, from which you can build the floor/ceiling. But this is by no means "simple".

The answer is essentially no way.

9
On

If $\frac{x+1}{2}$ isn't an integer, then $$\left\lceil \frac{x+1}{2} \right\rceil=\left\lfloor \frac{x+1}{2} \right\rfloor+1$$ and $$(x+1) \pmod{2}=x+1-2\cdot\left\lfloor \frac{x+1}{2} \right\rfloor$$ $$ \iff \left\lfloor \frac{x+1}{2} \right\rfloor=\frac{(x+1)-((x+1) \pmod{2})}{2}$$ $$\implies \left\lceil \frac{x+1}{2} \right\rceil=\frac{(x+1)-((x+1) \pmod{2})}{2}+1$$ Otherwise $\left\lceil \frac{x+1}{2} \right\rceil=\frac{x+1}{2}$