Average Error: 25.0 → 10.7
Time: 9.8s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;y \le 3.0282374466509755 \cdot 10^{-40} \lor \neg \left(y \le 2.29997582564267609 \cdot 10^{127}\right):\\ \;\;\;\;x - \left(\frac{1}{2} \cdot \log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right) + \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)\right) \cdot \frac{1}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;y \le 3.0282374466509755 \cdot 10^{-40} \lor \neg \left(y \le 2.29997582564267609 \cdot 10^{127}\right):\\
\;\;\;\;x - \left(\frac{1}{2} \cdot \log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right) + \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)\right) \cdot \frac{1}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r278719 = x;
        double r278720 = 1.0;
        double r278721 = y;
        double r278722 = r278720 - r278721;
        double r278723 = z;
        double r278724 = exp(r278723);
        double r278725 = r278721 * r278724;
        double r278726 = r278722 + r278725;
        double r278727 = log(r278726);
        double r278728 = t;
        double r278729 = r278727 / r278728;
        double r278730 = r278719 - r278729;
        return r278730;
}

double f(double x, double y, double z, double t) {
        double r278731 = y;
        double r278732 = 3.0282374466509755e-40;
        bool r278733 = r278731 <= r278732;
        double r278734 = 2.299975825642676e+127;
        bool r278735 = r278731 <= r278734;
        double r278736 = !r278735;
        bool r278737 = r278733 || r278736;
        double r278738 = x;
        double r278739 = 0.5;
        double r278740 = 1.0;
        double r278741 = z;
        double r278742 = expm1(r278741);
        double r278743 = r278731 * r278742;
        double r278744 = r278740 + r278743;
        double r278745 = log(r278744);
        double r278746 = r278739 * r278745;
        double r278747 = sqrt(r278744);
        double r278748 = log(r278747);
        double r278749 = r278746 + r278748;
        double r278750 = 1.0;
        double r278751 = t;
        double r278752 = r278750 / r278751;
        double r278753 = r278749 * r278752;
        double r278754 = r278738 - r278753;
        double r278755 = 0.5;
        double r278756 = 2.0;
        double r278757 = pow(r278741, r278756);
        double r278758 = r278757 * r278731;
        double r278759 = r278741 * r278731;
        double r278760 = log(r278740);
        double r278761 = fma(r278740, r278759, r278760);
        double r278762 = fma(r278755, r278758, r278761);
        double r278763 = r278762 / r278751;
        double r278764 = r278738 - r278763;
        double r278765 = r278737 ? r278754 : r278764;
        return r278765;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.0
Target16.1
Herbie10.7
\[\begin{array}{l} \mathbf{if}\;z \lt -2.88746230882079466 \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 y < 3.0282374466509755e-40 or 2.299975825642676e+127 < y

    1. Initial program 22.6

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

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

      \[\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 div-inv10.8

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

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

      \[\leadsto x - \color{blue}{\left(\log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)\right)} \cdot \frac{1}{t}\]
    11. Using strategy rm
    12. Applied pow1/210.8

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

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

    if 3.0282374466509755e-40 < y < 2.299975825642676e+127

    1. Initial program 42.7

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

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

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

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
    6. Taylor expanded around 0 10.1

      \[\leadsto 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}\]
    7. Simplified10.1

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

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

Reproduce

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