# 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... – J. M. Sep 10 '11 at 18:56
I'm on Javascript – eduardocereto Sep 10 '11 at 19:09

1
JS, huh? Well then: `(x < 11 ? 0 : (10*Math.floor((x-1)/10)+1))` ... – J. M. Sep 10 '11 at 19:23
– J. M. Sep 10 '11 at 19:29

## 4 Answers

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... – J. M. Sep 10 '11 at 18:48

2
@eduardo: What's cheating here? Your function is piecewise-defined, and unit step functions are used for representing piecewise-defined functions among other things... – J. M. 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... – J. M. Sep 10 '11 at 18:58
show 2 more comments

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... – J. M. 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

$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

2
If you multiply $f(x)$ with $[x-11 \geq 0]$ where $[p]$ is an Iverson bracket, then his problem's solved. – J. M. Sep 10 '11 at 18:53
– eduardocereto Sep 10 '11 at 18:56
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 20, "mathjax_display_tex": 5, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9338437914848328, "perplexity_flag": "middle"}