Average Error: 25.4 → 8.8
Time: 24.4s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -0.3115017031960372051457852649036794900894:\\ \;\;\;\;x - \sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)} \cdot \frac{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{1}{\frac{t}{\mathsf{fma}\left(y, \mathsf{fma}\left(0.5, {z}^{2}, 1 \cdot z\right), \log 1\right)}}\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -0.3115017031960372051457852649036794900894:\\
\;\;\;\;x - \sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)} \cdot \frac{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r231967 = x;
        double r231968 = 1.0;
        double r231969 = y;
        double r231970 = r231968 - r231969;
        double r231971 = z;
        double r231972 = exp(r231971);
        double r231973 = r231969 * r231972;
        double r231974 = r231970 + r231973;
        double r231975 = log(r231974);
        double r231976 = t;
        double r231977 = r231975 / r231976;
        double r231978 = r231967 - r231977;
        return r231978;
}

double f(double x, double y, double z, double t) {
        double r231979 = z;
        double r231980 = -0.3115017031960372;
        bool r231981 = r231979 <= r231980;
        double r231982 = x;
        double r231983 = expm1(r231979);
        double r231984 = y;
        double r231985 = 1.0;
        double r231986 = fma(r231983, r231984, r231985);
        double r231987 = log(r231986);
        double r231988 = sqrt(r231987);
        double r231989 = t;
        double r231990 = r231988 / r231989;
        double r231991 = r231988 * r231990;
        double r231992 = r231982 - r231991;
        double r231993 = 1.0;
        double r231994 = 0.5;
        double r231995 = 2.0;
        double r231996 = pow(r231979, r231995);
        double r231997 = r231985 * r231979;
        double r231998 = fma(r231994, r231996, r231997);
        double r231999 = log(r231985);
        double r232000 = fma(r231984, r231998, r231999);
        double r232001 = r231989 / r232000;
        double r232002 = r231993 / r232001;
        double r232003 = r231982 - r232002;
        double r232004 = r231981 ? r231992 : r232003;
        return r232004;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.4
Target16.5
Herbie8.8
\[\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 < -0.3115017031960372

    1. Initial program 10.9

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

      \[\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 *-un-lft-identity10.9

      \[\leadsto x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{\color{blue}{1 \cdot t}}\]
    5. Applied add-sqr-sqrt11.8

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

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

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

    if -0.3115017031960372 < z

    1. Initial program 31.3

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

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

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

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

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

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

Reproduce

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