8

Hello all I would like to learn how to show if/else logic in math notation so here is the problem I'm faced with.

then

If R_x is in [X1, X_end] 
 then: If R_y is f(R_x)
  then If R_z < C
   then 0
Else 
1

How do I convert this into math notation ?

  • What's wrong with writing things out? Why must everything be converted to dense symbols? For example, you can write "If $n$ is odd, then $f(n) = 3n + 1$, else $f(n) = \frac{n}{2}$." You can use symbols to make this statement more concise, and presumably intelligible for people who don't know English, but remember that far more people around the world know English than know math logic notation! – Robert Soupe May 08 '15 at 15:30

1 Answers1

11

If I understand your pseudocode correctly, you can state this as a piecewise-defined function using sets, for example:

$$ g(x) = \left\{\begin{array}{ll} 0 & x\in S\\ 1 & x\notin S \end{array}\right. $$

You just have to define the appropriate set $S$. In your case, it looks like you have 3 numbers i.e. $x = (R_x,R_y,R_z)$, and your set would look something like

$$ S = \{(R_x,R_y,R_z):x_1\leq R_x\leq x_{end}\}\cap \{(R_x,R_y,R_z):R_y = f(R_x)\} \cap \{(R_x,R_y,R_z):R_z<C\} $$ All three sets are subsets of $\Bbb{R}^3$, so $S$ is as well.

icurays1
  • 17,161
  • 2
    One doesn't need to define a set -- just giving the condition directly in the definition-by-cases is perfectly valid: $$ g(R_x,R_y,R_z) = \begin{cases} 0 & \text{if }R_x\in[X_1,X_{\rm end}] \land R_y=f(R_x) \land R_z< C \ 1 & \text{otherwise} \end{cases} $$ – hmakholm left over Monica May 07 '15 at 21:12
  • Sure, logically it's the same thing. Defining the set maybe makes it more clear that it's a function that is defined to be 0 on some subset of $\Bbb{R}^3$ and 1 elsewhere. In OP's case it looks like this set is a subset of the graph of a function, which might be useful from a visualization point of view. – icurays1 May 07 '15 at 21:15
  • Good to give both formulations. I personally found Henning's formulation easier to follow, but now OP has a choice. – Brian Tung May 07 '15 at 21:19