Average Error: 24.6 → 8.3
Time: 10.6s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -4.7189083472987007 \cdot 10^{-76}:\\ \;\;\;\;x - \frac{\log \left(1 + \left(\sqrt[3]{y \cdot \mathsf{expm1}\left(z\right)} \cdot \sqrt[3]{y \cdot \mathsf{expm1}\left(z\right)}\right) \cdot \sqrt[3]{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\\ \mathbf{elif}\;z \le 1.1800524692053243 \cdot 10^{-46}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}\\ \mathbf{elif}\;z \le 210.720453948241044:\\ \;\;\;\;x - \frac{1}{\frac{\frac{t}{2}}{\log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}}\\ \mathbf{else}:\\ \;\;\;\;x - \left(\left(\frac{y}{1} \cdot \frac{z}{t} + 2 \cdot \frac{\log \left(\sqrt{1}\right)}{t}\right) + \frac{\frac{1}{2} \cdot {z}^{2}}{1} \cdot \frac{y}{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 -4.7189083472987007 \cdot 10^{-76}:\\
\;\;\;\;x - \frac{\log \left(1 + \left(\sqrt[3]{y \cdot \mathsf{expm1}\left(z\right)} \cdot \sqrt[3]{y \cdot \mathsf{expm1}\left(z\right)}\right) \cdot \sqrt[3]{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\\

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

\mathbf{elif}\;z \le 210.720453948241044:\\
\;\;\;\;x - \frac{1}{\frac{\frac{t}{2}}{\log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}}\\

\mathbf{else}:\\
\;\;\;\;x - \left(\left(\frac{y}{1} \cdot \frac{z}{t} + 2 \cdot \frac{\log \left(\sqrt{1}\right)}{t}\right) + \frac{\frac{1}{2} \cdot {z}^{2}}{1} \cdot \frac{y}{t}\right)\\

\end{array}
double f(double x, double y, double z, double t) {
        double r252924 = x;
        double r252925 = 1.0;
        double r252926 = y;
        double r252927 = r252925 - r252926;
        double r252928 = z;
        double r252929 = exp(r252928);
        double r252930 = r252926 * r252929;
        double r252931 = r252927 + r252930;
        double r252932 = log(r252931);
        double r252933 = t;
        double r252934 = r252932 / r252933;
        double r252935 = r252924 - r252934;
        return r252935;
}

double f(double x, double y, double z, double t) {
        double r252936 = z;
        double r252937 = -4.718908347298701e-76;
        bool r252938 = r252936 <= r252937;
        double r252939 = x;
        double r252940 = 1.0;
        double r252941 = y;
        double r252942 = expm1(r252936);
        double r252943 = r252941 * r252942;
        double r252944 = cbrt(r252943);
        double r252945 = r252944 * r252944;
        double r252946 = r252945 * r252944;
        double r252947 = r252940 + r252946;
        double r252948 = log(r252947);
        double r252949 = t;
        double r252950 = r252948 / r252949;
        double r252951 = r252939 - r252950;
        double r252952 = 1.1800524692053243e-46;
        bool r252953 = r252936 <= r252952;
        double r252954 = 0.5;
        double r252955 = 2.0;
        double r252956 = pow(r252936, r252955);
        double r252957 = r252956 * r252941;
        double r252958 = r252936 * r252941;
        double r252959 = log(r252940);
        double r252960 = fma(r252940, r252958, r252959);
        double r252961 = fma(r252954, r252957, r252960);
        double r252962 = r252961 / r252949;
        double r252963 = r252939 - r252962;
        double r252964 = 210.72045394824104;
        bool r252965 = r252936 <= r252964;
        double r252966 = 1.0;
        double r252967 = r252949 / r252955;
        double r252968 = r252940 + r252943;
        double r252969 = sqrt(r252968);
        double r252970 = log(r252969);
        double r252971 = r252967 / r252970;
        double r252972 = r252966 / r252971;
        double r252973 = r252939 - r252972;
        double r252974 = r252941 / r252940;
        double r252975 = r252936 / r252949;
        double r252976 = r252974 * r252975;
        double r252977 = sqrt(r252940);
        double r252978 = log(r252977);
        double r252979 = r252978 / r252949;
        double r252980 = r252955 * r252979;
        double r252981 = r252976 + r252980;
        double r252982 = 0.5;
        double r252983 = r252982 * r252956;
        double r252984 = r252983 / r252940;
        double r252985 = r252941 / r252949;
        double r252986 = r252984 * r252985;
        double r252987 = r252981 + r252986;
        double r252988 = r252939 - r252987;
        double r252989 = r252965 ? r252973 : r252988;
        double r252990 = r252953 ? r252963 : r252989;
        double r252991 = r252938 ? r252951 : r252990;
        return r252991;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.6
Target16.0
Herbie8.3
\[\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 4 regimes
  2. if z < -4.718908347298701e-76

    1. Initial program 15.1

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

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

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

      \[\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-cbrt11.7

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

    if -4.718908347298701e-76 < z < 1.1800524692053243e-46

    1. Initial program 30.6

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

      \[\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.6

      \[\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.1800524692053243e-46 < z < 210.72045394824104

    1. Initial program 22.3

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

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

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

      \[\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-sqrt11.5

      \[\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-prod11.5

      \[\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}\]
    9. Using strategy rm
    10. Applied clear-num11.5

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

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

    if 210.72045394824104 < z

    1. Initial program 58.9

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

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

      \[\leadsto x - \frac{\log \color{blue}{\left(1 + \left(\left(-y\right) + y \cdot e^{z}\right)\right)}}{t}\]
    5. Simplified58.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-sqrt58.9

      \[\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-prod58.9

      \[\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}\]
    9. Taylor expanded around 0 34.4

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

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

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

Reproduce

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