title: How to get rid of unnecessary parentheses in mathematical expression
body: <p>Hi I was wondering if there is any known way to get rid of unnecessary parentheses in mathematical formula. The reason I am asking this question is that I have to minimize such formula length</p>
  
  <pre><code>if((-if(([V].[6432])=0;0;(([V].[6432])-([V].[6445]))*(((([V].[6443]))/1000*([V].[6448])
  +(([V].[6443]))*([V].[6449])+([V].[6450]))*(1-([V].[6446])))))=0;([V].[6428])*
  ((((([V].[6443]))/1000*([V].[6445])*([V].[6448])+(([V].[6443]))*([V].[6445])*
  ([V].[6449])+([V].[6445])*([V].[6450])))*(1-([V].[6446])));
  </code></pre>
  
  <p>it is basically part of sql select statement. It cannot surpass 255 characters and I cannot modify the code that produces this formula (basically a black box ;) )
  As you see many parentheses are useless. Not mentioning the fact that:</p>
  
  <pre><code>((a) * (b)) + (c) = a * b + c
  </code></pre>
  
  <p>So I want to keep the order of operations Parenthesis, Multiply/Divide, Add/Subtract.</p>
  
  <p>Im working in VB, but solution in any language will be fine.</p>
  
  <h1>Edit</h1>
  
  <p>I found an opposite problem (add parentheses to a expression) <a href="https://stackoverflow.com/questions/548613/how-do-i-parenthesize-an-expression-programmatically">Question</a>. </p>
  
  <p>I  really thought that this could be accomplished without heavy parsing. But it seems that some parser that will go through the expression and save it in a expression tree is unevitable.</p>