# definite integral in regards to x for n mod x where n is a constant

I have read some posts on x mod y integrals but am unsure of how to find the integral of a constant mod x.

For example
6 mod x between 0 and 6

or

10 mod x between 0 and 10.

When I look at the graph of these functions I can see it generates a lot of lines starting at a point on the line y = x and descending to zero at some angle. So I can tell it generates an infinite number of right triangles between 0 and 1 and then n right triangles between 1 and n.

But I am struggling to even know where to begin to find their area.

• Where did you read about "definite integrals in regards to $\;x\pmod n\;$" ? Perhaps it was "INTEGERS $\;x\pmod n\;$" or something of the like? Mar 7, 2016 at 9:28

You can rewrite the integral as

$$\int_0^x \left(n-t\lfloor\frac nt\rfloor\right)dt.$$

The floor factor remains constant in the ranges $t\in\left(\dfrac n{k+1},\dfrac nk\right]$ for $k$ decreasing from $\infty$ to $m=\lfloor\dfrac nx\rfloor$. The last interval is incomplete, $t\in\left(\dfrac n{m+1},x\right]$.

We have

$$I=\sum_{k=\infty}^{m}\int_{n/(k+1)}^{n/k}\left(n-tk\right)dt+\int_{n/(m+1)}^{x}\left(n-tm\right)dt,$$ giving

$$2I=\sum_{k=\infty}^{m}\left.\left(n-tk\right)^2\right|_{n/(k+1)}^{n/k}+\left.\left(n-tm\right)^2\right|_{n/(m+1)}^{x}\\ =\sum_{k=\infty}^{m}\frac{n^2}{(k+1)^2}+(n-mx)^2-\frac{n^2}{(m+1)^2}\\ =\frac{\pi^2}6-H_m^{(2)}+(n-mx)^2-\frac{n^2}{(m+1)^2},$$

where $H_m^{(2)}$ denotes the generalized harmonic numbers of degree $2$.

• What do the variables t and k signify?
– ajt
Mar 8, 2016 at 1:41
• @ajt t is the variable as in $y\equiv n$ (mod t), where n is a constant. And it turns out y can be written as a function of t by $n-t\floor{\frac{n}{t}}$. k is the integer that represent the roots in descending order, as observed in m.wolframalpha.com/input/?i=x%3D10+%28mod+y%29&x=0&y=0 when k is 1, n/k=n is the largest root of the equation
– lEm
Mar 8, 2016 at 4:45
• So can t=x ? I guess I am confused because in the original equation I posted I just had x. In the integral Yves posted ∫ from 0 to x but then uses t to divide n.
– ajt
Mar 8, 2016 at 5:29
• @ajt: $t$ is the dummy variable required for integration.
– user65203
Mar 8, 2016 at 8:07
• @YvesDaoust Thank you for everything. I have only taken up to AP calculus at this point so I must admit I don't fully understand what is happening here. I don't want to drag this on but for the last equation you give =π26−H(2)m+(n−mx)2−n2(m+1)2. Would I do this for 10 mod x at x = 10 as: pi**2/6 - Hm2 + (10 - floor(10/10)*10)**2 - 100/4 ? Also how do I get the sum of harmonic numbers of degree 2? Is it 3/2 or something else? mathworld.wolfram.com/HarmonicNumber.html
– ajt
Mar 9, 2016 at 1:04

http://m.wolframalpha.com/input/?i=x%3D10+%28mod+y%29&x=0&y=0

See the graph here, the equation $x\equiv 10$ (mod $y$) has infinite number of lines between $[0,1]$. The roots $x\equiv 0\equiv 10$ (mod $y$) can be found at all $\frac{p}{q}$ where $p$ is a factor of 10 and $q\in\Bbb{N}$. For examples, $\frac{10}{11}$, $\frac{5}{19}$. So it could be hard to find out the value.

But for $y\in[1,10]$, we know the roots of $x\equiv0$ (mod $y$) are located at $1$, $\frac{10}{9}$, $\frac{10}{8}$, $\frac{10}{7}$, $\frac{10}{6}$, $\frac{10}{5}=2$, $\frac{10}{4}$, $\frac{10}{3}$, $\frac{10}{2}=5$ and $10$.

So we can compute the integral by computing the sum of area of triangles. (At least between $[0,1]$),

$\int_1^{10}{x(y)dy}=\sum_{k=1}^{9} [\frac{1}{2}x(y_k)*(y_{k+1}-y_k)]$

where $y_k$ is the $k^{th}$ root starting from $y_1=1$. And $x(y_k)$ is taken to be equal to $\lim_{y \to y_k^-}x(y_k)=y_k$

(I take this value because otherwise $x(y_k)$ is counted as $0$)

By computing the sum, you can find that the integral is equal to approximately $17.5116...$, exactly $\frac{2224115}{127008}$.

On the graph, notice that $y=x$ is an asymptote for the function. So when the value of $y$ is small. (Maybe between $[0,1]$). You can approximate the integral by observing the triangles take up about half of the area. So $\int_0^{y_0}x(y)dy\approx \frac{1}{4}y_0^2$ for small $y_0$.