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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r247769 = x;
        double r247770 = 1.0;
        double r247771 = y;
        double r247772 = r247770 - r247771;
        double r247773 = z;
        double r247774 = exp(r247773);
        double r247775 = r247771 * r247774;
        double r247776 = r247772 + r247775;
        double r247777 = log(r247776);
        double r247778 = t;
        double r247779 = r247777 / r247778;
        double r247780 = r247769 - r247779;
        return r247780;
}

double f(double x, double y, double z, double t) {
        double r247781 = z;
        double r247782 = -2.3881342686465996e-79;
        bool r247783 = r247781 <= r247782;
        double r247784 = x;
        double r247785 = 1.0;
        double r247786 = y;
        double r247787 = expm1(r247781);
        double r247788 = r247786 * r247787;
        double r247789 = r247785 + r247788;
        double r247790 = log(r247789);
        double r247791 = log(r247790);
        double r247792 = exp(r247791);
        double r247793 = sqrt(r247792);
        double r247794 = t;
        double r247795 = cbrt(r247794);
        double r247796 = r247795 * r247795;
        double r247797 = r247793 / r247796;
        double r247798 = sqrt(r247790);
        double r247799 = r247795 / r247798;
        double r247800 = r247797 / r247799;
        double r247801 = r247784 - r247800;
        double r247802 = 0.5;
        double r247803 = 2.0;
        double r247804 = pow(r247781, r247803);
        double r247805 = r247804 * r247786;
        double r247806 = r247781 * r247786;
        double r247807 = log(r247785);
        double r247808 = fma(r247785, r247806, r247807);
        double r247809 = fma(r247802, r247805, r247808);
        double r247810 = r247809 / r247794;
        double r247811 = r247784 - r247810;
        double r247812 = r247783 ? r247801 : r247811;
        return r247812;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.7
Target16.3
Herbie8.9
\[\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 < -2.3881342686465996e-79

    1. Initial program 14.9

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

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

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

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

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

      \[\leadsto x - \frac{1}{\frac{t}{\color{blue}{\sqrt{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)} \cdot \sqrt{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}}}\]
    10. Applied add-cube-cbrt12.6

      \[\leadsto x - \frac{1}{\frac{\color{blue}{\left(\sqrt[3]{t} \cdot \sqrt[3]{t}\right) \cdot \sqrt[3]{t}}}{\sqrt{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)} \cdot \sqrt{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}}\]
    11. Applied times-frac12.6

      \[\leadsto x - \frac{1}{\color{blue}{\frac{\sqrt[3]{t} \cdot \sqrt[3]{t}}{\sqrt{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}} \cdot \frac{\sqrt[3]{t}}{\sqrt{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}}}\]
    12. Applied associate-/r*12.6

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

      \[\leadsto x - \frac{\color{blue}{\frac{\sqrt{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}{\sqrt[3]{t} \cdot \sqrt[3]{t}}}}{\frac{\sqrt[3]{t}}{\sqrt{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}}\]
    14. Using strategy rm
    15. Applied add-exp-log12.6

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

    if -2.3881342686465996e-79 < z

    1. Initial program 30.9

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Taylor expanded around 0 6.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}\]
    3. Simplified6.5

      \[\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}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification8.9

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

Reproduce

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