title: java how to determine logical expression minimum values to evauate
body: <p>I have an expression (an example)</p>
  
  <pre><code>(value1&lt;15 AND value2&gt;25) OR ((value3&gt;0 and vaue4&lt;5) OR (value5&lt;6 and value7&gt;8))
  </code></pre>
  
  <p>The issue is value1-7 are calls to external services, which are expensive. And we need to reduce cost, so we need to make a minimum number of calls to evaluate this expression. For example if we have </p>
  
  <pre><code>(value1&lt;15 AND value2&gt;25)
  </code></pre>
  
  <p>evaluated to true, we don't need to evaluate right part, so we don't need to make useless calls to external services. How to determine in java (or may be just in math) when we need to stop, and further evaluations will not make any effect?</p>
  
  <h2>UPDATE</h2>
  
  <p>I have 5 workers that works on 5 different servers. </p>
  
  <p>first worker:</p>
  
  <pre><code>    accept(expression)
      value1=calculateValue1()
      setValueToExpression(expression, 0, value1)
      enough=expression.checkIsItEnough()
      if(!enough){
        determineNextWorker(expression)
        sendToNExtWorker()
      }
      else return expression.evaluate()
  </code></pre>
  
  <p>The second worker</p>
  
  <pre><code>    accept(expression)
      value2=calculateValue2()
      setValueToExpression(expression, 1, value2)
      enough=expression.checkIsItEnough()
      if(!enough){
       determineNextWorker(expression)
       sendToNextWorker()
      }
      else return expression.evaluate()
  </code></pre>
  
  <p>.....................</p>
  
  <p>As I said in comments, I clearly understand that if we can write</p>
  
  <pre><code> evaluator.evaluate("(value1&lt;5 and value2&gt;6) or (value3&gt;5 and value4&gt;7)")
  </code></pre>
  
  <p>it evaluates it as all of us know, but I don't have this ability due to many reasons. I also can't make it function calls value1()&lt;15...
  It's happening synchronously, one by one but even on different servers, kinda offline evaluation. Hope it's clear</p>