From 5970c77cb98ddbe6a442a2d2b4fe9e16012e9433 Mon Sep 17 00:00:00 2001 From: Marcell Vazquez-Chanlatte Date: Sun, 9 Oct 2016 23:47:55 -0700 Subject: [PATCH] lazily compute early termination boundary conditions --- synth.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/synth.py b/synth.py index 5ad0804..fa0dad1 100644 --- a/synth.py +++ b/synth.py @@ -5,14 +5,10 @@ from lenses import lens def binsearch(stleval, *, tol=1e-3, lo, hi, polarity): """Only run search if tightest robustness was positive.""" - # Only check low since hi taken care of by precondition. - # TODO: allow for different polarities - rL, rH = stleval(lo), stleval(hi) # Early termination via bounds checks - posL, posH = rL > 0, rH > 0 - if polarity and posL: + if polarity and stleval(lo) > 0: return lo - elif not polarity and posH: + elif not polarity and stleval(hi) > 0: return hi while hi - lo > tol: