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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r322084 = x;
        double r322085 = 1.0;
        double r322086 = y;
        double r322087 = r322085 - r322086;
        double r322088 = z;
        double r322089 = exp(r322088);
        double r322090 = r322086 * r322089;
        double r322091 = r322087 + r322090;
        double r322092 = log(r322091);
        double r322093 = t;
        double r322094 = r322092 / r322093;
        double r322095 = r322084 - r322094;
        return r322095;
}

double f(double x, double y, double z, double t) {
        double r322096 = z;
        double r322097 = -1.022726975677261e-92;
        bool r322098 = r322096 <= r322097;
        double r322099 = x;
        double r322100 = 2.0;
        double r322101 = expm1(r322096);
        double r322102 = y;
        double r322103 = 1.0;
        double r322104 = fma(r322101, r322102, r322103);
        double r322105 = cbrt(r322104);
        double r322106 = pow(r322105, r322100);
        double r322107 = cbrt(r322106);
        double r322108 = sqrt(r322107);
        double r322109 = log(r322108);
        double r322110 = r322109 + r322109;
        double r322111 = cbrt(r322105);
        double r322112 = log(r322111);
        double r322113 = r322110 + r322112;
        double r322114 = r322100 * r322113;
        double r322115 = log(r322105);
        double r322116 = r322114 + r322115;
        double r322117 = t;
        double r322118 = r322116 / r322117;
        double r322119 = r322099 - r322118;
        double r322120 = 0.5;
        double r322121 = r322120 * r322096;
        double r322122 = r322103 + r322121;
        double r322123 = r322096 * r322122;
        double r322124 = log(r322103);
        double r322125 = fma(r322102, r322123, r322124);
        double r322126 = r322125 / r322117;
        double r322127 = r322099 - r322126;
        double r322128 = r322098 ? r322119 : r322127;
        return r322128;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.9
Target16.0
Herbie8.5
\[\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 2 regimes
  2. if z < -1.022726975677261e-92

    1. Initial program 15.9

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

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

      \[\leadsto x - \frac{\log \color{blue}{\left(\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)}}{t}\]
    5. Applied log-prod11.3

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

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

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

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

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

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

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

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

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

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

    if -1.022726975677261e-92 < z

    1. Initial program 30.8

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

      \[\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 6.7

      \[\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. Simplified6.7

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

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

Reproduce

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