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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r280126 = x;
        double r280127 = 1.0;
        double r280128 = y;
        double r280129 = r280127 - r280128;
        double r280130 = z;
        double r280131 = exp(r280130);
        double r280132 = r280128 * r280131;
        double r280133 = r280129 + r280132;
        double r280134 = log(r280133);
        double r280135 = t;
        double r280136 = r280134 / r280135;
        double r280137 = r280126 - r280136;
        return r280137;
}

double f(double x, double y, double z, double t) {
        double r280138 = z;
        double r280139 = -1.8224838885264432e-106;
        bool r280140 = r280138 <= r280139;
        double r280141 = x;
        double r280142 = 1.0;
        double r280143 = 1.0;
        double r280144 = y;
        double r280145 = expm1(r280138);
        double r280146 = r280144 * r280145;
        double r280147 = r280143 + r280146;
        double r280148 = log(r280147);
        double r280149 = t;
        double r280150 = r280148 / r280149;
        double r280151 = r280142 * r280150;
        double r280152 = r280141 - r280151;
        double r280153 = 0.5;
        double r280154 = 2.0;
        double r280155 = pow(r280138, r280154);
        double r280156 = r280155 * r280144;
        double r280157 = r280138 * r280144;
        double r280158 = log(r280143);
        double r280159 = fma(r280143, r280157, r280158);
        double r280160 = fma(r280153, r280156, r280159);
        double r280161 = r280149 / r280160;
        double r280162 = r280142 / r280161;
        double r280163 = r280141 - r280162;
        double r280164 = r280140 ? r280152 : r280163;
        return r280164;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.1
Target16.4
Herbie8.6
\[\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 < -1.8224838885264432e-106

    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.7

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

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

      \[\leadsto x - \frac{1}{\color{blue}{t \cdot \frac{1}{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}}\]
    10. Applied associate-/r*11.8

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

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

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

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

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

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

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

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

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

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

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

    if -1.8224838885264432e-106 < z

    1. Initial program 31.3

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

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

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

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

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

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

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

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

Reproduce

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