# Defining a piecewise function using restricted operations

### Question

Can the piecewise function

$$f(x) = \begin{cases} 0 & \text{if x > 0} \\ 1 & \text{if x = 0} \\ 0 & \text{if x < 0} \\ \end{cases}$$

be defined using only the operations $$+ , -, *, /, |\cdots|, \max$$, and $$\min$$?

### What I have tried

I can define the first and last pieces: $$0$$ if $$x > 0$$ or $$x < 0$$ with

$$1 - \frac{x}{x}$$

But this will fail with a division by $$0$$ in the case where $$x = 0$$

$$1 - \frac{0}{0}$$

I can fix the division error by forcing a 1 on the bottom.

$$a(x) = 1 - \frac{x}{\max(1, x) \min(-1, x)}$$

This works for most negatives and $$0$$ and fails when $$-1 < x < 0$$ and $$x > 0$$. When $$x > 0$$, $$a(x) = 2$$. Fixing this requires another max to check a number is positive. Defining $$b(x)$$ to be $$2$$ when $$x > 0$$ and $$0$$ when $$x = 0$$ or $$x <= -1$$

$$b(x) = 2\frac{\max(0, x)}{\max(1, x) \min(-1, x)}$$

Combining them to get

$$c(x) = a(x) - b(x) = 1 - \frac{x - 2\max(0, x)}{\max(1, x) \min(-1, x)}$$

This mess is what I want except when $$-1 < x < 0$$ and $$0 < x < 1$$. This is as far as I have gotten.

• This is a unit impulse function $\delta(x)$. – Nash J. Sep 14 '17 at 12:01
• It's hard (for me) to see how to get a discontinuous, everywhere-defined function using the given operations. – paw88789 Sep 14 '17 at 12:16
• @NashJ.: The unit impulse function has value $\infty$ at $x=0$, but OP's function has value 1. – Kevin Sep 14 '17 at 18:17

Let's do algebra on functions, by defining for functions $f$ and $g$, $(f+g)(x) = f(x) + g(x)$, and so on with other operators.

Note that $f$ is not a continuous function. However, $+$, $-$, $\times$, $|\dots|$, $\max$ and $\min$ all produces continuous function if you provide them continuous function. Since all you base functions, $x \mapsto x$ and the constant functions $x \mapsto c$, are continuous on $\mathbb R$, you won't be able to create a non-continous function with finitely many operators.

That leaves only the division $\frac{\dots}{\dots}$, which is continuous on $\mathbb R \setminus \{ 0 \}$. However it is undefined on $0$, which means that either you would be left with undefined values, which you cannot since $f$ is defined everywhere, or your denominator is guaranteed to be all positive (or all negative) and the division will operate only on a fully continuous component and your result will again be continuous.

On $\mathbb R$, your problem cannot be solved with finitely many operations of $+$, $-$, $\times$, $\frac{\dots}{\dots}$, $|\dots|$, $\max$ and $\min$.

• So I would need a function which has a discontinuous jump but is defined everywhere like floor or ceil? How would the problem be solved with infinitely many operations of the above list? – spyr03 Sep 14 '17 at 12:55
• If you do add floor or ceil (either can be expressed in terms of the other), then $\lceil x \rceil - \lfloor x \rfloor = \begin{cases} 0, & x \in \mathbb{Z} \\ 1, & x \notin \mathbb{Z} \end{cases}$. You could then combine that with one of the tent functions in the other answers to get the originally desired function. – Daniel Schepler Sep 14 '17 at 22:06
• @spyr03 consider $x\mapsto\max(0, \min(1, x)),$ which is the function $f(x)=\{0\text{ if } x<0 \text{ else } x \text{ if } x < 1 \text{ else } 1\}$. Raise it to the $n^\text{th}$ power and the first and last regions do not change, but the middle region becomes $x^n$. In the limit $n\mapsto\infty$ the entire interval $x\in(0, 1)$ maps to the value $0$ and one has the Heaviside step function $H(x-1) = \{0\text{ if } x < 1 \text{ else }1\},$ from which your function is $H(x)\cdot H(-x).$ – CR Drost Sep 14 '17 at 22:08

Following Lærne's answer, I would like to elucubrate on how the problem coould be solved with infinite operations.

Let then define $$g(x) = \max (0, - \vert x \vert +1)$$ This is a "tent" function, that equals $0$ if $\vert x \vert > 1$, and equals $1$ for $x = 0$, being continuous and piecewise linear.

An approximation to the function $f$ indicated by the OP can be built to any degree of accuracy as $$f(x) \approx g(x)^n$$ (intuitively speaking, where $f(x) = 0$ or $f(x) = 1$ nothing happens upon multypling, while for any $x : 1 < g(x) < 1 , \,\,\, g(x)^k < g(x)^j$ when $k > j$)

