title: SymPy: Interval Math
body: <h3>Intro</h3>
  
  <p>We have been working on a recent project and have been looking for a suitable system to calculate some values. SymPy was recommended as being a rich mathematical library. However, we have been unable to make it "work" with our project.</p>
  
  <p>The issue we have been struggling with specifically is that many of the values we would be using have been rounded numerous times and are likely susceptible to float errors. To work around this on a previous project, we used <a href="https://www.npmjs.com/package/interval-arithmetic" rel="nofollow noreferrer">Interval Arithmetic</a> for JavaScript to fairly effective use. mpmath for Python appears to be similar, but SymPy not only uses mpmath, but also offers other potentially useful functions we may need in the future.</p>
  
  <h3>Problem</h3>
  
  <p>A sample equation that we have been working on lately is <code>a = b * (1 + c * d * e)</code> and we are looking to solve for <code>e</code> when all other variables are known. However, some of the variables need to be represented as a range of values as we don't know the exact value, but a small range.</p>
  
  <h3>Code</h3>
  
  <pre class="lang-py prettyprint-override"><code>from sympy import *
  from sympy.sets.setexpr import SetExpr
  
  a, b, c, d, e = symbols('a b c d e')
  
  b = 40
  c = 1
  d = 0.1
  a = SetExpr(Interval(45.995, 46.005))
  equ = Eq(b * (1 + c * d * e), a)
  solveset(equ, e)
  </code></pre>
  
  <pre><code>ValueError: The argument '45.995*I' is not comparable.
  </code></pre>
  
  <p>This was just the latest attempt, but I have tried setting domains, setting inequalities for symbols, using <code>AccumBounds</code>, and numerous other solutions but I can't help but think that we have completely overlooked something simple. </p>
  
  <hr>
  
  <h3>Solution</h3>
  
  <p>It appears that that using one interval is doable with the code provided by the selected answer, but it doesn't extend to multiple symbols requiring intervals or ranges of values. It appears we will be extending the <a href="http://mpmath.org/" rel="nofollow noreferrer">mpmath</a> library to support additional interval functions.</p>