0

I have a formula and I don't know how to write it in mathematical form (I'm a programmer.)

The formula needs the variable y to be y - 1 unless y <= 0, in which case y should just be 0.

Programmatically, it would look like this:

if (y > 0) then
  y = y - 1
else
  y = 0

How does one write this using proper mathematical terminology?

jpreed00
  • 113
  • 2
    $$\max{y-1,0}\quad\text{or}\quad\tfrac12(y-1+|y-1|)\quad\text{or}\ldots$$ – Did Jun 26 '15 at 21:02
  • Excellent, thank you. – jpreed00 Jun 26 '15 at 21:03
  • Technically, even if you did not have a different assignment for the case where $y \leq 0$, the mathematical form of y=y-1 would still not be $y=y-1$. Instead you might have $y' = y-1$, $y_{n+1} = y_n - 1$, or some even more complicated structure. So it becomes a rather open-ended question to ask, "How does one write this using proper mathematical terminology?" – David K Jun 26 '15 at 21:09
  • @jpreed00 You are welcome. – Did Jun 26 '15 at 21:40
  • @Did : your proposed solution gives 0 for y=1/2 instead of -1/2 – Tryss Jun 26 '15 at 22:01
  • @Tryss Should y be an integer? Anyway, the OP got the idea and can adapt it to their specific situation, I believe. – Did Jun 27 '15 at 07:13

1 Answers1

2

There's no such thing as "assignment" in mathematics (it's a bit different from equivalence, e.g. $y=y-1$ is a statement, rather than an operation), unless you're speaking of a function. In such a case it would look something like (rewriting what you've said explicitly):

$$ f(y) = \begin{cases} y-1, &\text{if } y>0\\ 0, & \text{otherwise}. \end{cases} $$

  • 1
    It might also make more sense writing this as a recursion, since this might be inside of a loop of some sort: $$y_{n+1} = \left{ \begin{array}{ll} y_n - 1 & y_n > 0\ 0 & y_n \le 0 \end{array}\right.$$ – Joel Jun 26 '15 at 21:07