Average Error: 25.0 → 8.0
Time: 32.8s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -0.17745823722532728:\\ \;\;\;\;x - \frac{\sqrt{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}}{\frac{t}{\sqrt{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}}}\\ \mathbf{elif}\;z \le -7.05653233804947833 \cdot 10^{-90}:\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(y, \mathsf{fma}\left(\frac{1}{2}, {z}^{2}, z\right), 1\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(1, \frac{1}{\frac{\frac{t}{z}}{y}}, \frac{\log 1}{t}\right)\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -0.17745823722532728:\\
\;\;\;\;x - \frac{\sqrt{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}}{\frac{t}{\sqrt{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}}}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r213176 = x;
        double r213177 = 1.0;
        double r213178 = y;
        double r213179 = r213177 - r213178;
        double r213180 = z;
        double r213181 = exp(r213180);
        double r213182 = r213178 * r213181;
        double r213183 = r213179 + r213182;
        double r213184 = log(r213183);
        double r213185 = t;
        double r213186 = r213184 / r213185;
        double r213187 = r213176 - r213186;
        return r213187;
}

double f(double x, double y, double z, double t) {
        double r213188 = z;
        double r213189 = -0.17745823722532728;
        bool r213190 = r213188 <= r213189;
        double r213191 = x;
        double r213192 = exp(r213188);
        double r213193 = y;
        double r213194 = 1.0;
        double r213195 = r213194 - r213193;
        double r213196 = fma(r213192, r213193, r213195);
        double r213197 = log(r213196);
        double r213198 = sqrt(r213197);
        double r213199 = t;
        double r213200 = r213199 / r213198;
        double r213201 = r213198 / r213200;
        double r213202 = r213191 - r213201;
        double r213203 = -7.056532338049478e-90;
        bool r213204 = r213188 <= r213203;
        double r213205 = 0.5;
        double r213206 = 2.0;
        double r213207 = pow(r213188, r213206);
        double r213208 = fma(r213205, r213207, r213188);
        double r213209 = fma(r213193, r213208, r213194);
        double r213210 = log(r213209);
        double r213211 = r213210 / r213199;
        double r213212 = r213191 - r213211;
        double r213213 = 1.0;
        double r213214 = r213199 / r213188;
        double r213215 = r213214 / r213193;
        double r213216 = r213213 / r213215;
        double r213217 = log(r213194);
        double r213218 = r213217 / r213199;
        double r213219 = fma(r213194, r213216, r213218);
        double r213220 = r213191 - r213219;
        double r213221 = r213204 ? r213212 : r213220;
        double r213222 = r213190 ? r213202 : r213221;
        return r213222;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.0
Target15.9
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 3 regimes
  2. if z < -0.17745823722532728

    1. Initial program 11.6

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified11.6

      \[\leadsto \color{blue}{x - \frac{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}{t}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt12.4

      \[\leadsto x - \frac{\color{blue}{\sqrt{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)} \cdot \sqrt{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}}}{t}\]
    5. Applied associate-/l*12.4

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

    if -0.17745823722532728 < z < -7.056532338049478e-90

    1. Initial program 28.4

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified28.4

      \[\leadsto \color{blue}{x - \frac{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}{t}}\]
    3. Taylor expanded around 0 11.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}\]
    4. Simplified11.9

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

    if -7.056532338049478e-90 < z

    1. Initial program 30.8

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified30.8

      \[\leadsto \color{blue}{x - \frac{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}{t}}\]
    3. Taylor expanded around 0 6.3

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

      \[\leadsto x - \frac{\color{blue}{\mathsf{fma}\left(y, \mathsf{fma}\left(0.5, {z}^{2}, 1 \cdot z\right), \log 1\right)}}{t}\]
    5. Taylor expanded around 0 6.4

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

      \[\leadsto \color{blue}{x - \mathsf{fma}\left(1, \frac{z \cdot y}{t}, \frac{\log 1}{t}\right)}\]
    7. Using strategy rm
    8. Applied clear-num6.4

      \[\leadsto x - \mathsf{fma}\left(1, \color{blue}{\frac{1}{\frac{t}{z \cdot y}}}, \frac{\log 1}{t}\right)\]
    9. Using strategy rm
    10. Applied associate-/r*5.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -0.17745823722532728:\\ \;\;\;\;x - \frac{\sqrt{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}}{\frac{t}{\sqrt{\log \left(\mathsf{fma}\left(e^{z}, y, 1 - y\right)\right)}}}\\ \mathbf{elif}\;z \le -7.05653233804947833 \cdot 10^{-90}:\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(y, \mathsf{fma}\left(\frac{1}{2}, {z}^{2}, z\right), 1\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(1, \frac{1}{\frac{\frac{t}{z}}{y}}, \frac{\log 1}{t}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019199 +o rules:numerics
(FPCore (x y z t)
  :name "System.Random.MWC.Distributions:truncatedExp from mwc-random-0.13.3.2"

  :herbie-target
  (if (< z -2.8874623088207947e+119) (- (- x (/ (/ (- 0.5) (* y t)) (* z z))) (* (/ (- 0.5) (* y t)) (/ (/ 2.0 z) (* z z)))) (- x (/ (log (+ 1.0 (* z y))) t)))

  (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))