Average Error: 25.6 → 9.3
Time: 19.7s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.731260742038221807671652239454073553396 \cdot 10^{-171}:\\ \;\;\;\;x - \frac{\left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right) + \left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(1, \frac{z \cdot y}{t}, \mathsf{fma}\left(\frac{{z}^{2} \cdot y}{t}, 0.5, \frac{\log 1}{t}\right)\right)\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -3.731260742038221807671652239454073553396 \cdot 10^{-171}:\\
\;\;\;\;x - \frac{\left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right) + \left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\\

\mathbf{else}:\\
\;\;\;\;x - \mathsf{fma}\left(1, \frac{z \cdot y}{t}, \mathsf{fma}\left(\frac{{z}^{2} \cdot y}{t}, 0.5, \frac{\log 1}{t}\right)\right)\\

\end{array}
double f(double x, double y, double z, double t) {
        double r172278 = x;
        double r172279 = 1.0;
        double r172280 = y;
        double r172281 = r172279 - r172280;
        double r172282 = z;
        double r172283 = exp(r172282);
        double r172284 = r172280 * r172283;
        double r172285 = r172281 + r172284;
        double r172286 = log(r172285);
        double r172287 = t;
        double r172288 = r172286 / r172287;
        double r172289 = r172278 - r172288;
        return r172289;
}

double f(double x, double y, double z, double t) {
        double r172290 = z;
        double r172291 = -3.731260742038222e-171;
        bool r172292 = r172290 <= r172291;
        double r172293 = x;
        double r172294 = expm1(r172290);
        double r172295 = y;
        double r172296 = 1.0;
        double r172297 = fma(r172294, r172295, r172296);
        double r172298 = sqrt(r172297);
        double r172299 = sqrt(r172298);
        double r172300 = log(r172299);
        double r172301 = r172300 + r172300;
        double r172302 = r172301 + r172301;
        double r172303 = t;
        double r172304 = r172302 / r172303;
        double r172305 = r172293 - r172304;
        double r172306 = r172290 * r172295;
        double r172307 = r172306 / r172303;
        double r172308 = 2.0;
        double r172309 = pow(r172290, r172308);
        double r172310 = r172309 * r172295;
        double r172311 = r172310 / r172303;
        double r172312 = 0.5;
        double r172313 = log(r172296);
        double r172314 = r172313 / r172303;
        double r172315 = fma(r172311, r172312, r172314);
        double r172316 = fma(r172296, r172307, r172315);
        double r172317 = r172293 - r172316;
        double r172318 = r172292 ? r172305 : r172317;
        return r172318;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.6
Target16.5
Herbie9.3
\[\begin{array}{l} \mathbf{if}\;z \lt -2.887462308820794658905265984545350618896 \cdot 10^{119}:\\ \;\;\;\;\left(x - \frac{\frac{-0.5}{y \cdot t}}{z \cdot z}\right) - \frac{-0.5}{y \cdot t} \cdot \frac{\frac{2}{z}}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(1 + z \cdot y\right)}{t}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -3.731260742038222e-171

    1. Initial program 19.3

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified12.2

      \[\leadsto \color{blue}{x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt12.2

      \[\leadsto x - \frac{\log \color{blue}{\left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)} \cdot \sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}}{t}\]
    5. Applied log-prod12.2

      \[\leadsto x - \frac{\color{blue}{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}}{t}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt12.2

      \[\leadsto x - \frac{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right) + \log \left(\sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)} \cdot \sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right)}{t}\]
    8. Applied sqrt-prod12.2

      \[\leadsto x - \frac{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right) + \log \color{blue}{\left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)}}{t}\]
    9. Applied log-prod12.2

      \[\leadsto x - \frac{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right) + \color{blue}{\left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}}{t}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrt12.2

      \[\leadsto x - \frac{\log \left(\sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)} \cdot \sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right) + \left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\]
    12. Applied sqrt-prod12.2

      \[\leadsto x - \frac{\log \color{blue}{\left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)} + \left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\]
    13. Applied log-prod12.2

      \[\leadsto x - \frac{\color{blue}{\left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)} + \left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\]

    if -3.731260742038222e-171 < z

    1. Initial program 31.4

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified11.6

      \[\leadsto \color{blue}{x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}}\]
    3. Taylor expanded around 0 6.7

      \[\leadsto x - \color{blue}{\left(1 \cdot \frac{z \cdot y}{t} + \left(\frac{\log 1}{t} + 0.5 \cdot \frac{{z}^{2} \cdot y}{t}\right)\right)}\]
    4. Simplified6.7

      \[\leadsto x - \color{blue}{\mathsf{fma}\left(1, \frac{z \cdot y}{t}, \mathsf{fma}\left(\frac{{z}^{2} \cdot y}{t}, 0.5, \frac{\log 1}{t}\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification9.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.731260742038221807671652239454073553396 \cdot 10^{-171}:\\ \;\;\;\;x - \frac{\left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right) + \left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(1, \frac{z \cdot y}{t}, \mathsf{fma}\left(\frac{{z}^{2} \cdot y}{t}, 0.5, \frac{\log 1}{t}\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019347 +o rules:numerics
(FPCore (x y z t)
  :name "System.Random.MWC.Distributions:truncatedExp from mwc-random-0.13.3.2"
  :precision binary64

  :herbie-target
  (if (< z -2.8874623088207947e+119) (- (- x (/ (/ (- 0.5) (* y t)) (* z z))) (* (/ (- 0.5) (* y t)) (/ (/ 2 z) (* z z)))) (- x (/ (log (+ 1 (* z y))) t)))

  (- x (/ (log (+ (- 1 y) (* y (exp z)))) t)))