Average Error: 25.9 → 7.9
Time: 1.0m
Precision: 64
Internal Precision: 1408
\[1.0 - \log \left(1.0 - \frac{x - y}{1.0 - y}\right)\]
\[\begin{array}{l} \mathbf{if}\;\frac{x - y}{1.0 - y} \le 0.9996997279733931:\\ \;\;\;\;\log \left(\frac{e^{1.0}}{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

Original25.9
Target10.8
Herbie7.9
\[\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 (/ (- x y) (- 1.0 y)) < 0.9996997279733931

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\log \left(e^{1.0 - \log \left(1.0 - \frac{x - y}{1.0 - y}\right)}\right)}\]
    4. Applied simplify0.0

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

    if 0.9996997279733931 < (/ (- x y) (- 1.0 y))

    1. Initial program 61.7

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

      \[\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 simplify18.8

      \[\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)}\]
  3. Recombined 2 regimes into one program.
  4. Removed slow pow expressions.

Runtime

Time bar (total: 1.0m)Debug log

herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit
(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))))))