title: Converting an If-Else statement into a Formula
body: <p>I have code as follows:</p>
  
  <pre><code>`if (a &lt;= 10){
      z = 5;
   } else {
      z = -1;
   }`
  </code></pre>
  
  <p>I figured out that when <code>s(10 - a) = |10 - a| / (10 - a)</code> where it outputs a 1 or -1. It outputs <code>1</code> if <code>a &lt; 10</code> and <code>-1</code> if <code>a &gt; 10</code>.</p>
  
  <p>Then, I just solve the linear equation <code>z = s(10 - a) * m + b</code>, to find constants m and b.</p>
  
  <p><code>5 = 1 * m + b</code>  and <code>-1 = -1 * m + b</code>
  Which outputs <code>b = 2, m = 3</code>.</p>
  
  <p>Then this can be modeled as <code>z = 3 * s(10 - a) + 2</code>.</p>
  
  <p>Now the question becomes more tricky. What if I have two variables in nested if statements? Such as:</p>
  
  <pre><code>`if (a &lt;= 10){
      if(b &lt;= 3){
         z = 3;
      } else {
         z = 1;
      }
   } else {
      if(b &lt;= -5){
         z = -11;
      } else {
       z = 4;
      }
  }`
  </code></pre>
  
  <p>I tried to solve this using another series of linear equations.</p>
  
  <ol>
  <li><code>3 = A * s(10 - a) + B * s(3 - b) + C</code></li>
  <li><code>1 = A * s(10 - a) + B * s(3 - b) + C</code></li>
  <li><code>-11 = A * s(10 - a) + D * s(-5 - b) + C</code></li>
  <li><code>4 = A * s(10 - a) + D * s(-5 - b) + C</code></li>
  </ol>
  
  <p>with A, B, C, D as constants. However, this isn't giving me the right answer. What am I doing wrong?</p>