Average Error: 25.0 → 8.3
Time: 28.0s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.557590633596780287583542096152555700428 \cdot 10^{-6}:\\ \;\;\;\;x - \frac{\log \left(\sqrt[3]{e^{z} \cdot y + \left(1 - y\right)} \cdot \sqrt[3]{e^{z} \cdot y + \left(1 - y\right)}\right) + \log \left(\sqrt[3]{e^{z} \cdot y + \left(1 - y\right)}\right)}{t}\\ \mathbf{elif}\;z \le -9.563892971882941508989059528465610985701 \cdot 10^{-142}:\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(z, y, \mathsf{fma}\left(y \cdot \left(z \cdot z\right), \frac{1}{2}, 1\right)\right)\right)}{t}\\ \mathbf{elif}\;z \le 1.83589965406300168931794931963947709314 \cdot 10^{-159}:\\ \;\;\;\;x - \mathsf{fma}\left(y \cdot \frac{z}{t}, 1, \frac{\log 1}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(z, y, \mathsf{fma}\left(y \cdot \left(z \cdot z\right), \frac{1}{2}, 1\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 -3.557590633596780287583542096152555700428 \cdot 10^{-6}:\\
\;\;\;\;x - \frac{\log \left(\sqrt[3]{e^{z} \cdot y + \left(1 - y\right)} \cdot \sqrt[3]{e^{z} \cdot y + \left(1 - y\right)}\right) + \log \left(\sqrt[3]{e^{z} \cdot y + \left(1 - y\right)}\right)}{t}\\

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

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r12360928 = x;
        double r12360929 = 1.0;
        double r12360930 = y;
        double r12360931 = r12360929 - r12360930;
        double r12360932 = z;
        double r12360933 = exp(r12360932);
        double r12360934 = r12360930 * r12360933;
        double r12360935 = r12360931 + r12360934;
        double r12360936 = log(r12360935);
        double r12360937 = t;
        double r12360938 = r12360936 / r12360937;
        double r12360939 = r12360928 - r12360938;
        return r12360939;
}

double f(double x, double y, double z, double t) {
        double r12360940 = z;
        double r12360941 = -3.5575906335967803e-06;
        bool r12360942 = r12360940 <= r12360941;
        double r12360943 = x;
        double r12360944 = exp(r12360940);
        double r12360945 = y;
        double r12360946 = r12360944 * r12360945;
        double r12360947 = 1.0;
        double r12360948 = r12360947 - r12360945;
        double r12360949 = r12360946 + r12360948;
        double r12360950 = cbrt(r12360949);
        double r12360951 = r12360950 * r12360950;
        double r12360952 = log(r12360951);
        double r12360953 = log(r12360950);
        double r12360954 = r12360952 + r12360953;
        double r12360955 = t;
        double r12360956 = r12360954 / r12360955;
        double r12360957 = r12360943 - r12360956;
        double r12360958 = -9.563892971882942e-142;
        bool r12360959 = r12360940 <= r12360958;
        double r12360960 = r12360940 * r12360940;
        double r12360961 = r12360945 * r12360960;
        double r12360962 = 0.5;
        double r12360963 = fma(r12360961, r12360962, r12360947);
        double r12360964 = fma(r12360940, r12360945, r12360963);
        double r12360965 = log(r12360964);
        double r12360966 = r12360965 / r12360955;
        double r12360967 = r12360943 - r12360966;
        double r12360968 = 1.8358996540630017e-159;
        bool r12360969 = r12360940 <= r12360968;
        double r12360970 = r12360940 / r12360955;
        double r12360971 = r12360945 * r12360970;
        double r12360972 = log(r12360947);
        double r12360973 = r12360972 / r12360955;
        double r12360974 = fma(r12360971, r12360947, r12360973);
        double r12360975 = r12360943 - r12360974;
        double r12360976 = r12360969 ? r12360975 : r12360967;
        double r12360977 = r12360959 ? r12360967 : r12360976;
        double r12360978 = r12360942 ? r12360957 : r12360977;
        return r12360978;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.0
Target16.2
Herbie8.3
\[\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 < -3.5575906335967803e-06

    1. Initial program 11.5

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

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

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

    if -3.5575906335967803e-06 < z < -9.563892971882942e-142 or 1.8358996540630017e-159 < z

    1. Initial program 29.6

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

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

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

    if -9.563892971882942e-142 < z < 1.8358996540630017e-159

    1. Initial program 31.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.557590633596780287583542096152555700428 \cdot 10^{-6}:\\ \;\;\;\;x - \frac{\log \left(\sqrt[3]{e^{z} \cdot y + \left(1 - y\right)} \cdot \sqrt[3]{e^{z} \cdot y + \left(1 - y\right)}\right) + \log \left(\sqrt[3]{e^{z} \cdot y + \left(1 - y\right)}\right)}{t}\\ \mathbf{elif}\;z \le -9.563892971882941508989059528465610985701 \cdot 10^{-142}:\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(z, y, \mathsf{fma}\left(y \cdot \left(z \cdot z\right), \frac{1}{2}, 1\right)\right)\right)}{t}\\ \mathbf{elif}\;z \le 1.83589965406300168931794931963947709314 \cdot 10^{-159}:\\ \;\;\;\;x - \mathsf{fma}\left(y \cdot \frac{z}{t}, 1, \frac{\log 1}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(z, y, \mathsf{fma}\left(y \cdot \left(z \cdot z\right), \frac{1}{2}, 1\right)\right)\right)}{t}\\ \end{array}\]

Reproduce

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