Average Error: 25.6 → 8.4
Time: 11.4s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -4.41248982228196080047607816779617544214 \cdot 10^{-82}:\\ \;\;\;\;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 1.552415002017130815259544856599366962842 \cdot 10^{-104}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(1 + \mathsf{fma}\left(\frac{1}{6}, {z}^{3} \cdot y, \mathsf{fma}\left(z, y, \frac{1}{2} \cdot \left({z}^{2} \cdot y\right)\right)\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 -4.41248982228196080047607816779617544214 \cdot 10^{-82}:\\
\;\;\;\;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 1.552415002017130815259544856599366962842 \cdot 10^{-104}:\\
\;\;\;\;x - \frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r242255 = x;
        double r242256 = 1.0;
        double r242257 = y;
        double r242258 = r242256 - r242257;
        double r242259 = z;
        double r242260 = exp(r242259);
        double r242261 = r242257 * r242260;
        double r242262 = r242258 + r242261;
        double r242263 = log(r242262);
        double r242264 = t;
        double r242265 = r242263 / r242264;
        double r242266 = r242255 - r242265;
        return r242266;
}

double f(double x, double y, double z, double t) {
        double r242267 = z;
        double r242268 = -4.412489822281961e-82;
        bool r242269 = r242267 <= r242268;
        double r242270 = x;
        double r242271 = 1.0;
        double r242272 = y;
        double r242273 = expm1(r242267);
        double r242274 = r242272 * r242273;
        double r242275 = r242271 + r242274;
        double r242276 = sqrt(r242275);
        double r242277 = log(r242276);
        double r242278 = r242277 + r242277;
        double r242279 = t;
        double r242280 = r242278 / r242279;
        double r242281 = r242270 - r242280;
        double r242282 = 1.5524150020171308e-104;
        bool r242283 = r242267 <= r242282;
        double r242284 = 0.5;
        double r242285 = 2.0;
        double r242286 = pow(r242267, r242285);
        double r242287 = r242286 * r242272;
        double r242288 = r242267 * r242272;
        double r242289 = log(r242271);
        double r242290 = fma(r242271, r242288, r242289);
        double r242291 = fma(r242284, r242287, r242290);
        double r242292 = r242291 / r242279;
        double r242293 = r242270 - r242292;
        double r242294 = 0.16666666666666666;
        double r242295 = 3.0;
        double r242296 = pow(r242267, r242295);
        double r242297 = r242296 * r242272;
        double r242298 = 0.5;
        double r242299 = r242298 * r242287;
        double r242300 = fma(r242267, r242272, r242299);
        double r242301 = fma(r242294, r242297, r242300);
        double r242302 = r242271 + r242301;
        double r242303 = log(r242302);
        double r242304 = r242303 / r242279;
        double r242305 = r242270 - r242304;
        double r242306 = r242283 ? r242293 : r242305;
        double r242307 = r242269 ? r242281 : r242306;
        return r242307;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.6
Target16.0
Herbie8.4
\[\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 < -4.412489822281961e-82

    1. Initial program 16.2

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

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

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

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

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

      \[\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.412489822281961e-82 < z < 1.5524150020171308e-104

    1. Initial program 31.0

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

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

      \[\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}\]

    if 1.5524150020171308e-104 < z

    1. Initial program 31.6

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

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

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

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

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

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

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

Reproduce

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