Average Error: 25.4 → 8.6
Time: 9.1s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;e^{z} \le 0.999999999996927458:\\ \;\;\;\;x - \frac{1}{\frac{t}{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\left(z \cdot y\right) \cdot \frac{1}{t}, 1, \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;e^{z} \le 0.999999999996927458:\\
\;\;\;\;x - \frac{1}{\frac{t}{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r289310 = x;
        double r289311 = 1.0;
        double r289312 = y;
        double r289313 = r289311 - r289312;
        double r289314 = z;
        double r289315 = exp(r289314);
        double r289316 = r289312 * r289315;
        double r289317 = r289313 + r289316;
        double r289318 = log(r289317);
        double r289319 = t;
        double r289320 = r289318 / r289319;
        double r289321 = r289310 - r289320;
        return r289321;
}

double f(double x, double y, double z, double t) {
        double r289322 = z;
        double r289323 = exp(r289322);
        double r289324 = 0.9999999999969275;
        bool r289325 = r289323 <= r289324;
        double r289326 = x;
        double r289327 = 1.0;
        double r289328 = t;
        double r289329 = 1.0;
        double r289330 = y;
        double r289331 = r289329 - r289330;
        double r289332 = r289330 * r289323;
        double r289333 = r289331 + r289332;
        double r289334 = log(r289333);
        double r289335 = r289328 / r289334;
        double r289336 = r289327 / r289335;
        double r289337 = r289326 - r289336;
        double r289338 = r289322 * r289330;
        double r289339 = r289327 / r289328;
        double r289340 = r289338 * r289339;
        double r289341 = 0.5;
        double r289342 = 2.0;
        double r289343 = pow(r289322, r289342);
        double r289344 = r289343 * r289330;
        double r289345 = r289344 / r289328;
        double r289346 = log(r289329);
        double r289347 = r289346 / r289328;
        double r289348 = fma(r289341, r289345, r289347);
        double r289349 = fma(r289340, r289329, r289348);
        double r289350 = r289326 - r289349;
        double r289351 = r289325 ? r289337 : r289350;
        return r289351;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.4
Target16.2
Herbie8.6
\[\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 (exp z) < 0.9999999999969275

    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 clear-num11.7

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

    if 0.9999999999969275 < (exp z)

    1. Initial program 31.6

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

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

      \[\leadsto x - \color{blue}{\mathsf{fma}\left(\frac{z \cdot y}{t}, 1, \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)}\]
    4. Using strategy rm
    5. Applied div-inv7.2

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

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

Reproduce

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