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

\mathbf{else}:\\
\;\;\;\;x - \frac{1}{\frac{t}{2 \cdot \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r248088 = x;
        double r248089 = 1.0;
        double r248090 = y;
        double r248091 = r248089 - r248090;
        double r248092 = z;
        double r248093 = exp(r248092);
        double r248094 = r248090 * r248093;
        double r248095 = r248091 + r248094;
        double r248096 = log(r248095);
        double r248097 = t;
        double r248098 = r248096 / r248097;
        double r248099 = r248088 - r248098;
        return r248099;
}

double f(double x, double y, double z, double t) {
        double r248100 = z;
        double r248101 = -4.6972541441660704e-38;
        bool r248102 = r248100 <= r248101;
        double r248103 = x;
        double r248104 = 1.0;
        double r248105 = y;
        double r248106 = expm1(r248100);
        double r248107 = r248105 * r248106;
        double r248108 = r248104 + r248107;
        double r248109 = sqrt(r248108);
        double r248110 = log(r248109);
        double r248111 = r248110 + r248110;
        double r248112 = t;
        double r248113 = r248111 / r248112;
        double r248114 = r248103 - r248113;
        double r248115 = 4.717741906354947e-57;
        bool r248116 = r248100 <= r248115;
        double r248117 = r248100 * r248105;
        double r248118 = r248117 / r248112;
        double r248119 = 0.5;
        double r248120 = 2.0;
        double r248121 = pow(r248100, r248120);
        double r248122 = r248121 * r248105;
        double r248123 = r248122 / r248112;
        double r248124 = log(r248104);
        double r248125 = r248124 / r248112;
        double r248126 = fma(r248119, r248123, r248125);
        double r248127 = fma(r248118, r248104, r248126);
        double r248128 = r248103 - r248127;
        double r248129 = 1.0;
        double r248130 = cbrt(r248108);
        double r248131 = log(r248130);
        double r248132 = r248120 * r248131;
        double r248133 = r248132 + r248131;
        double r248134 = r248112 / r248133;
        double r248135 = r248129 / r248134;
        double r248136 = r248103 - r248135;
        double r248137 = r248116 ? r248128 : r248136;
        double r248138 = r248102 ? r248114 : r248137;
        return r248138;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.4
Target15.9
Herbie8.2
\[\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 3 regimes
  2. if z < -4.6972541441660704e-38

    1. Initial program 12.6

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

      \[\leadsto x - \frac{\log \left(\color{blue}{\left(1 + \left(-y\right)\right)} + y \cdot e^{z}\right)}{t}\]
    4. Applied associate-+l+12.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 add-sqr-sqrt11.5

      \[\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-prod11.5

      \[\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.6972541441660704e-38 < z < 4.717741906354947e-57

    1. Initial program 30.3

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

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

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

    if 4.717741906354947e-57 < z

    1. Initial program 28.6

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

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

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

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

      \[\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-cube-cbrt15.3

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

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

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

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

Reproduce

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