Average Error: 25.6 → 8.4
Time: 11.7s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -4.41248982228196080047607816779617544214 \cdot 10^{-82}:\\ \;\;\;\;x - \frac{\log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\\ \mathbf{elif}\;z \le 1.552415002017130815259544856599366962842 \cdot 10^{-104}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(1 + \mathsf{fma}\left(\frac{1}{6}, {z}^{3} \cdot y, \mathsf{fma}\left(z, y, \frac{1}{2} \cdot \left({z}^{2} \cdot y\right)\right)\right)\right)}{t}\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -4.41248982228196080047607816779617544214 \cdot 10^{-82}:\\
\;\;\;\;x - \frac{\log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r286795 = x;
        double r286796 = 1.0;
        double r286797 = y;
        double r286798 = r286796 - r286797;
        double r286799 = z;
        double r286800 = exp(r286799);
        double r286801 = r286797 * r286800;
        double r286802 = r286798 + r286801;
        double r286803 = log(r286802);
        double r286804 = t;
        double r286805 = r286803 / r286804;
        double r286806 = r286795 - r286805;
        return r286806;
}

double f(double x, double y, double z, double t) {
        double r286807 = z;
        double r286808 = -4.412489822281961e-82;
        bool r286809 = r286807 <= r286808;
        double r286810 = x;
        double r286811 = 1.0;
        double r286812 = y;
        double r286813 = expm1(r286807);
        double r286814 = r286812 * r286813;
        double r286815 = r286811 + r286814;
        double r286816 = sqrt(r286815);
        double r286817 = log(r286816);
        double r286818 = r286817 + r286817;
        double r286819 = t;
        double r286820 = r286818 / r286819;
        double r286821 = r286810 - r286820;
        double r286822 = 1.5524150020171308e-104;
        bool r286823 = r286807 <= r286822;
        double r286824 = 0.5;
        double r286825 = 2.0;
        double r286826 = pow(r286807, r286825);
        double r286827 = r286826 * r286812;
        double r286828 = r286807 * r286812;
        double r286829 = log(r286811);
        double r286830 = fma(r286811, r286828, r286829);
        double r286831 = fma(r286824, r286827, r286830);
        double r286832 = r286831 / r286819;
        double r286833 = r286810 - r286832;
        double r286834 = 0.16666666666666666;
        double r286835 = 3.0;
        double r286836 = pow(r286807, r286835);
        double r286837 = r286836 * r286812;
        double r286838 = 0.5;
        double r286839 = r286838 * r286827;
        double r286840 = fma(r286807, r286812, r286839);
        double r286841 = fma(r286834, r286837, r286840);
        double r286842 = r286811 + r286841;
        double r286843 = log(r286842);
        double r286844 = r286843 / r286819;
        double r286845 = r286810 - r286844;
        double r286846 = r286823 ? r286833 : r286845;
        double r286847 = r286809 ? r286821 : r286846;
        return r286847;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.6
Target16.0
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 3 regimes
  2. if z < -4.412489822281961e-82

    1. Initial program 16.2

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

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

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

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

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

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

    if -4.412489822281961e-82 < z < 1.5524150020171308e-104

    1. Initial program 31.0

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

      \[\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}\]
    3. Simplified5.0

      \[\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}\]

    if 1.5524150020171308e-104 < z

    1. Initial program 31.6

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

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

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

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

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

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

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

Reproduce

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