Average Error: 25.2 → 8.8
Time: 13.1s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -5.2073484199518872 \cdot 10^{-38} \lor \neg \left(z \le 1.8330086343134758 \cdot 10^{-124} \lor \neg \left(z \le 3.2223812747103702 \cdot 10^{-17}\right)\right):\\ \;\;\;\;x - \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right) \cdot \frac{1}{t}\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -5.2073484199518872 \cdot 10^{-38} \lor \neg \left(z \le 1.8330086343134758 \cdot 10^{-124} \lor \neg \left(z \le 3.2223812747103702 \cdot 10^{-17}\right)\right):\\
\;\;\;\;x - \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r352294 = x;
        double r352295 = 1.0;
        double r352296 = y;
        double r352297 = r352295 - r352296;
        double r352298 = z;
        double r352299 = exp(r352298);
        double r352300 = r352296 * r352299;
        double r352301 = r352297 + r352300;
        double r352302 = log(r352301);
        double r352303 = t;
        double r352304 = r352302 / r352303;
        double r352305 = r352294 - r352304;
        return r352305;
}

double f(double x, double y, double z, double t) {
        double r352306 = z;
        double r352307 = -5.207348419951887e-38;
        bool r352308 = r352306 <= r352307;
        double r352309 = 1.8330086343134758e-124;
        bool r352310 = r352306 <= r352309;
        double r352311 = 3.22238127471037e-17;
        bool r352312 = r352306 <= r352311;
        double r352313 = !r352312;
        bool r352314 = r352310 || r352313;
        double r352315 = !r352314;
        bool r352316 = r352308 || r352315;
        double r352317 = x;
        double r352318 = expm1(r352306);
        double r352319 = y;
        double r352320 = 1.0;
        double r352321 = fma(r352318, r352319, r352320);
        double r352322 = log(r352321);
        double r352323 = 1.0;
        double r352324 = t;
        double r352325 = r352323 / r352324;
        double r352326 = r352322 * r352325;
        double r352327 = r352317 - r352326;
        double r352328 = 0.5;
        double r352329 = 2.0;
        double r352330 = pow(r352306, r352329);
        double r352331 = r352330 * r352319;
        double r352332 = r352306 * r352319;
        double r352333 = log(r352320);
        double r352334 = fma(r352320, r352332, r352333);
        double r352335 = fma(r352328, r352331, r352334);
        double r352336 = r352335 * r352325;
        double r352337 = r352317 - r352336;
        double r352338 = r352316 ? r352327 : r352337;
        return r352338;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.2
Target16.2
Herbie8.8
\[\begin{array}{l} \mathbf{if}\;z \lt -2.88746230882079466 \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 < -5.207348419951887e-38 or 1.8330086343134758e-124 < z < 3.22238127471037e-17

    1. Initial program 18.0

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

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

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

    if -5.207348419951887e-38 < z < 1.8330086343134758e-124 or 3.22238127471037e-17 < z

    1. Initial program 31.1

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified11.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 div-inv11.2

      \[\leadsto x - \color{blue}{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}}\]
    5. Using strategy rm
    6. Applied add-cbrt-cube11.3

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -5.2073484199518872 \cdot 10^{-38} \lor \neg \left(z \le 1.8330086343134758 \cdot 10^{-124} \lor \neg \left(z \le 3.2223812747103702 \cdot 10^{-17}\right)\right):\\ \;\;\;\;x - \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right) \cdot \frac{1}{t}\\ \end{array}\]

Reproduce

herbie shell --seed 2020042 +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)))