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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r188130 = x;
        double r188131 = 1.0;
        double r188132 = y;
        double r188133 = r188131 - r188132;
        double r188134 = z;
        double r188135 = exp(r188134);
        double r188136 = r188132 * r188135;
        double r188137 = r188133 + r188136;
        double r188138 = log(r188137);
        double r188139 = t;
        double r188140 = r188138 / r188139;
        double r188141 = r188130 - r188140;
        return r188141;
}

double f(double x, double y, double z, double t) {
        double r188142 = z;
        double r188143 = -3716868871.2444687;
        bool r188144 = r188142 <= r188143;
        double r188145 = x;
        double r188146 = 1.0;
        double r188147 = y;
        double r188148 = r188146 - r188147;
        double r188149 = sqrt(r188148);
        double r188150 = exp(r188142);
        double r188151 = r188150 * r188147;
        double r188152 = fma(r188149, r188149, r188151);
        double r188153 = log(r188152);
        double r188154 = t;
        double r188155 = r188153 / r188154;
        double r188156 = r188145 - r188155;
        double r188157 = r188154 / r188142;
        double r188158 = r188147 / r188157;
        double r188159 = log(r188146);
        double r188160 = r188159 / r188154;
        double r188161 = fma(r188146, r188158, r188160);
        double r188162 = r188145 - r188161;
        double r188163 = r188144 ? r188156 : r188162;
        return r188163;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.8
Target16.5
Herbie8.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 2 regimes
  2. if z < -3716868871.2444687

    1. Initial program 11.4

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

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

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

    if -3716868871.2444687 < z

    1. Initial program 30.3

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. 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)}\]
    3. Simplified7.5

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

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

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

      \[\leadsto x - \color{blue}{\left(1 \cdot \frac{z \cdot y}{t} + \frac{\log 1}{t}\right)}\]
    8. Simplified9.7

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

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

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

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

Reproduce

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