title: Newton's method with known bounds on the root
body: <p>I have an equation <code>f(x)=y</code> with the follwing properties:</p>
  <ul>
  <li>we have an explicit expression for the derivative <code>f'</code></li>
  <li>the root is known to be between 0 and 1 (in fact <code>f</code> is defined only in this interval)</li>
  <li><code>f</code> is (weakly) increasing</li>
  </ul>
  <p>I am currently solving this equation with <code>scipy.optimize.brentq</code>, which works well enough.</p>
  <pre class="lang-py prettyprint-override"><code>optimize.brentq(f_to_zero, 0, 1)
  </code></pre>
  <p><code>brentq</code> uses the secant method, a finite-difference equivalent of Newton's method; it does not make use of any explicit <code>f'</code>.</p>
  <p>I was hoping I could make the root finding faster by making use of this derivative. In other words, I want to use Newton's method augmented with bounds; this <a href="https://notes.quantecon.org/submission/5d5eb45c020ad500163051a8" rel="nofollow noreferrer">article</a> suggests the following idea: if at any point the Newton guess falls outside the bounds, perform a bisection (between the current guess and the bound) instead. Is there any well-tested package for this? I would really rather not write my own  implementation (it's probably not worth it for the performance gain).</p>
  <p>Another point is that the function isn't even defined outside the bounds, so using</p>
  <pre class="lang-py prettyprint-override"><code>optimize.newton(f_to_zero, fprime=f_prime, x0=0.5)
  </code></pre>
  <p>is not just inefficient, it will throw an error</p>
  <p>Somebody asked what the expression for <code>f'</code> is. <code>f</code> and <code>f'</code> are very long, so I have made gist here: <a href="https://gist.github.com/d3c48dde09389e8c48da0e990b57bf99" rel="nofollow noreferrer">https://gist.github.com/d3c48dde09389e8c48da0e990b57bf99</a></p>