Average Error: 24.6 → 8.4
Time: 21.0s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -6.310119903545574434291526250400899439411 \cdot 10^{-134}:\\ \;\;\;\;x + \left(-\frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(-\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)\right)\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -6.310119903545574434291526250400899439411 \cdot 10^{-134}:\\
\;\;\;\;x + \left(-\frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}\right)\\

\mathbf{else}:\\
\;\;\;\;x + \left(-\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)\right)\\

\end{array}
double f(double x, double y, double z, double t) {
        double r207133 = x;
        double r207134 = 1.0;
        double r207135 = y;
        double r207136 = r207134 - r207135;
        double r207137 = z;
        double r207138 = exp(r207137);
        double r207139 = r207135 * r207138;
        double r207140 = r207136 + r207139;
        double r207141 = log(r207140);
        double r207142 = t;
        double r207143 = r207141 / r207142;
        double r207144 = r207133 - r207143;
        return r207144;
}

double f(double x, double y, double z, double t) {
        double r207145 = z;
        double r207146 = -6.310119903545574e-134;
        bool r207147 = r207145 <= r207146;
        double r207148 = x;
        double r207149 = expm1(r207145);
        double r207150 = y;
        double r207151 = 1.0;
        double r207152 = fma(r207149, r207150, r207151);
        double r207153 = log(r207152);
        double r207154 = t;
        double r207155 = r207153 / r207154;
        double r207156 = -r207155;
        double r207157 = r207148 + r207156;
        double r207158 = r207145 * r207150;
        double r207159 = r207158 / r207154;
        double r207160 = 0.5;
        double r207161 = 2.0;
        double r207162 = pow(r207145, r207161);
        double r207163 = r207162 * r207150;
        double r207164 = r207163 / r207154;
        double r207165 = log(r207151);
        double r207166 = r207165 / r207154;
        double r207167 = fma(r207160, r207164, r207166);
        double r207168 = fma(r207151, r207159, r207167);
        double r207169 = -r207168;
        double r207170 = r207148 + r207169;
        double r207171 = r207147 ? r207157 : r207170;
        return r207171;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.6
Target16.1
Herbie8.4
\[\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 < -6.310119903545574e-134

    1. Initial program 16.9

      \[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. Using strategy rm
    4. Applied div-inv11.6

      \[\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 sub-neg11.6

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

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

    if -6.310119903545574e-134 < z

    1. Initial program 30.4

      \[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 sub-neg11.2

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

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

      \[\leadsto x + \left(-\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)}\right)\]
    9. Simplified6.0

      \[\leadsto x + \left(-\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)}\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification8.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -6.310119903545574434291526250400899439411 \cdot 10^{-134}:\\ \;\;\;\;x + \left(-\frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(-\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)\right)\\ \end{array}\]

Reproduce

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