Average Error: 25.0 → 9.0
Time: 50.2s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.355985277760923721475726033060808414189 \cdot 10^{-91}:\\ \;\;\;\;x - \frac{1}{\frac{\frac{t}{\sqrt{\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)}}}{\sqrt{\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z \cdot y}{t}, 1, \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 -1.355985277760923721475726033060808414189 \cdot 10^{-91}:\\
\;\;\;\;x - \frac{1}{\frac{\frac{t}{\sqrt{\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)}}}{\sqrt{\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)}}}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r9629034 = x;
        double r9629035 = 1.0;
        double r9629036 = y;
        double r9629037 = r9629035 - r9629036;
        double r9629038 = z;
        double r9629039 = exp(r9629038);
        double r9629040 = r9629036 * r9629039;
        double r9629041 = r9629037 + r9629040;
        double r9629042 = log(r9629041);
        double r9629043 = t;
        double r9629044 = r9629042 / r9629043;
        double r9629045 = r9629034 - r9629044;
        return r9629045;
}

double f(double x, double y, double z, double t) {
        double r9629046 = z;
        double r9629047 = -1.3559852777609237e-91;
        bool r9629048 = r9629046 <= r9629047;
        double r9629049 = x;
        double r9629050 = 1.0;
        double r9629051 = t;
        double r9629052 = y;
        double r9629053 = expm1(r9629046);
        double r9629054 = 1.0;
        double r9629055 = fma(r9629052, r9629053, r9629054);
        double r9629056 = log(r9629055);
        double r9629057 = sqrt(r9629056);
        double r9629058 = r9629051 / r9629057;
        double r9629059 = r9629058 / r9629057;
        double r9629060 = r9629050 / r9629059;
        double r9629061 = r9629049 - r9629060;
        double r9629062 = r9629046 * r9629052;
        double r9629063 = r9629062 / r9629051;
        double r9629064 = log(r9629054);
        double r9629065 = r9629064 / r9629051;
        double r9629066 = fma(r9629063, r9629054, r9629065);
        double r9629067 = r9629049 - r9629066;
        double r9629068 = r9629048 ? r9629061 : r9629067;
        return r9629068;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.0
Target16.4
Herbie9.0
\[\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 2 regimes
  2. if z < -1.3559852777609237e-91

    1. Initial program 15.6

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

      \[\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 clear-num11.9

      \[\leadsto x - \color{blue}{\frac{1}{\frac{t}{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt12.8

      \[\leadsto x - \frac{1}{\frac{t}{\color{blue}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)} \cdot \sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}}}\]
    7. Applied *-un-lft-identity12.8

      \[\leadsto x - \frac{1}{\frac{\color{blue}{1 \cdot t}}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)} \cdot \sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}}\]
    8. Applied times-frac12.8

      \[\leadsto x - \frac{1}{\color{blue}{\frac{1}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}} \cdot \frac{t}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}}}\]
    9. Applied *-un-lft-identity12.8

      \[\leadsto x - \frac{\color{blue}{1 \cdot 1}}{\frac{1}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}} \cdot \frac{t}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}}\]
    10. Applied times-frac12.8

      \[\leadsto x - \color{blue}{\frac{1}{\frac{1}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}} \cdot \frac{1}{\frac{t}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}}}\]
    11. Using strategy rm
    12. Applied expm1-log1p-u12.8

      \[\leadsto x - \frac{1}{\frac{1}{\sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right)\right)}}}} \cdot \frac{1}{\frac{t}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}}\]
    13. Using strategy rm
    14. Applied frac-times12.8

      \[\leadsto x - \color{blue}{\frac{1 \cdot 1}{\frac{1}{\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right)\right)}} \cdot \frac{t}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}}}\]
    15. Simplified12.8

      \[\leadsto x - \frac{\color{blue}{1}}{\frac{1}{\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right)\right)}} \cdot \frac{t}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}}\]
    16. Simplified12.8

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

    if -1.3559852777609237e-91 < z

    1. Initial program 30.9

      \[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(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}}\]
    3. Taylor expanded around 0 6.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.355985277760923721475726033060808414189 \cdot 10^{-91}:\\ \;\;\;\;x - \frac{1}{\frac{\frac{t}{\sqrt{\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)}}}{\sqrt{\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z \cdot y}{t}, 1, \frac{\log 1}{t}\right)\\ \end{array}\]

Reproduce

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