Average Error: 25.1 → 8.1
Time: 26.0s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;e^{z} \le 5.133580128615205696306839549874698191978 \cdot 10^{-9}:\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(y, e^{z}, 1 - y\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(1, \frac{z}{t} \cdot y, \mathsf{fma}\left(\frac{z \cdot \left(z \cdot y\right)}{t}, 0.5, \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 5.133580128615205696306839549874698191978 \cdot 10^{-9}:\\
\;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(y, e^{z}, 1 - y\right)\right)}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r12247085 = x;
        double r12247086 = 1.0;
        double r12247087 = y;
        double r12247088 = r12247086 - r12247087;
        double r12247089 = z;
        double r12247090 = exp(r12247089);
        double r12247091 = r12247087 * r12247090;
        double r12247092 = r12247088 + r12247091;
        double r12247093 = log(r12247092);
        double r12247094 = t;
        double r12247095 = r12247093 / r12247094;
        double r12247096 = r12247085 - r12247095;
        return r12247096;
}

double f(double x, double y, double z, double t) {
        double r12247097 = z;
        double r12247098 = exp(r12247097);
        double r12247099 = 5.133580128615206e-09;
        bool r12247100 = r12247098 <= r12247099;
        double r12247101 = x;
        double r12247102 = y;
        double r12247103 = 1.0;
        double r12247104 = r12247103 - r12247102;
        double r12247105 = fma(r12247102, r12247098, r12247104);
        double r12247106 = log(r12247105);
        double r12247107 = t;
        double r12247108 = r12247106 / r12247107;
        double r12247109 = r12247101 - r12247108;
        double r12247110 = r12247097 / r12247107;
        double r12247111 = r12247110 * r12247102;
        double r12247112 = r12247097 * r12247102;
        double r12247113 = r12247097 * r12247112;
        double r12247114 = r12247113 / r12247107;
        double r12247115 = 0.5;
        double r12247116 = log(r12247103);
        double r12247117 = r12247116 / r12247107;
        double r12247118 = fma(r12247114, r12247115, r12247117);
        double r12247119 = fma(r12247103, r12247111, r12247118);
        double r12247120 = r12247101 - r12247119;
        double r12247121 = r12247100 ? r12247109 : r12247120;
        return r12247121;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.1
Target16.6
Herbie8.1
\[\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 (exp z) < 5.133580128615206e-09

    1. Initial program 11.8

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

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

      \[\leadsto x - \frac{\log \left(\mathsf{fma}\left(y, e^{z}, 1 - y\right)\right)}{\color{blue}{1 \cdot t}}\]
    5. Applied pow111.8

      \[\leadsto x - \frac{\log \color{blue}{\left({\left(\mathsf{fma}\left(y, e^{z}, 1 - y\right)\right)}^{1}\right)}}{1 \cdot t}\]
    6. Applied log-pow11.8

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

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

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

    if 5.133580128615206e-09 < (exp z)

    1. Initial program 30.9

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

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

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

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

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

Reproduce

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