# A floor function appeared after integration. What happended?

I have laplace's equation, $\nabla^2f=0$, inside a circle (radius $a$) for which the boundary condition (polar coordinates) is

$$f(a,\phi) = \begin{cases} 1\quad \text{for 0< \phi < \pi/2}\\ -1\quad \text{for -\pi < \phi < -\pi/2}\\ 0\quad \text{otherwise} \end{cases}$$

I went to solve it using the formula (for $r<a$): $$f(r,\phi) = \frac{a^2 - r^2}{2\pi} \int^\pi_{-\pi} \frac{f(a,\phi)}{a^2 + r^2 - 2ar \cos(\phi-t)}dt$$

$$f(r,\phi) = \frac{a^2 - r^2}{2\pi} \left[ \int^{-\pi/2}_{-\pi} \frac{-1}{a^2 + r^2 - 2ar \cos(\phi-t)}dt + \int^{\pi/2}_{0} \frac{1}{a^2 + r^2 - 2ar \cos(\phi-t)}dt\right]$$

By using the universal trigonometric substitution, I arrived at $$f(r,\phi) = \frac{1}{\pi}\left[h\left(r,\phi,\frac{-\pi}{2}\right) - h\left(r,\phi,-\pi\right) - h\left(r,\phi,\frac{\pi}{2}\right) + h\left(r,\phi,0\right)\right]$$

Where $$h(r,\phi,t) = \arctan\left(\frac{a+r}{a-r} \tan\left(\frac{\phi - t}{2}\right)\right)$$

Which agrees with wolfram alpha's result.

But then the plotting for various values of $r$ gave me

When I did the symbolic integration using a hp 50g calculator, a $floor$ function appeared adding to $h$.

$$g(r,\phi,t) = h(r,\phi,t) + \pi\, \text{floor} \left( \frac{\phi-t}{2\pi} +\frac{1}{2} \right)$$

The final result being

$$f(r,\phi) = \frac{1}{\pi}\left[g\left(r,\phi,\frac{-\pi}{2}\right) - g\left(r,\phi,-\pi\right) - g\left(r,\phi,\frac{\pi}{2}\right) + g\left(r,\phi,0\right)\right]$$

Which plotting gave me the expected result

Now I cannot understand what happenned. Why and how did (must) that floor function appear?

Your $$h$$ is a local antiderivative; it has jump discontinuities whenever that argument $$\frac{\phi-t}{2}$$ of the tangent is equivalent to $$\frac{\pi}{2}$$ mod $$\pi$$. When we increase past such a point, that tangent goes from $$\infty$$ to $$-\infty$$, and thus $$h$$ decreases by $$\pi$$. (In practice, we'll be running the argument $$\phi-t$$ in the opposite direction, so they'll be upward jumps)

Except - this is an artificial singularity, introduced by our substitution. There's nothing wrong with those points in the underlying integral, and we should have an antiderivative that crosses them. In order to do that, we'll have to introduce something that cancels out the jump discontinuities - a step function. It's simplest to do that with $$h$$; we need something that steps up by $$\pi$$ at every odd multiple of $$\pi$$, and that formula $$\pi\left\lfloor \frac{\phi-t+\pi}{2\pi}\right\rfloor$$ is one way to do it.

Working without this, and blindly using your original form across those points, is wrong. For example, consider what would happen if we used $$f(a,\theta)=1$$. We would get $$f(r,\phi)=\frac{a^2-r^2}{2\pi}\int_{-\pi}^{\pi}\frac{1}{a^2+r^2-2ar\cos(\phi-t)}\,dt = \frac1{\pi}[h(r,\phi,-\pi)-h(r,\phi,\pi)] = 0$$ (Your sign convention for $$h$$ is a little confusing there)
Anyway, this is a ridiculous result; we should get that $$f$$ is uniformly equal to $$1$$ in this case, and certainly the integral of a positive function must be positive. We need a fix, and that fixed antiderivative $$g$$ is one way to do it. In the example, we get $$\frac1{\pi}[h(r,\phi,-\pi)-h(r,\phi,\pi)] = 1$$ as it should be, since $$\phi-t$$ crosses the key point exactly once in any given interval of length $$2\pi$$.

In your problem, with the more complicated boundary conditions, the form of the erroneous solution shifts whenever that key point $$\phi-t\equiv \pi$$ passes one of the jumps in $$f(a,\phi)$$.
For $$\phi\in (-\pi,-\frac{\pi}{2})$$, the key point is in $$(0,\frac{\pi}{2})$$ where $$f(a,\phi)=1$$ and missing the jump erroneously subtracts $$1$$ from the solution.
For $$\phi\in (-\frac{\pi}{2},0)$$, the key point is in $$(\frac{\pi}{2},\pi)$$ where $$f(a,\phi)=0$$ and the solution is unchanged.
For $$\phi\in (0,\frac{\pi}{2})$$, the key point is in $$(-\pi,-\frac{\pi}{2})$$ where $$f(a,\phi)=01$$ and missing the jump erroneously adds $$1$$ to the solution.
For $$\phi\in (\frac{\pi}{2},\pi)$$, the key point is in $$(-\frac{\pi}{2},0)$$ where $$f(a,\phi)=0$$ and the solution is unchanged.