Fellow Mathstackexchangers more versed on convergence issues could maybe formalise the limiting operation. I believe $g^n \to f$ pointwise as $n \to \infty$.

Note: The solution below is true only for integer values of $x$, i.e., $x \in \{\ldots, -3, -2, -1, 0, 1, 2, 3, \ldots\}$

Let $$f(x) = 1 - \dfrac{\max [\text{abs }\{ \max(0, x)\}, \text{abs }\{ \min(0, x)\}]}{\max [1, \text{abs}(x)]}$$

• Case I: When $x < 0$ \begin{align} f(x) & = 1 - \dfrac{\max [\text{abs }\{ \max(0, x)\}, \text{abs }\{ \min(0, x)\}]}{\max [1, \text{abs}(x)]} \\ & = 1 - \dfrac{\max [0, \text{abs}(x)\}]}{\text{abs(x)}} = 1 - \dfrac{\text{abs}(x)}{\text{abs}(x)} = 1- 1 = 0 \end{align}
• Case II: When $x = 0$ \begin{align} f(x) & = 1 - \dfrac{\max [\text{abs }\{ \max(0, x)\}, \text{abs }\{ \min(0, x)\}]}{\max [1, \text{abs}(x)]} \\ & = 1 - \dfrac{\max [0, 0\}]}{1} = 1 - \dfrac{0}{\text{abs}(x)} = 1- 0 = 1 \end{align}
• Case III: When $x > 0$ \begin{align} f(x) & = 1 - \dfrac{\max [\text{abs }\{ \max(0, x)\}, \text{abs }\{ \min(0, x)\}]}{\max [1, \text{abs}(x)]} \\ & = 1 - \dfrac{\max [x, 0]}{x} = 1 - \dfrac{x}{x} = 1- 1 = 0 \end{align}

Edit: A simple form can be $$f(x) = 1 - \dfrac{\max[0, \text{abs}(x)]}{\max[1, \text{abs}(x)]}$$

Suppose $\epsilon \rightarrow 0^+$, the piecewise function can be defined as $$f(x) = 1 - \dfrac{\max[0, \text{abs}(x)]}{\max[\epsilon, \text{abs}(x)]}$$

• You are missing a limit expression $\lim_{\varepsilon \to 0^+}$ on the right hand side, which is not allowed in the question. – Ben McKay Sep 14 '17 at 16:22
• @BenMcKay: He has a series of approximations to the piecewise function, and none of the approximations perform a limit. It is the limit of the series which is a "perfect" approximation to the function. This limit can't be expressed without a limit operation, but an arbitrarily good approximation, which doesn't use limit, can be selected. – Ben Voigt Sep 14 '17 at 17:02
• @BenVoigt: Sorry, I misunderstood. His mistake is the equals sign. – Ben McKay Sep 14 '17 at 17:04
• @BenMcKay: I agree, that should be $\rightarrow$ or $\approx$ – Ben Voigt Sep 14 '17 at 17:05

You asked how to define your function with an infinite number of operations from your list. Here it is defined by means of an infinite sum:

$$f(x) = \max(0,1-|x|) + \frac12\sum_{n=1}^\infty (\min(1,|2^n x+1|) + \min(1,|2^n x-1|) - 2).$$

The first part of this, $\max(0,1-|x|),$ is zero except for $-1<x<1,$ where its graph is an isoceles triangle whose vertices are $(-1,0),$ $(1,0),$ and $(0,1)$. Each of the terms of the sum is zero except for $-\frac{2}{2^n}<x<\frac{2}{2^n},$ where its graph consists of two isoceles triangles with vertices at $\left(-\frac{2}{2^n},0\right),$ $(0,0),$ and $\left(-\frac{1}{2^n},-1\right)$ (first triangle) and at $(0,0),$ $\left(\frac{2}{2^n},0\right),$ and $\left(\frac{1}{2^n},-1\right)$ (second triangle). The function $$f_m(x) = \max(0,1-|x|) + \frac12\sum_{n=1}^m (\min(1,|2^n x+1|) + \min(1,|2^n x-1|) - 2)$$ defined by taking only a partial sum is zero everywhere except for $-\frac{1}{2^m}<x<\frac{1}{2^m},$ where its graph is an isoceles triangle with vertices $\left(-\frac{1}{2^n},0\right),$ $\left(\frac{1}{2^n},0\right),$ and $(0,1).$ So for any $x\neq 0,$ $f_m(x) = 0$ whenever $m$ is large enough, whereas $f_m(0) = 1$ for all $m.$