Average Error: 25.4 → 8.8
Time: 9.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.01243893441116220889564036866659080260433:\\ \;\;\;\;x - \frac{1}{\frac{t}{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}}\\ \mathbf{elif}\;z \le 4.549364555403628313368183381315866295653 \cdot 10^{-95}:\\ \;\;\;\;x - \left(\sqrt[3]{\frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}}\right) \cdot \sqrt[3]{\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(\mathsf{fma}\left(\frac{1}{2}, {z}^{2} \cdot y, \mathsf{fma}\left(z, y, 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 -0.01243893441116220889564036866659080260433:\\
\;\;\;\;x - \frac{1}{\frac{t}{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}}\\

\mathbf{elif}\;z \le 4.549364555403628313368183381315866295653 \cdot 10^{-95}:\\
\;\;\;\;x - \left(\sqrt[3]{\frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}}\right) \cdot \sqrt[3]{\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(\mathsf{fma}\left(\frac{1}{2}, {z}^{2} \cdot y, \mathsf{fma}\left(z, y, 1\right)\right)\right)}{t}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r263723 = x;
        double r263724 = 1.0;
        double r263725 = y;
        double r263726 = r263724 - r263725;
        double r263727 = z;
        double r263728 = exp(r263727);
        double r263729 = r263725 * r263728;
        double r263730 = r263726 + r263729;
        double r263731 = log(r263730);
        double r263732 = t;
        double r263733 = r263731 / r263732;
        double r263734 = r263723 - r263733;
        return r263734;
}

double f(double x, double y, double z, double t) {
        double r263735 = z;
        double r263736 = -0.012438934411162209;
        bool r263737 = r263735 <= r263736;
        double r263738 = x;
        double r263739 = 1.0;
        double r263740 = t;
        double r263741 = 1.0;
        double r263742 = y;
        double r263743 = r263741 - r263742;
        double r263744 = exp(r263735);
        double r263745 = r263742 * r263744;
        double r263746 = r263743 + r263745;
        double r263747 = log(r263746);
        double r263748 = r263740 / r263747;
        double r263749 = r263739 / r263748;
        double r263750 = r263738 - r263749;
        double r263751 = 4.549364555403628e-95;
        bool r263752 = r263735 <= r263751;
        double r263753 = 0.5;
        double r263754 = 2.0;
        double r263755 = pow(r263735, r263754);
        double r263756 = r263755 * r263742;
        double r263757 = r263735 * r263742;
        double r263758 = log(r263741);
        double r263759 = fma(r263741, r263757, r263758);
        double r263760 = fma(r263753, r263756, r263759);
        double r263761 = r263760 / r263740;
        double r263762 = cbrt(r263761);
        double r263763 = r263762 * r263762;
        double r263764 = r263763 * r263762;
        double r263765 = r263738 - r263764;
        double r263766 = 0.5;
        double r263767 = fma(r263735, r263742, r263741);
        double r263768 = fma(r263766, r263756, r263767);
        double r263769 = log(r263768);
        double r263770 = r263769 / r263740;
        double r263771 = r263738 - r263770;
        double r263772 = r263752 ? r263765 : r263771;
        double r263773 = r263737 ? r263750 : r263772;
        return r263773;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.4
Target16.4
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 3 regimes
  2. if z < -0.012438934411162209

    1. Initial program 12.3

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

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

    if -0.012438934411162209 < z < 4.549364555403628e-95

    1. Initial program 31.6

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

      \[\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}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt6.4

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

    if 4.549364555403628e-95 < z

    1. Initial program 28.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -0.01243893441116220889564036866659080260433:\\ \;\;\;\;x - \frac{1}{\frac{t}{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}}\\ \mathbf{elif}\;z \le 4.549364555403628313368183381315866295653 \cdot 10^{-95}:\\ \;\;\;\;x - \left(\sqrt[3]{\frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}}\right) \cdot \sqrt[3]{\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(\mathsf{fma}\left(\frac{1}{2}, {z}^{2} \cdot y, \mathsf{fma}\left(z, y, 1\right)\right)\right)}{t}\\ \end{array}\]

Reproduce

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