Average Error: 25.6 → 8.4
Time: 11.4s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -4.41248982228196080047607816779617544214 \cdot 10^{-82}:\\ \;\;\;\;x - \frac{\log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\\ \mathbf{elif}\;z \le 1.552415002017130815259544856599366962842 \cdot 10^{-104}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(1 + \mathsf{fma}\left(\frac{1}{6}, {z}^{3} \cdot y, \mathsf{fma}\left(z, y, \frac{1}{2} \cdot \left({z}^{2} \cdot y\right)\right)\right)\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 -4.41248982228196080047607816779617544214 \cdot 10^{-82}:\\
\;\;\;\;x - \frac{\log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r265869 = x;
        double r265870 = 1.0;
        double r265871 = y;
        double r265872 = r265870 - r265871;
        double r265873 = z;
        double r265874 = exp(r265873);
        double r265875 = r265871 * r265874;
        double r265876 = r265872 + r265875;
        double r265877 = log(r265876);
        double r265878 = t;
        double r265879 = r265877 / r265878;
        double r265880 = r265869 - r265879;
        return r265880;
}

double f(double x, double y, double z, double t) {
        double r265881 = z;
        double r265882 = -4.412489822281961e-82;
        bool r265883 = r265881 <= r265882;
        double r265884 = x;
        double r265885 = 1.0;
        double r265886 = y;
        double r265887 = expm1(r265881);
        double r265888 = r265886 * r265887;
        double r265889 = r265885 + r265888;
        double r265890 = sqrt(r265889);
        double r265891 = log(r265890);
        double r265892 = r265891 + r265891;
        double r265893 = t;
        double r265894 = r265892 / r265893;
        double r265895 = r265884 - r265894;
        double r265896 = 1.5524150020171308e-104;
        bool r265897 = r265881 <= r265896;
        double r265898 = 0.5;
        double r265899 = 2.0;
        double r265900 = pow(r265881, r265899);
        double r265901 = r265900 * r265886;
        double r265902 = r265881 * r265886;
        double r265903 = log(r265885);
        double r265904 = fma(r265885, r265902, r265903);
        double r265905 = fma(r265898, r265901, r265904);
        double r265906 = r265905 / r265893;
        double r265907 = r265884 - r265906;
        double r265908 = 0.16666666666666666;
        double r265909 = 3.0;
        double r265910 = pow(r265881, r265909);
        double r265911 = r265910 * r265886;
        double r265912 = 0.5;
        double r265913 = r265912 * r265901;
        double r265914 = fma(r265881, r265886, r265913);
        double r265915 = fma(r265908, r265911, r265914);
        double r265916 = r265885 + r265915;
        double r265917 = log(r265916);
        double r265918 = r265917 / r265893;
        double r265919 = r265884 - r265918;
        double r265920 = r265897 ? r265907 : r265919;
        double r265921 = r265883 ? r265895 : r265920;
        return r265921;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.6
Target16.0
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 3 regimes
  2. if z < -4.412489822281961e-82

    1. Initial program 16.2

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

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

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

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt12.0

      \[\leadsto x - \frac{\log \color{blue}{\left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)} \cdot \sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}}{t}\]
    8. Applied log-prod12.0

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

    if -4.412489822281961e-82 < z < 1.5524150020171308e-104

    1. Initial program 31.0

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Taylor expanded around 0 5.0

      \[\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}\]
    3. Simplified5.0

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

    if 1.5524150020171308e-104 < z

    1. Initial program 31.6

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

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

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

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

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

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

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

Reproduce

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