Average Error: 24.4 → 7.6
Time: 27.2s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -6.358797691452859197803043329522892515885 \cdot 10^{-48}:\\ \;\;\;\;x - \frac{\left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right) + \left(\left(\log \left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right|}\right) + \log \left(\sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right)\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\\ \mathbf{elif}\;z \le 5.278878335163116895565645241280298789929 \cdot 10^{-40}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, \frac{y}{1}, \mathsf{fma}\left(\frac{1}{2}, \frac{\frac{{z}^{2} \cdot y}{1}}{t}, 2 \cdot \frac{\log \left(\sqrt{1}\right)}{t}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(y, \mathsf{fma}\left(\frac{1}{2}, {z}^{2}, z\right), 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 -6.358797691452859197803043329522892515885 \cdot 10^{-48}:\\
\;\;\;\;x - \frac{\left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right) + \left(\left(\log \left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right|}\right) + \log \left(\sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right)\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r162141 = x;
        double r162142 = 1.0;
        double r162143 = y;
        double r162144 = r162142 - r162143;
        double r162145 = z;
        double r162146 = exp(r162145);
        double r162147 = r162143 * r162146;
        double r162148 = r162144 + r162147;
        double r162149 = log(r162148);
        double r162150 = t;
        double r162151 = r162149 / r162150;
        double r162152 = r162141 - r162151;
        return r162152;
}

double f(double x, double y, double z, double t) {
        double r162153 = z;
        double r162154 = -6.358797691452859e-48;
        bool r162155 = r162153 <= r162154;
        double r162156 = x;
        double r162157 = expm1(r162153);
        double r162158 = y;
        double r162159 = 1.0;
        double r162160 = fma(r162157, r162158, r162159);
        double r162161 = sqrt(r162160);
        double r162162 = sqrt(r162161);
        double r162163 = log(r162162);
        double r162164 = r162163 + r162163;
        double r162165 = cbrt(r162160);
        double r162166 = fabs(r162165);
        double r162167 = sqrt(r162166);
        double r162168 = log(r162167);
        double r162169 = sqrt(r162165);
        double r162170 = sqrt(r162169);
        double r162171 = log(r162170);
        double r162172 = r162168 + r162171;
        double r162173 = r162172 + r162163;
        double r162174 = r162164 + r162173;
        double r162175 = t;
        double r162176 = r162174 / r162175;
        double r162177 = r162156 - r162176;
        double r162178 = 5.278878335163117e-40;
        bool r162179 = r162153 <= r162178;
        double r162180 = r162153 / r162175;
        double r162181 = r162158 / r162159;
        double r162182 = 0.5;
        double r162183 = 2.0;
        double r162184 = pow(r162153, r162183);
        double r162185 = r162184 * r162158;
        double r162186 = r162185 / r162159;
        double r162187 = r162186 / r162175;
        double r162188 = sqrt(r162159);
        double r162189 = log(r162188);
        double r162190 = r162189 / r162175;
        double r162191 = r162183 * r162190;
        double r162192 = fma(r162182, r162187, r162191);
        double r162193 = fma(r162180, r162181, r162192);
        double r162194 = r162156 - r162193;
        double r162195 = fma(r162182, r162184, r162153);
        double r162196 = fma(r162158, r162195, r162159);
        double r162197 = log(r162196);
        double r162198 = r162197 / r162175;
        double r162199 = r162156 - r162198;
        double r162200 = r162179 ? r162194 : r162199;
        double r162201 = r162155 ? r162177 : r162200;
        return r162201;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.4
Target16.5
Herbie7.6
\[\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 < -6.358797691452859e-48

    1. Initial program 13.2

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.358797691452859e-48 < z < 5.278878335163117e-40

    1. Initial program 30.6

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

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

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

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

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

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

    if 5.278878335163117e-40 < z

    1. Initial program 25.6

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

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

      \[\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}\]
    4. Simplified11.6

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

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

Reproduce

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