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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r245165 = x;
        double r245166 = 1.0;
        double r245167 = y;
        double r245168 = r245166 - r245167;
        double r245169 = z;
        double r245170 = exp(r245169);
        double r245171 = r245167 * r245170;
        double r245172 = r245168 + r245171;
        double r245173 = log(r245172);
        double r245174 = t;
        double r245175 = r245173 / r245174;
        double r245176 = r245165 - r245175;
        return r245176;
}

double f(double x, double y, double z, double t) {
        double r245177 = z;
        double r245178 = -3.93535345747879e-11;
        bool r245179 = r245177 <= r245178;
        double r245180 = x;
        double r245181 = 2.0;
        double r245182 = 0.3333333333333333;
        double r245183 = y;
        double r245184 = expm1(r245177);
        double r245185 = 1.0;
        double r245186 = fma(r245183, r245184, r245185);
        double r245187 = log(r245186);
        double r245188 = r245182 * r245187;
        double r245189 = r245181 * r245188;
        double r245190 = sqrt(r245186);
        double r245191 = cbrt(r245190);
        double r245192 = log(r245191);
        double r245193 = sqrt(r245190);
        double r245194 = cbrt(r245193);
        double r245195 = log(r245194);
        double r245196 = r245195 + r245195;
        double r245197 = r245192 + r245196;
        double r245198 = r245189 + r245197;
        double r245199 = t;
        double r245200 = r245198 / r245199;
        double r245201 = r245180 - r245200;
        double r245202 = 0.5;
        double r245203 = r245202 * r245177;
        double r245204 = r245203 + r245185;
        double r245205 = r245177 * r245204;
        double r245206 = log(r245185);
        double r245207 = fma(r245183, r245205, r245206);
        double r245208 = r245207 / r245199;
        double r245209 = r245180 - r245208;
        double r245210 = r245179 ? r245201 : r245209;
        return r245210;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.9
Target16.2
Herbie8.5
\[\begin{array}{l} \mathbf{if}\;z \lt -2.88746230882079466 \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 < -3.93535345747879e-11

    1. Initial program 11.5

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

      \[\leadsto \color{blue}{x - \frac{\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)}{t}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt11.5

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

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

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

      \[\leadsto x - \frac{2 \cdot \log \left(\sqrt[3]{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}\right) + \log \left(\sqrt[3]{\color{blue}{\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}\]
    9. Applied cbrt-prod11.5

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

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

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

      \[\leadsto x - \frac{2 \cdot \color{blue}{\left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)\right)} + \left(\log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}}\right) + \log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}}\right)\right)}{t}\]
    14. Using strategy rm
    15. Applied add-sqr-sqrt11.5

      \[\leadsto x - \frac{2 \cdot \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)\right) + \left(\log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}}\right) + \log \left(\sqrt[3]{\sqrt{\color{blue}{\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)\right)}{t}\]
    16. Applied sqrt-prod11.5

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

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

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

    if -3.93535345747879e-11 < z

    1. Initial program 30.9

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

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

      \[\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}\]
    4. Simplified7.2

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

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

Reproduce

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