3

My brother asked me what the definition of mod was, and I gave him the usual spiel about it being the "remainder" of division. However, he wanted a definition of mod based on functions he understood.

He's told me that he has an inherent sense of most basic operators (+, -, /, *, ^, log), but not the sorts of ones that I brought up at first when trying to define mod (ceil, floor, integer division). However, he also feels like he has a good understanding of trig as well, so basic trig functions are generally permitted (sin, cos, tan, arcsin, arccos, arctan) alongside usage of $\pi$.

Is it possible to define $a \pmod b$ in terms of these more elementary operators?

(Again, the list is: +, -, /, *, ^, log, sin, cos, tan, arcsin, arccos, arctan, $\pi$.)

I believe I have a solution using tan and arctan which I will post as an answer, so I'm especially curious about solutions that don't use trig functions, or a proof that it's impossible to do without the trig functions.

From a mathematics perspective, I'm particularly curious about answers to this question because each one of these definitions will likely have an extension into negatives or imaginary numbers that will give interesting extrapolations that our usual definition of "remainder" is difficult to bring to bear in those situations.

(As an additional note, the solution shouldn't just define mod as an "infinite piecewise function." In other words, the solution can be piecewise, it just can't have infinite pieces.)

EDIT: As mentioned in the comments under my answer, I should also allow piecewise functions that check for domain and range. As L.F. put it, functions in the form "$f(x)$ if $x \in \mathrm{dom}(f)$, or $g(x)$ otherwise" are also permitted. (My brother does have an inherent understanding of domains and ranges.)

Pro Q
  • 915
  • 5
    I'm sorry... what? Your brother understands the logarithm and the exponential function, but ceil, floor, and integer division are just too difficult? – 5xum Jul 27 '22 at 06:28
  • He'd never encountered them in school before! Obviously, the mod function itself isn't too difficult to understand, but he was curious about only using the functions he's encountered in school. (They usually don't teach ceil, floor, integer division, mod, etc.) – Pro Q Jul 27 '22 at 07:34
  • 4
    Learning about integer division would give much more insight into the mod function than defining it in terms of tan and whatnot. Just my 2ct. – Martin R Jul 27 '22 at 07:45
  • 1
    I'm a little surprised your brother never encountered them in school before. Perhaps my school was weird, but integer division and modular arithmetic was essentially how we first learned division, just not by those names. For example, in elementary school we would say "$5$ divided by $3$ is $1$ with a remainder of $2$." Then later we learned about fractions and decimals and how to define non-integer answers. – user6247850 Jul 27 '22 at 13:18
  • @user6247850 While I think these comments will probably be deleted due to not really helping the question, I think my brothers' teaching was similar. However, they did not teach a % modulo operator or a // integer division symbol. He's mathematically inclined and so was curious about finding solutions only using operators he'd encountered. It's not the concepts that are tricky, he's just curious! (And this proved to be an interesting challenge that I wanted to share and offer up to members of the site as well.) – Pro Q Jul 28 '22 at 09:07

1 Answers1

4

The solution I found was to use the repeating nature of tangent in order to create a mod function.

The tangent function has a period of $\pi$, but it starts at this awkward $-\frac{\pi}{2}$. So the first thing I did was get rid of that, and shift the function over to the right by $\frac{\pi}{2}$. This looks like $\tan\left({x - \frac{\pi}{2}}\right)$. (Note that while it may seem like you can just remove this step, if you do, you may get negative numbers for your mod when you only input positive numbers, which is not desirable.)

Now, the trick is to turn a modulo operation like $a \pmod b$ into a number that's a fraction ($\frac{a}{b}$) of the period. Then, we can use the tan function to turn it into the same number whether it's $a$ or $a + b$ (or $a + 2*b$, etc.), because $\frac{a+b}{b} = \frac{a}{b} + 1$, which, when multiplied by the period, will put us on the same $\frac{a}{b}$ part of the tan function! So this gives us $\tan \left(\frac{a}{b} \pi - \frac{\pi}{2} \right)$.

Then, we can use $\arctan$ to recover the input to the $\tan$ function, but now that input will have been shifted to always be in the range of $\arctan$, which is exactly what we want for mod. So, then, all we need to do is recover the $a$, which we do by undoing the $-\frac{\pi}{2}$ with addition, undoing the multiplication by the period ($\pi$) by dividing by $\pi$, and then undoing the original divide by $b$ in the fraction by instead multiplying by $b$.

In the end, we get:

$$a \pmod b = \left( \arctan \left( \tan \left(\frac{a}{b} \pi - \frac{\pi}{2} \right) \right)+\frac{\pi}{2}\right) \frac{b}{\pi}$$

Here's a Desmos demo to show what I'm talking about.

The only other thing that needs fixing (as pointed out by @John Omielan) is that tan can become undefined when $a \pmod b$ is 0. So, to fix this, we can just turn it into a piecewise equation.

Let $m(a, b) = \left( \arctan \left( \tan \left(\frac{a}{b} \pi - \frac{\pi}{2} \right) \right)+\frac{\pi}{2}\right) \frac{b}{\pi}$. Then, $$a \pmod b = m(a, b) \text{ if } a, b \in \mathrm{dom}(m) \text{, and } 0 \text{ otherwise.}$$

(The "if $a, b \in \mathrm{dom}(m)$" just means "if $a$ and $b$ are in the domain of $m$." Another way of saying this would be "if $m(a, b)$ is defined.")

Pro Q
  • 915
  • 1
    One issue is that $\tan(\theta)$ is not defined when $\cos(\theta) = 0$, i.e., for $\theta = n\pi - \frac{\pi}{2}$ for any integer $n$, with this occurring in your equation whenever $\frac{a}{b}$ is an integer. – John Omielan Jul 27 '22 at 06:06
  • Note that your solution uses the operation "$m$ if $m$ is in the domain of xxx and $0$ otherwise", which is not permitted in the body of the question. – L. F. Jul 27 '22 at 07:55
  • Hm @L.F. , I had thought that piecewise functions covered this, but I think you're right! In that case, this isn't a perfect solution. Any ideas on how to fix it? – Pro Q Jul 27 '22 at 19:12
  • 1
    @ProQ I think the problem here is that we allow piecewise functions but didn't provide any predicates. It is certainly reasonable to allow "$f(x)$ if $x \in \operatorname{dom}(f)$, or $g(x)$ otherwise" as a building block. – L. F. Jul 28 '22 at 01:44
  • If you're using Excel with A1=a & A2=b, you can use:

    =((ATAN(TAN(A1/A2PI()-PI()/2))+PI()/2)A2/PI())(1/PI()ATAN(COT(PI()(ACOS(COS(ABS(SIN(PI()A1/A2))))+1)))+1/2+(ACOS(COS(ABS(SIN(PI()*A1/A2))))+1)-1)

    – Michael Mar 09 '24 at 00:58