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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r182778 = x;
        double r182779 = 1.0;
        double r182780 = y;
        double r182781 = r182779 - r182780;
        double r182782 = z;
        double r182783 = exp(r182782);
        double r182784 = r182780 * r182783;
        double r182785 = r182781 + r182784;
        double r182786 = log(r182785);
        double r182787 = t;
        double r182788 = r182786 / r182787;
        double r182789 = r182778 - r182788;
        return r182789;
}

double f(double x, double y, double z, double t) {
        double r182790 = z;
        double r182791 = -6.310119903545574e-134;
        bool r182792 = r182790 <= r182791;
        double r182793 = 1.0;
        double r182794 = x;
        double r182795 = expm1(r182790);
        double r182796 = y;
        double r182797 = 1.0;
        double r182798 = fma(r182795, r182796, r182797);
        double r182799 = log(r182798);
        double r182800 = t;
        double r182801 = r182799 / r182800;
        double r182802 = -r182801;
        double r182803 = fma(r182793, r182794, r182802);
        double r182804 = 0.5;
        double r182805 = r182804 * r182790;
        double r182806 = r182805 + r182797;
        double r182807 = r182790 * r182806;
        double r182808 = log(r182797);
        double r182809 = fma(r182796, r182807, r182808);
        double r182810 = r182809 / r182800;
        double r182811 = -r182810;
        double r182812 = fma(r182793, r182794, r182811);
        double r182813 = r182792 ? r182803 : r182812;
        return r182813;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.6
Target16.1
Herbie8.4
\[\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 < -6.310119903545574e-134

    1. Initial program 16.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. Using strategy rm
    4. Applied div-inv11.6

      \[\leadsto x - \color{blue}{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity11.6

      \[\leadsto \color{blue}{1 \cdot x} - \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}\]
    7. Applied fma-neg11.6

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

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

    if -6.310119903545574e-134 < z

    1. Initial program 30.4

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

      \[\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 div-inv11.2

      \[\leadsto x - \color{blue}{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity11.2

      \[\leadsto \color{blue}{1 \cdot x} - \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}\]
    7. Applied fma-neg11.2

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

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

      \[\leadsto \mathsf{fma}\left(1, 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}\right)\]
    10. Simplified6.0

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

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

Reproduce

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