# Find a general formula from piecewise-defined function (II)

This question is very similar to my previous one. I have: $s \in [0;100]$ and $s \in Z$. The piece-wise definition is as follows: $$20 \le s \le 100 \to 0\\ 10 \le s \lt 20 \to 1\\ s \le 9 \to 2\\$$

Following the previous question's answers my best try was this:

$\displaystyle f(s) = 2 - \left \lfloor \frac{s}{10} \right \rfloor + H \left (\left \lfloor \frac{s}{10} \right \rfloor - 3 \right ) \cdot \left ( \left \lfloor \frac{s}{10} \right \rfloor - 2 \right )$

where $H(x)$ is the Heaviside Step Function. That involves too many calculations. There must be something simpler, I'm just too blind to see it

-
You need to specify what functions can appear in the formula. For example, in C you could write something like (s <= 9 ? 2 : (s >= 10 && s < 20 ? 1 : 0)). – copper.hat Oct 10 '12 at 17:19
What is your objective exactly? Are you using this for a computer program or are you seeking a mathematical answer? – Emmad Kareem Oct 10 '12 at 17:43
@copper.hat: I seek a mathematical answer, like those of my previous question. Allowed functions should be floor, ceil, heaviside step function. But if an answer formula contains some other functions I could accept it. It's difficult to say which one are allowed beforehand. – rubik Oct 10 '12 at 18:05
@EmmadKareem: See my previous comment. – rubik Oct 10 '12 at 18:05

1
A mathematical answer is a bit vague. For what purpose do you want such a formula? One formula could be in terms of characteristic functions, eg, $s \mapsto 1_{\{0,...,9\}}(s)+ 2 \cdot 1_{\{10,...,19\}}(s)$. – copper.hat Oct 10 '12 at 18:20
show 1 more comment

## 2 Answers

With this definition of the Heaviside step function you may use for example : $$f(s)=\left(2-\left \lfloor \frac s{10}\right \rfloor\right)\operatorname{H}(19-s)$$ or the simple : $$f(s)=\operatorname{H}(9-s)+\operatorname{H}(19-s)$$

-

Aw, your second one was rather obvious, I feel stupid now :) – rubik Oct 10 '12 at 19:17
@rubik: Agreed (I was influenced by your divisions by $10$ first and had to get out of the attractor :-)) – Raymond Manzoni Oct 10 '12 at 19:27

$$f(s)=1-\text{sgn}(\lfloor s/10-1 \rfloor)$$

-

1
Interesing idea with the sign function! – rubik Oct 10 '12 at 19:16
Thanks ${ }$ ${ }$ – draks ... Oct 10 '12 at 19:19
{"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": 8, "mathjax_display_tex": 4, "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": false}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9050265550613403, "perplexity_flag": "middle"}