1

Are there a mathematical function that takes the integer variable $x$ and uses a constant $k$ then,

it outputs $x$ when $x > k$

else outputs Zero

For example, when $k=5$ and,

when $x$ is given inputs $2, 3, 4, 5, 6, 7$ respectively,

It must output $0, 0, 0, 0, 6, 7$ respectively.

I want a purely mathematical equation for the function.

(Only using variables, arithmetic symbols and other functions such as the absolute function, but without using comparison operators)

  • 1
    "purely algebraic"... what is wrong with explicitly defining the function as you state it? Alternatively if you are wishing to impliment this in code, $(x>k)$ is often thought of as a boolean operator which outputs $1$ if true and $0$ if false, so $x(x>k)$ would have the effect you desire – JMoravitz Mar 30 '17 at 17:37

3 Answers3

3

I am not sure about what you consider to be algebraic but there is a famous function called the Heaviside function denoted by $u(x)$ which is equal to $1$ when $x>0$ and equal to $0$ otherwise. So for an integer $k$ your function will look something like this in terms of the Heavside function.

$$f(x) = xu(x-k)$$

Notice how when $x>k$ then $u(x-k) = 1$ so $f(x) = x$ and zero otherwise

2

Although fine answers have been given, alternatively one could do

$$f(x)=\frac x2\left(\frac{x-k}{|x-k|}+1\right)$$

Unfortunately we're dividing by $0$ if $x=k$, but if that doesn't occur, then you're good to go with this one.

Note that it is impossible to do only using variables and arithmetic symbols, since all of those are differentiable everywhere so any composition is also differentiable everywhere. We'll have to use "other functions such as the absolute function". I'm not quite sure to what extend we can use other mathematical functions, since, well, the one you described could be one.


Programatically however, as has been pointed out by @JMoravitz, a good solution would be
x(x>k);

Or, if boolean-to-integer conversion is not your thing, you could do

(x>k)?x:0;
1

Here is a solution using the ${\rm sign}(x)$ function: $$ f(x) = {x\over2}(1+{\rm sign}(x-k-0.5)). $$ We assume that both $x$ and $k$ are integers.

Alex
  • 4,873
  • Why the $-0.5$ though? It isn't given that $k$ is an integer, so it really doesn't do much. If we have $k=0.6$, then $f(1)=0$. Not really what the OP is looking for, I think –  Mar 30 '17 at 17:49
  • $0.5$ is needed to handle the case $x=k$. I did assume both $x$ and $k$ to be integers. – Alex Mar 30 '17 at 17:51
  • All the answers are working well and helpful, thanks again! – practronix512 Mar 31 '17 at 05:32