Average Error: 25.2 → 8.8
Time: 13.4s
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 r379627 = x;
        double r379628 = 1.0;
        double r379629 = y;
        double r379630 = r379628 - r379629;
        double r379631 = z;
        double r379632 = exp(r379631);
        double r379633 = r379629 * r379632;
        double r379634 = r379630 + r379633;
        double r379635 = log(r379634);
        double r379636 = t;
        double r379637 = r379635 / r379636;
        double r379638 = r379627 - r379637;
        return r379638;
}

double f(double x, double y, double z, double t) {
        double r379639 = z;
        double r379640 = -5.207348419951887e-38;
        bool r379641 = r379639 <= r379640;
        double r379642 = 1.8330086343134758e-124;
        bool r379643 = r379639 <= r379642;
        double r379644 = 3.22238127471037e-17;
        bool r379645 = r379639 <= r379644;
        double r379646 = !r379645;
        bool r379647 = r379643 || r379646;
        double r379648 = !r379647;
        bool r379649 = r379641 || r379648;
        double r379650 = x;
        double r379651 = expm1(r379639);
        double r379652 = y;
        double r379653 = 1.0;
        double r379654 = fma(r379651, r379652, r379653);
        double r379655 = log(r379654);
        double r379656 = 1.0;
        double r379657 = t;
        double r379658 = r379656 / r379657;
        double r379659 = r379655 * r379658;
        double r379660 = r379650 - r379659;
        double r379661 = 0.5;
        double r379662 = 2.0;
        double r379663 = pow(r379639, r379662);
        double r379664 = r379663 * r379652;
        double r379665 = r379639 * r379652;
        double r379666 = log(r379653);
        double r379667 = fma(r379653, r379665, r379666);
        double r379668 = fma(r379661, r379664, r379667);
        double r379669 = r379668 * r379658;
        double r379670 = r379650 - r379669;
        double r379671 = r379649 ? r379660 : r379670;
        return r379671;
}

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)))