Associated Topics || Dr. Math Home || Search Dr. Math

### Floor and Mod Functions Discontinuous

```
Date: 10/10/2001 at 08:52:30
From: Alkhaled
Subject: The derivative of --> a MOD b

Dear Dr. Math,

I'll be more than greatful, having an answer to the following:

What is the derivative of --->    a MOD b      ?

To my understanding --> (a MOD b) = a - [floor(a/b) * b]

even in this case, i have no idea what is the derivative of:

[floor(a/b)]

Can [a MOD b] be represented in basic maths? i.e. using (+,-,/,*) or
something that can be differentiated?

Many thanks.
```

```
Date: 10/10/2001 at 12:56:05
From: Doctor Peterson
Subject: Re: The derivative of --> a MOD b

Hi, Alkhaled.

You haven't said whether you want the derivative with respect to a or
b; I'll assume you mean

f(x) = x mod b

for some fixed b. It would be possible to treat both a and b as
variables and determine the partial derivatives of

f(x,y) = x mod y

but I'll leave that for later if you need that.

The mod function, like any function whose definition involves
conversion from real numbers to integers (the floor function, in this
case), is discontinuous. If you graph it, it will be a sawtooth,
rising from 0 to b, then dropping back to zero (instantaneously) and
rising again. If you picture it right, you will immediately see what
its derivative has to be: 1 everywhere except at multiples of b, where
it is undefined.

The floor function is a step function, rising vertically at each
integer and then remaining constant until the next. Therefore, its
derivative is zero, but undefined at integers. If you then apply the
chain rule, you see that

d/dx[x mod b] = d/dx[x - b floor(x/b)]
= d/dx[x] - b d/dx[floor(x/b)]
= 1       - b * 0
= 1

for values of x except multiples of b.

The fact that floor and mod are discontinuous is the reason there is
no simple expression involving the (continuous) basic operations that
can  yield either of them.

- Doctor Peterson, The Math Forum
http://mathforum.org/dr.math/
```
Associated Topics:
High School Calculus
High School Functions

Search the Dr. Math Library:

 Find items containing (put spaces between keywords):   Click only once for faster results: [ Choose "whole words" when searching for a word like age.] all keywords, in any order at least one, that exact phrase parts of words whole words

Submit your own question to Dr. Math
Math Forum Home || Math Library || Quick Reference || Math Forum Search