Average Error: 24.9 → 7.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 -1.052384401893189 \cdot 10^{-27}:\\ \;\;\;\;x - \frac{2 \cdot \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \left(\frac{1}{3} \cdot \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \frac{1}{3} \cdot \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)\right)}{t}\\ \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 -1.052384401893189 \cdot 10^{-27}:\\
\;\;\;\;x - \frac{2 \cdot \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \left(\frac{1}{3} \cdot \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \frac{1}{3} \cdot \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)\right)}{t}\\

\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 r268212 = x;
        double r268213 = 1.0;
        double r268214 = y;
        double r268215 = r268213 - r268214;
        double r268216 = z;
        double r268217 = exp(r268216);
        double r268218 = r268214 * r268217;
        double r268219 = r268215 + r268218;
        double r268220 = log(r268219);
        double r268221 = t;
        double r268222 = r268220 / r268221;
        double r268223 = r268212 - r268222;
        return r268223;
}

double f(double x, double y, double z, double t) {
        double r268224 = z;
        double r268225 = -1.052384401893189e-27;
        bool r268226 = r268224 <= r268225;
        double r268227 = x;
        double r268228 = 2.0;
        double r268229 = 1.0;
        double r268230 = y;
        double r268231 = expm1(r268224);
        double r268232 = r268230 * r268231;
        double r268233 = r268229 + r268232;
        double r268234 = cbrt(r268233);
        double r268235 = log(r268234);
        double r268236 = r268228 * r268235;
        double r268237 = 0.3333333333333333;
        double r268238 = sqrt(r268233);
        double r268239 = log(r268238);
        double r268240 = r268237 * r268239;
        double r268241 = r268240 + r268240;
        double r268242 = r268236 + r268241;
        double r268243 = t;
        double r268244 = r268242 / r268243;
        double r268245 = r268227 - r268244;
        double r268246 = 0.5;
        double r268247 = pow(r268224, r268228);
        double r268248 = r268247 * r268230;
        double r268249 = r268224 * r268230;
        double r268250 = log(r268229);
        double r268251 = fma(r268229, r268249, r268250);
        double r268252 = fma(r268246, r268248, r268251);
        double r268253 = r268252 / r268243;
        double r268254 = r268227 - r268253;
        double r268255 = r268226 ? r268245 : r268254;
        return r268255;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.9
Target15.6
Herbie7.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 < -1.052384401893189e-27

    1. Initial program 11.7

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

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

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

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

      \[\leadsto x - \frac{\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)}}{t}\]
    8. Applied log-prod11.0

      \[\leadsto x - \frac{\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)}}{t}\]
    9. Simplified11.0

      \[\leadsto x - \frac{\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)}{t}\]
    10. Using strategy rm
    11. Applied pow1/311.0

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

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

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

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

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

    if -1.052384401893189e-27 < z

    1. Initial program 31.0

      \[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 simplification7.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.052384401893189 \cdot 10^{-27}:\\ \;\;\;\;x - \frac{2 \cdot \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \left(\frac{1}{3} \cdot \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \frac{1}{3} \cdot \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)\right)}{t}\\ \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 2020046 +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)))