2
$\begingroup$

Is there any simple math expression that returns $-1$ if $x > a$ or $1$ if $x < a$?

$\endgroup$
  • $\begingroup$ What if $x=a$?? $\endgroup$ – Marc van Leeuwen Oct 24 '13 at 13:19
  • $\begingroup$ It can either be undefined at x = a, or -1 or 1. Doesn't matter to me. $\endgroup$ – Alon Gubkin Oct 24 '13 at 13:20
  • 1
    $\begingroup$ Is $\dfrac{a-x}{\lvert a-x\rvert}$ to your liking? $\endgroup$ – Daniel Fischer Oct 24 '13 at 13:24
  • $\begingroup$ @DanielFischer Yeah, can you post that as an answer? $\endgroup$ – Alon Gubkin Oct 24 '13 at 13:26
3
$\begingroup$

To convert Daniel Fischer's perfectly good comment-answer into an actual answer: $$\frac{a-x}{|a-x|}$$

$\endgroup$
  • $\begingroup$ Hey, that's not true. I do that a lot. I just can't keep up with them all. $\endgroup$ – Daniel Fischer Oct 24 '13 at 18:13
  • $\begingroup$ Fair enough. It always strikes me that you (and David Mitra) leave a whole bunch of comment-answers, but I haven't seen many of your actual answers. $\endgroup$ – Cameron Buie Oct 24 '13 at 19:23
  • $\begingroup$ Odd. Our primary tags have a fair amount of overlap. $\endgroup$ – Daniel Fischer Oct 24 '13 at 19:30
3
$\begingroup$

The simplest I know is $$f(x)= \begin {cases} 1 &x \lt a\\-1&x\gt a \end {cases}$$ This is a fine expression

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.