Average Error: 25.3 → 8.9
Time: 21.5s
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.0:\\ \;\;\;\;x - \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(y, \mathsf{fma}\left(0.5 \cdot z, 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}\;e^{z} \le 0.0:\\
\;\;\;\;x - \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r239867 = x;
        double r239868 = 1.0;
        double r239869 = y;
        double r239870 = r239868 - r239869;
        double r239871 = z;
        double r239872 = exp(r239871);
        double r239873 = r239869 * r239872;
        double r239874 = r239870 + r239873;
        double r239875 = log(r239874);
        double r239876 = t;
        double r239877 = r239875 / r239876;
        double r239878 = r239867 - r239877;
        return r239878;
}

double f(double x, double y, double z, double t) {
        double r239879 = z;
        double r239880 = exp(r239879);
        double r239881 = 0.0;
        bool r239882 = r239880 <= r239881;
        double r239883 = x;
        double r239884 = expm1(r239879);
        double r239885 = y;
        double r239886 = 1.0;
        double r239887 = fma(r239884, r239885, r239886);
        double r239888 = log(r239887);
        double r239889 = 1.0;
        double r239890 = t;
        double r239891 = r239889 / r239890;
        double r239892 = r239888 * r239891;
        double r239893 = r239883 - r239892;
        double r239894 = 0.5;
        double r239895 = r239894 * r239879;
        double r239896 = r239886 * r239879;
        double r239897 = fma(r239895, r239879, r239896);
        double r239898 = log(r239886);
        double r239899 = fma(r239885, r239897, r239898);
        double r239900 = r239899 / r239890;
        double r239901 = r239883 - r239900;
        double r239902 = r239882 ? r239893 : r239901;
        return r239902;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.3
Target16.5
Herbie8.9
\[\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.0

    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(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}}\]
    3. Using strategy rm
    4. Applied div-inv12.1

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

    if 0.0 < (exp z)

    1. Initial program 30.8

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

      \[\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 add-cbrt-cube11.7

      \[\leadsto x - \frac{\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)}}}{t}\]
    5. Simplified11.7

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

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

      \[\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 simplification8.9

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

Reproduce

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