Average Error: 24.9 → 8.0
Time: 29.4s
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 \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) + \mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\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 \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) + \mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\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 r288000 = x;
        double r288001 = 1.0;
        double r288002 = y;
        double r288003 = r288001 - r288002;
        double r288004 = z;
        double r288005 = exp(r288004);
        double r288006 = r288002 * r288005;
        double r288007 = r288003 + r288006;
        double r288008 = log(r288007);
        double r288009 = t;
        double r288010 = r288008 / r288009;
        double r288011 = r288000 - r288010;
        return r288011;
}

double f(double x, double y, double z, double t) {
        double r288012 = z;
        double r288013 = -1.052384401893189e-27;
        bool r288014 = r288012 <= r288013;
        double r288015 = x;
        double r288016 = 2.0;
        double r288017 = 0.3333333333333333;
        double r288018 = expm1(r288012);
        double r288019 = y;
        double r288020 = 1.0;
        double r288021 = fma(r288018, r288019, r288020);
        double r288022 = log(r288021);
        double r288023 = r288017 * r288022;
        double r288024 = r288016 * r288023;
        double r288025 = cbrt(r288021);
        double r288026 = log(r288025);
        double r288027 = log1p(r288026);
        double r288028 = expm1(r288027);
        double r288029 = r288024 + r288028;
        double r288030 = t;
        double r288031 = r288029 / r288030;
        double r288032 = r288015 - r288031;
        double r288033 = 0.5;
        double r288034 = pow(r288012, r288016);
        double r288035 = r288034 * r288019;
        double r288036 = r288012 * r288019;
        double r288037 = log(r288020);
        double r288038 = fma(r288020, r288036, r288037);
        double r288039 = fma(r288033, r288035, r288038);
        double r288040 = r288039 / r288030;
        double r288041 = r288015 - r288040;
        double r288042 = r288014 ? r288032 : r288041;
        return r288042;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.9
Target15.6
Herbie8.0
\[\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. Simplified11.0

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

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

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

      \[\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 pow1/311.0

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

      \[\leadsto x - \frac{2 \cdot \color{blue}{\left(\frac{1}{3} \cdot \log \left(\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}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrt11.0

      \[\leadsto x - \frac{2 \cdot \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) + \log \color{blue}{\left(\sqrt{\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)}}{t}\]
    12. Using strategy rm
    13. Applied expm1-log1p-u11.0

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

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

      \[\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.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}\]
    4. 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 simplification8.0

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