Average Error: 25.2 → 9.2
Time: 8.3s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.086785831759009406096340959265535489196 \cdot 10^{-25}:\\ \;\;\;\;x - \frac{\log \left(\left(1 - y\right) + \left(\sqrt[3]{y \cdot e^{z}} \cdot \sqrt[3]{y \cdot e^{z}}\right) \cdot \sqrt[3]{y \cdot e^{z}}\right)}{t}\\ \mathbf{elif}\;z \le 2.008863834229322266441971002211124440982 \cdot 10^{-217}:\\ \;\;\;\;x - \left(\frac{1}{\frac{t}{z}} \cdot y + \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(\frac{1}{2}, {z}^{2} \cdot y, \mathsf{fma}\left(z, y, 1\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 -2.086785831759009406096340959265535489196 \cdot 10^{-25}:\\
\;\;\;\;x - \frac{\log \left(\left(1 - y\right) + \left(\sqrt[3]{y \cdot e^{z}} \cdot \sqrt[3]{y \cdot e^{z}}\right) \cdot \sqrt[3]{y \cdot e^{z}}\right)}{t}\\

\mathbf{elif}\;z \le 2.008863834229322266441971002211124440982 \cdot 10^{-217}:\\
\;\;\;\;x - \left(\frac{1}{\frac{t}{z}} \cdot y + \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r339178 = x;
        double r339179 = 1.0;
        double r339180 = y;
        double r339181 = r339179 - r339180;
        double r339182 = z;
        double r339183 = exp(r339182);
        double r339184 = r339180 * r339183;
        double r339185 = r339181 + r339184;
        double r339186 = log(r339185);
        double r339187 = t;
        double r339188 = r339186 / r339187;
        double r339189 = r339178 - r339188;
        return r339189;
}

double f(double x, double y, double z, double t) {
        double r339190 = z;
        double r339191 = -2.0867858317590094e-25;
        bool r339192 = r339190 <= r339191;
        double r339193 = x;
        double r339194 = 1.0;
        double r339195 = y;
        double r339196 = r339194 - r339195;
        double r339197 = exp(r339190);
        double r339198 = r339195 * r339197;
        double r339199 = cbrt(r339198);
        double r339200 = r339199 * r339199;
        double r339201 = r339200 * r339199;
        double r339202 = r339196 + r339201;
        double r339203 = log(r339202);
        double r339204 = t;
        double r339205 = r339203 / r339204;
        double r339206 = r339193 - r339205;
        double r339207 = 2.0088638342293223e-217;
        bool r339208 = r339190 <= r339207;
        double r339209 = r339204 / r339190;
        double r339210 = r339194 / r339209;
        double r339211 = r339210 * r339195;
        double r339212 = 0.5;
        double r339213 = 2.0;
        double r339214 = pow(r339190, r339213);
        double r339215 = r339214 * r339195;
        double r339216 = r339215 / r339204;
        double r339217 = log(r339194);
        double r339218 = r339217 / r339204;
        double r339219 = fma(r339212, r339216, r339218);
        double r339220 = r339211 + r339219;
        double r339221 = r339193 - r339220;
        double r339222 = 0.5;
        double r339223 = fma(r339190, r339195, r339194);
        double r339224 = fma(r339222, r339215, r339223);
        double r339225 = log(r339224);
        double r339226 = r339225 / r339204;
        double r339227 = r339193 - r339226;
        double r339228 = r339208 ? r339221 : r339227;
        double r339229 = r339192 ? r339206 : r339228;
        return r339229;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.2
Target16.8
Herbie9.2
\[\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 < -2.0867858317590094e-25

    1. Initial program 13.1

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

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

    if -2.0867858317590094e-25 < z < 2.0088638342293223e-217

    1. Initial program 31.2

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

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

      \[\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 clear-num5.3

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

      \[\leadsto x - \color{blue}{\left(\frac{1}{\frac{t}{z \cdot y}} \cdot 1 + \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)}\]
    8. Simplified4.4

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

    if 2.0088638342293223e-217 < z

    1. Initial program 30.7

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

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

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

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

Reproduce

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