Average Error: 18.1 → 0.1
Time: 1.5m
Precision: 64
Internal Precision: 1408
\[1.0 - \log \left(1.0 - \frac{x - y}{1.0 - y}\right)\]
\[\begin{array}{l} \mathbf{if}\;y \le -159550078.41948086:\\ \;\;\;\;1.0 - \log \left(\frac{x \cdot 1.0}{y \cdot y} + \left(\frac{x}{y} - \frac{1.0}{y}\right)\right)\\ \mathbf{if}\;y \le 5654171.140492215:\\ \;\;\;\;1.0 - \log \left(\sqrt{1.0 - \frac{x - y}{1.0 - y}} \cdot \sqrt{1.0 - \frac{x - y}{1.0 - y}}\right)\\ \mathbf{else}:\\ \;\;\;\;1.0 - \log \left(\frac{x \cdot 1.0}{y \cdot y} + \left(\frac{x}{y} - \frac{1.0}{y}\right)\right)\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Target

Original18.1
Target0.1
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;y \lt -81284752.61947241:\\ \;\;\;\;1.0 - \log \left(\frac{x}{y \cdot y} - \left(\frac{1.0}{y} - \frac{x}{y}\right)\right)\\ \mathbf{if}\;y \lt 3.0094271212461764 \cdot 10^{+25}:\\ \;\;\;\;\log \left(\frac{e^{1.0}}{1.0 - \frac{x - y}{1.0 - y}}\right)\\ \mathbf{else}:\\ \;\;\;\;1.0 - \log \left(\frac{x}{y \cdot y} - \left(\frac{1.0}{y} - \frac{x}{y}\right)\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if y < -159550078.41948086 or 5654171.140492215 < y

    1. Initial program 45.5

      \[1.0 - \log \left(1.0 - \frac{x - y}{1.0 - y}\right)\]
    2. Taylor expanded around inf 0.0

      \[\leadsto 1.0 - \log \color{blue}{\left(\left(1.0 \cdot \frac{x}{{y}^{2}} + \frac{x}{y}\right) - 1.0 \cdot \frac{1}{y}\right)}\]
    3. Applied simplify0.0

      \[\leadsto \color{blue}{1.0 - \log \left(\frac{x \cdot 1.0}{y \cdot y} + \left(\frac{x}{y} - \frac{1.0}{y}\right)\right)}\]

    if -159550078.41948086 < y < 5654171.140492215

    1. Initial program 0.1

      \[1.0 - \log \left(1.0 - \frac{x - y}{1.0 - y}\right)\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.1

      \[\leadsto 1.0 - \log \color{blue}{\left(\sqrt{1.0 - \frac{x - y}{1.0 - y}} \cdot \sqrt{1.0 - \frac{x - y}{1.0 - y}}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Removed slow pow expressions.

Runtime

Time bar (total: 1.5m)Debug log

herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit +o reduce:binary-search
(FPCore (x y)
  :name "Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, B"

  :herbie-target
  (if (< y -81284752.61947241) (- 1.0 (log (- (/ x (* y y)) (- (/ 1.0 y) (/ x y))))) (if (< y 3.0094271212461764e+25) (log (/ (exp 1.0) (- 1.0 (/ (- x y) (- 1.0 y))))) (- 1.0 (log (- (/ x (* y y)) (- (/ 1.0 y) (/ x y)))))))

  (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))