Can this expression: $\left \lfloor \left(\frac x 2 \right)^2\right \rfloor $ be rewritten without the floor part?

98 Views Asked by At

I was working on a graph theory problem that asks the maximum amount of edges on a bipartite graph of $x$ vertices, I got to the conclusion it should be: $$\left \lfloor \left(\frac x 2 \right)^2\right \rfloor $$

Note that if $x$ is even, the floor part is redundant.

1

There are 1 best solutions below

2
On

You can define it to be a piecewise function (thanks @Winther - the equation was not coming to my head until I saw your comment):

$$\left\{\begin{matrix} (x/2)^2 & \text{if }x\text{ is even}\\ (x^2-1)/4 & \text{if }x\text{ is odd} \end{matrix}\right.$$

For arbitrary reals? You can define $a(x)=\frac{2\left(\cos \left(x\pi \right)-1\right)}{4}+1$ and define your function to be $a\left(x\right)\left(\frac{x}{2}\right)^2+a\left(x-1\right)\left(\frac{x^2-1}{4}\right)$. This works since $a(x)$ is $0$ for odd numbers and $1$ for even numbers. Expanded, it would look like this: $$\left(\frac{2\left(\cos \left(x\pi \right)-1\right)}{4}+1\right)\left(\frac{x}{2}\right)^2+\left(\frac{2\left(\cos \left(x\pi-\pi\right)-1\right)}{4}+1\right)\left(\frac{x^2-1}{4}\right).$$ Oh yes. That was fun.