title: Multiplication of two intervals
body: <p>As per the below question picked from self training <a href="http://www-inst.eecs.berkeley.edu/~cs61a/fa12/hw/hw3.html" rel="nofollow">exercise</a>:</p>
  
  <blockquote>
    <p>In passing, Ben also cryptically comments, "By testing the signs of the endpoints of the intervals, it is possible to break mul_interval into nine cases, only one of which requires more than two multiplications." Write a fast multiplication function using Ben's suggestion:</p>
  </blockquote>
  
  <pre><code>def mul_interval_fast(x, y):
      """Return the interval that contains the product of any value in x and any
      value in y, using as few multiplications as possible.
  
      &gt;&gt;&gt; str_interval(mul_interval_fast(interval(-1, 2), interval(4, 8)))
      '-8 to 16'
      &gt;&gt;&gt; str_interval(mul_interval_fast(interval(-2, -1), interval(4, 8)))
      '-16 to -4'
      &gt;&gt;&gt; str_interval(mul_interval_fast(interval(-1, 3), interval(-4, 8)))
      '-12 to 24'
      &gt;&gt;&gt; str_interval(mul_interval_fast(interval(-1, 2), interval(-8, 4)))
      '-16 to 8'
      """
      "*** YOUR CODE HERE ***"
  </code></pre>
  
  <p>I could analyse that, below is the pattern of results:</p>
  
  <pre><code>(1, 3)(5, 7)  ---&gt; [min(5, 7, 15, 21), max(5, 7, 15, 21)]              ---&gt;   (5, 21)
  (-1, -3)(-5, -7)  ---&gt;  [min(5, 7, 15, 21), max(5, 7, 15, 21)]         ---&gt;   (5, 21)
  +++++++++++++++++++++++++++++++
  (1, 3)(5, -7)  ---&gt;  [min(5, -7, 15, -21), max(5, -7, 15, -21)]        ---&gt;   (-21, 15)
  (-1, 3)(5, -7)  ---&gt;  [min(-5, 7, 15, -21), max(-5, 7, 15, -21)]       ---&gt;   (-21, 15)
  (1, -3)(-5, 7)  ---&gt;  [min(-5, 7, 15, -21), max(-5, 7, 15, -21)]       ---&gt;   (-21, 15)
  (-1, -3)(-5, 7)  ---&gt;  [min(5, -7, 15, -21), max(5, -7, 15, -21)]      ---&gt;   (-21, 15)
  +++++++++++++++++++++++++++++++++++
  (1, 3)(-5, 7)  ---&gt;  [min(-5, 7, -15, 21), max(-5, 7, -15, 21)]        ---&gt;   (-15, 21)
  (-1, 3)(-5, 7)  ---&gt;  [min(5, -7, -15, 21), max(5, -7, -15, 21)]       ---&gt;   (-15, 21)
  (1, -3)(5, -7)  ---&gt;  [min(5, -7, -15, 21), max(5, -7, -15, 21)]       ---&gt;   (-15, 21)
  (-1, -3)(5, -7)  ---&gt;  [min(-5, 7, -15, 21), max(-5, 7, -15, 21)]      ---&gt;   (-15, 21)
  ++++++++++++++++++++++++++++++++
  (1, 3)(-5, -7)   ---&gt; [min(-5, -7, -15, -21), max(-5, -7, -15, -21)]   ---&gt;   (-21, -5)
  (-1, -3)(5, 7)  ---&gt;  [min(-5, -7, -15, -21), max(-5, -7, -15, -21)]   ---&gt;   (-21, -5)
  ++++++++++++++++++++++++++++++
  (-1, 3)(5, 7)   ---&gt; [min(-5, -7, 15, 21), max(-5, -7, 15, 21)]        ---&gt;   (-7, 21)
  (1, -3)(-5, -7)  ---&gt;  [min(-5, -7, 15, 21), max(-5, -7, 15, 21)]      ---&gt;   (-7, 21)
  +++++++++++++++++++++++++++++++
  (-1, 3)(-5, -7) ---&gt;   [min(5, 7, -15, -21), max(5, 7, -15, -21)]      ---&gt;   (-21, 7)
  (1, -3)(5, 7)  ---&gt;  [min(5, 7, -15, -21), max(5, 7, -15, -21)]        ---&gt;   (-21, 7)
  </code></pre>
  
  <p>But above pattern does not show those <code>nine cases</code>.</p>
  
  <p>So, In specific, I would like to understand this point: <code>By testing the signs of the endpoints of the intervals, it is possible to break mul_interval into nine cases,</code></p>
  
  <p>Please help me on this interval arithmetic!!!</p>