# How do you make an accurate, integrable approximation of $a \operatorname{mod} \left(\frac xb,1 \right)$ with a scaling constant $N$?

I'm working on a project where I'm working with modulo functions. However, to continue, I need to integrate integral powers of a weighted sum of them (e.g of the form $$\left(c+\operatorname{weighted sum} \right)^p$$, with $$c$$ a real, positive constant, and $$p \in \mathbb{Z}$$). So, I first tried Fourier series. However, since the weights are pretty high, the errors blew up, and the amount of terms necessary to correct them are prohibitively high. So, I need another way to create the modulo functions.

This leads me to my question: just like the title says, is there some approximation of $$a \operatorname{mod} \left(\frac xb,1 \right)$$, $$f(x)$$ (with $$a,b, \geq 1, \in \mathbb{R}$$), that has an elementary, closed form antiderivative, has a scaling constant $$N$$ so that as $$N \to \infty$$, $$|a \operatorname{mod} \left(\frac xb,1 \right)-f(x)| \to 0$$ (hopefully $$\sim \mathcal{O} \left(10^{-\operatorname{|poly(N)|}}\right)$$, but not neccessary) at least on $$\{ bk+0.1 \leq x \leq bk+0.9, k=\{0,1,2,3..,\lceil \frac nb \rceil\}\}$$, with $$n \in \mathbb{R}$$ (but hopefully over all $$x \in [0,n]$$), and has a constant number of terms $$k$$ that independent of $$N,n,a,b$$.

• Did you try to use the substitution $x=1/y$? Sep 19 '20 at 5:56
• @მამუკაჯიბლაძე How would that help me? Sep 19 '20 at 20:20
• There's something I don't understand here - $a\ \mbox{mod} (\frac{x}{b} )$ itself is elementary and has a closed form antiderivative, so why approximate it? Restricted to intervals between jumps, it's linear, and a square of a weighted sum thereof consists of pieces of parabolas. Sep 20 '20 at 0:49
• @MichaelEngelhardt While that is true, the square (and other integral powers) of the function does not have such a closed form antiderivative (however, if they do, I would like to know). Sep 20 '20 at 1:40
• Isn't the modulo function linear in each interval between jumps? Isn't the square of a linear function a parabola? Sep 20 '20 at 1:55

Let's consider the concrete example given by the OP in comments, $$f(x) = \left( 4\ \mbox{mod} \left( \frac{x}{5} ,1\right) + 10\ \mbox{mod} \left( \frac{x}{33} ,1\right) \right)^{p} \ .$$ $$f(x)$$ is periodic with period $$5\cdot 33 = 165$$. It is discontinuous at the points $$\{ 5n : n\in \mathbb{Z} \} \cup \{ 33n : n\in \mathbb{Z} \}$$; these can be easily listed and sorted in ascending order within any integration range one may be interested in (and for a periodic example such as this, it's of course sufficient to be able to treat one period). The entire integral of $$f$$ can be assembled by summing up the integrals over individual intervals between consecutive discontinuities, for all such intervals contained in the integration range one is interested in.
Consider an arbitrary such interval, $$[d_i ,d_{i+1} ]$$, where the $$d_i$$ denote the discontinuities. On this interval (caveat - for negative $$x$$, one might have to specify exactly how one interprets the mod function), $$f(x) = \left( 4\ \mbox{mod} \left( \frac{d_i }{5} ,1\right) + 10\ \mbox{mod} \left( \frac{d_i}{33} ,1\right) + \left( \frac{4}{5} + \frac{10}{33} \right) (x-d_i ) \right)^{p} \ .$$ or, to streamline the notation, $$f(x) = (s+tx)^p$$ and one has the integral $$\int_{d_i}^{d_{i+1} } dx\, f(x) = \frac{(s+td_{i+1} )^{p+1} }{t(p+1)} - \frac{(s+td_i )^{p+1} }{t(p+1)}$$ It remains to sum up these contributions; note that the first and the last interval may be only partially integrated over and then the lower or upper integration limits, respectively, have to be appropriately adjusted.