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}\]
Target
| Original | 18.1 |
|---|
| Target | 0.1 |
|---|
| Herbie | 0.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
- Split input into 2 regimes
if y < -159550078.41948086 or 5654171.140492215 < y
Initial program 45.5
\[1.0 - \log \left(1.0 - \frac{x - y}{1.0 - y}\right)\]
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)}\]
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
Initial program 0.1
\[1.0 - \log \left(1.0 - \frac{x - y}{1.0 - y}\right)\]
- Using strategy
rm 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)}\]
- Recombined 2 regimes into one program.
- Removed slow
pow expressions.
Runtime
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))))))