Average Error: 25.0 → 9.0
Time: 29.6s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -5.701067561750732141737610406634812570077 \cdot 10^{-215}:\\ \;\;\;\;x - \frac{\log \left(\sqrt{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}\right) + \frac{1}{2} \cdot \log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(y, \mathsf{fma}\left(z \cdot 0.5, z, 1 \cdot z\right), \log 1\right)}{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.701067561750732141737610406634812570077 \cdot 10^{-215}:\\
\;\;\;\;x - \frac{\log \left(\sqrt{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}\right) + \frac{1}{2} \cdot \log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r12675296 = x;
        double r12675297 = 1.0;
        double r12675298 = y;
        double r12675299 = r12675297 - r12675298;
        double r12675300 = z;
        double r12675301 = exp(r12675300);
        double r12675302 = r12675298 * r12675301;
        double r12675303 = r12675299 + r12675302;
        double r12675304 = log(r12675303);
        double r12675305 = t;
        double r12675306 = r12675304 / r12675305;
        double r12675307 = r12675296 - r12675306;
        return r12675307;
}

double f(double x, double y, double z, double t) {
        double r12675308 = z;
        double r12675309 = -5.701067561750732e-215;
        bool r12675310 = r12675308 <= r12675309;
        double r12675311 = x;
        double r12675312 = y;
        double r12675313 = expm1(r12675308);
        double r12675314 = 1.0;
        double r12675315 = fma(r12675312, r12675313, r12675314);
        double r12675316 = sqrt(r12675315);
        double r12675317 = log(r12675316);
        double r12675318 = 0.5;
        double r12675319 = log(r12675315);
        double r12675320 = r12675318 * r12675319;
        double r12675321 = r12675317 + r12675320;
        double r12675322 = t;
        double r12675323 = r12675321 / r12675322;
        double r12675324 = r12675311 - r12675323;
        double r12675325 = 0.5;
        double r12675326 = r12675308 * r12675325;
        double r12675327 = r12675314 * r12675308;
        double r12675328 = fma(r12675326, r12675308, r12675327);
        double r12675329 = log(r12675314);
        double r12675330 = fma(r12675312, r12675328, r12675329);
        double r12675331 = r12675330 / r12675322;
        double r12675332 = r12675311 - r12675331;
        double r12675333 = r12675310 ? r12675324 : r12675332;
        return r12675333;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.0
Target15.7
Herbie9.0
\[\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 < -5.701067561750732e-215

    1. Initial program 19.3

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Using strategy rm
    3. Applied sub-neg19.3

      \[\leadsto x - \frac{\log \left(\color{blue}{\left(1 + \left(-y\right)\right)} + y \cdot e^{z}\right)}{t}\]
    4. Applied associate-+l+13.5

      \[\leadsto x - \frac{\log \color{blue}{\left(1 + \left(\left(-y\right) + y \cdot e^{z}\right)\right)}}{t}\]
    5. Simplified13.5

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{\left(e^{z} \cdot y - y\right)}\right)}{t}\]
    6. Using strategy rm
    7. Applied add-log-exp13.5

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

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

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

      \[\leadsto x - \frac{\color{blue}{\log \left(\sqrt{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}\right)}}{t}\]
    12. Using strategy rm
    13. Applied pow1/211.1

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

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

    if -5.701067561750732e-215 < z

    1. Initial program 31.2

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Using strategy rm
    3. Applied sub-neg31.2

      \[\leadsto x - \frac{\log \left(\color{blue}{\left(1 + \left(-y\right)\right)} + y \cdot e^{z}\right)}{t}\]
    4. Applied associate-+l+15.2

      \[\leadsto x - \frac{\log \color{blue}{\left(1 + \left(\left(-y\right) + y \cdot e^{z}\right)\right)}}{t}\]
    5. Simplified15.2

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{\left(e^{z} \cdot y - y\right)}\right)}{t}\]
    6. Taylor expanded around 0 6.8

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

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

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

Reproduce

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

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

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