Average Error: 26.2 → 10.6
Time: 25.1s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;e^{z} \le 0.9999999836499344763041108308243565261364:\\ \;\;\;\;x - \left(\sqrt[3]{\frac{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}{t}} \cdot \sqrt[3]{\frac{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}{t}}\right) \cdot \sqrt[3]{\frac{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}{t}}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(1, z \cdot \frac{y}{t}, \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \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}\;e^{z} \le 0.9999999836499344763041108308243565261364:\\
\;\;\;\;x - \left(\sqrt[3]{\frac{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}{t}} \cdot \sqrt[3]{\frac{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}{t}}\right) \cdot \sqrt[3]{\frac{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}{t}}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r192584 = x;
        double r192585 = 1.0;
        double r192586 = y;
        double r192587 = r192585 - r192586;
        double r192588 = z;
        double r192589 = exp(r192588);
        double r192590 = r192586 * r192589;
        double r192591 = r192587 + r192590;
        double r192592 = log(r192591);
        double r192593 = t;
        double r192594 = r192592 / r192593;
        double r192595 = r192584 - r192594;
        return r192595;
}

double f(double x, double y, double z, double t) {
        double r192596 = z;
        double r192597 = exp(r192596);
        double r192598 = 0.9999999836499345;
        bool r192599 = r192597 <= r192598;
        double r192600 = x;
        double r192601 = y;
        double r192602 = 1.0;
        double r192603 = r192602 - r192601;
        double r192604 = fma(r192597, r192601, r192603);
        double r192605 = log(r192604);
        double r192606 = t;
        double r192607 = r192605 / r192606;
        double r192608 = cbrt(r192607);
        double r192609 = r192608 * r192608;
        double r192610 = r192609 * r192608;
        double r192611 = r192600 - r192610;
        double r192612 = r192601 / r192606;
        double r192613 = r192596 * r192612;
        double r192614 = 0.5;
        double r192615 = 2.0;
        double r192616 = pow(r192596, r192615);
        double r192617 = r192616 * r192601;
        double r192618 = r192617 / r192606;
        double r192619 = log(r192602);
        double r192620 = r192619 / r192606;
        double r192621 = fma(r192614, r192618, r192620);
        double r192622 = fma(r192602, r192613, r192621);
        double r192623 = r192600 - r192622;
        double r192624 = r192599 ? r192611 : r192623;
        return r192624;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original26.2
Target16.6
Herbie10.6
\[\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 (exp z) < 0.9999999836499345

    1. Initial program 12.1

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

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

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

    if 0.9999999836499345 < (exp z)

    1. Initial program 32.2

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

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

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

      \[\leadsto x - \color{blue}{\mathsf{fma}\left(1, \frac{z \cdot y}{t}, \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity7.8

      \[\leadsto x - \mathsf{fma}\left(1, \frac{z \cdot y}{\color{blue}{1 \cdot t}}, \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)\]
    7. Applied times-frac9.9

      \[\leadsto x - \mathsf{fma}\left(1, \color{blue}{\frac{z}{1} \cdot \frac{y}{t}}, \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)\]
    8. Simplified9.9

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

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

Reproduce

herbie shell --seed 2019235 +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.88746230882079466e119) (- (- 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)))