# What function is this?

I'm trying to find a function. And although it seems to be very simple at first I can't figure it out. Maybe I just need some sleep, and maybe someone could help me out.

given an Integer x between 0 and 100:
if x is between 0-10 then f(x)=0
if x is between 11-20 then f(x)=11
if x is between 21-30 then f(x)=21
if x is between 31-40 then f(x)=31
...
if x is between 91-100 f(x)=91


I'm trying to find the simplest f possible.

The best I could do is:

f(x) = x / 10 * 10


But it's not right.

What function is f?

EDIT

I'm accepting @Didier's solution but I'm going with this one instead.

$$f(x) = \begin{cases} 1+10\lfloor (x-1)/10 \rfloor & \mbox{if } x >10; \\ 0 & \mbox{if } x \leq 10 \end{cases}$$

-
What language are you using? As I mentioned in comments to the answers, your problem becomes slightly easier if your environment treats 0 and 1 as Booleans... –  Guess who it is. Sep 10 '11 at 18:56
I'm on Javascript –  eduardocereto Sep 10 '11 at 19:09
JS, huh? Well then: (x < 11 ? 0 : (10*Math.floor((x-1)/10)+1)) ... –  Guess who it is. Sep 10 '11 at 19:23
P.S. generating-functions is for something quite different... –  Guess who it is. Sep 10 '11 at 19:29

Let $H$ denote the Heaviside step function, using the convention that $H(x)=1$ if $x\ge0$ and $H(x)=0$ if $x<0$. Then, for every $x$, $$f(x)=H(x-11)+10\,\sum\limits_{k=1}^9H(x-1-10\,k).$$ An equivalent formulation, based on Iverson bracket, is $$f(x)=[x\ge11]+10\,\sum\limits_{k=1}^9[x\ge1+10\,k].$$ Still equivalently, but less rigorously, $$f(x)=[x\ge11]+10\,[x\ge11]+10\,[x\ge21]+10\,[x\ge31]+\cdots+10\,[x\ge91].$$

-
I have no idea of what you mean. But it looks like cheating to me. A magical function that get's rid of the different range problem. You sure there's no simpler function? –  eduardocereto Sep 10 '11 at 18:46
If OP is working in a C-ish language, one could formally replace the unit step functions with Iverson brackets... –  Guess who it is. Sep 10 '11 at 18:48
@eduardo: What's cheating here? Your function is piecewise-defined, and unit step functions are used for representing piecewise-defined functions among other things... –  Guess who it is. Sep 10 '11 at 18:49
Sorry I was just checking. I'm not a pro mthematician like you guys. But I'm still trying to understand this function. The $\sum$ is puzzling me. I think I'll go with 2 separate functions, one for the first range and one for the second. –  eduardocereto Sep 10 '11 at 18:54
@eduardo: The $\sum$ means you can use a for loop or while loop, as the case may be... –  Guess who it is. Sep 10 '11 at 18:58

$f(x) = 1+10\lfloor (x-1)/10 \rfloor$ works, except for the first range. Are you sure that $f(x)$ is not $1$ for $0 \le x \le 10$?

-
yes I'm sure. But thanks for the effort. –  eduardocereto Sep 10 '11 at 18:39

The function would be $$f(x)=10\left\lfloor\frac{x-1}{10}\right\rfloor+1$$ where $\lfloor \;\;\;\rfloor$ denotes the floor function, except that the definition for $0\leq x\leq 10$ does not match the pattern of the other parts of the definition - if you defined $f(x)=1$ for $1\leq x\leq 10$ and $f(0)=-9$, then the above function would be correct for all inputs.

-
This is exactly what is driving me crazy. The first range doesn't match. But the question is correct. –  eduardocereto Sep 10 '11 at 18:41
If you multiply $f(x)$ with $[x-11 \geq 0]$ where $[p]$ is an Iverson bracket, then his problem's solved. –  Guess who it is. Sep 10 '11 at 18:53
I had to google about the Iverson bracket. But it seems good. en.wikipedia.org/wiki/Iverson_bracket –  eduardocereto Sep 10 '11 at 18:56

In C notation,

(x > 10 ? 1 : 0)*((x-1)/10*10 +1)

-
Yup, the inline conditional would be best, but I'd have done (x <= 10 ? 0 : 1 + (x-1)/10*10) or something... –  Guess who it is. Sep 10 '11 at 19:03
This is very useful, thanks for providing this, I'm accepting Didier's because it's more in line with my question about a single function to solve the case. Though your solution is better in pratical terms to me. –  eduardocereto Sep 10 '11 at 19:10