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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r246740 = x;
        double r246741 = 1.0;
        double r246742 = y;
        double r246743 = r246741 - r246742;
        double r246744 = z;
        double r246745 = exp(r246744);
        double r246746 = r246742 * r246745;
        double r246747 = r246743 + r246746;
        double r246748 = log(r246747);
        double r246749 = t;
        double r246750 = r246748 / r246749;
        double r246751 = r246740 - r246750;
        return r246751;
}

double f(double x, double y, double z, double t) {
        double r246752 = z;
        double r246753 = -3.083544696508266e-246;
        bool r246754 = r246752 <= r246753;
        double r246755 = x;
        double r246756 = 2.0;
        double r246757 = 1.0;
        double r246758 = y;
        double r246759 = expm1(r246752);
        double r246760 = r246758 * r246759;
        double r246761 = r246757 + r246760;
        double r246762 = cbrt(r246761);
        double r246763 = log(r246762);
        double r246764 = r246756 * r246763;
        double r246765 = r246764 + r246763;
        double r246766 = t;
        double r246767 = r246765 / r246766;
        double r246768 = r246755 - r246767;
        double r246769 = r246752 * r246758;
        double r246770 = r246769 / r246766;
        double r246771 = 0.5;
        double r246772 = pow(r246752, r246756);
        double r246773 = r246772 * r246758;
        double r246774 = r246773 / r246766;
        double r246775 = log(r246757);
        double r246776 = r246775 / r246766;
        double r246777 = fma(r246771, r246774, r246776);
        double r246778 = fma(r246770, r246757, r246777);
        double r246779 = r246755 - r246778;
        double r246780 = r246754 ? r246768 : r246779;
        return r246780;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.9
Target15.8
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 < -3.083544696508266e-246

    1. Initial program 19.8

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

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

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

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt10.8

      \[\leadsto x - \frac{\log \color{blue}{\left(\left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)} \cdot \sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) \cdot \sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}}{t}\]
    8. Applied log-prod10.8

      \[\leadsto x - \frac{\color{blue}{\log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)} \cdot \sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}}{t}\]
    9. Simplified10.8

      \[\leadsto x - \frac{\color{blue}{2 \cdot \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)} + \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]

    if -3.083544696508266e-246 < z

    1. Initial program 31.2

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Taylor expanded around 0 6.6

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

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

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

Reproduce

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