Average Error: 25.5 → 11.1
Time: 7.7s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;y \le -2045829589.78826594:\\ \;\;\;\;x - \log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right) \cdot \frac{1}{t}\\ \mathbf{elif}\;y \le -2.33715474181218539 \cdot 10^{-79}:\\ \;\;\;\;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}\;y \le 0.509833754303126052:\\ \;\;\;\;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}\;y \le 3.45567648289861118 \cdot 10^{68}:\\ \;\;\;\;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{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}\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;y \le -2045829589.78826594:\\
\;\;\;\;x - \log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right) \cdot \frac{1}{t}\\

\mathbf{elif}\;y \le -2.33715474181218539 \cdot 10^{-79}:\\
\;\;\;\;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}\;y \le 0.509833754303126052:\\
\;\;\;\;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}\;y \le 3.45567648289861118 \cdot 10^{68}:\\
\;\;\;\;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{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}\\

\end{array}
double code(double x, double y, double z, double t) {
	return (x - (log(((1.0 - y) + (y * exp(z)))) / t));
}
double code(double x, double y, double z, double t) {
	double VAR;
	if ((y <= -2045829589.788266)) {
		VAR = (x - (log((1.0 + (y * expm1(z)))) * (1.0 / t)));
	} else {
		double VAR_1;
		if ((y <= -2.3371547418121854e-79)) {
			VAR_1 = (x - (fma(0.5, (pow(z, 2.0) * y), fma(1.0, (z * y), log(1.0))) / t));
		} else {
			double VAR_2;
			if ((y <= 0.509833754303126)) {
				VAR_2 = (x - ((log(sqrt((1.0 + (y * expm1(z))))) + log(sqrt((1.0 + (y * expm1(z)))))) / t));
			} else {
				double VAR_3;
				if ((y <= 3.455676482898611e+68)) {
					VAR_3 = (x - (fma(0.5, (pow(z, 2.0) * y), fma(1.0, (z * y), log(1.0))) / t));
				} else {
					VAR_3 = (x - (((2.0 * log(cbrt((1.0 + (y * expm1(z)))))) + log(cbrt((1.0 + (y * expm1(z)))))) / t));
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.5
Target16.6
Herbie11.1
\[\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 y < -2045829589.788266

    1. Initial program 37.3

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Using strategy rm
    3. Applied sub-neg37.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. Simplified9.0

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

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

    if -2045829589.788266 < y < -2.3371547418121854e-79 or 0.509833754303126 < y < 3.455676482898611e+68

    1. Initial program 28.6

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

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

      \[\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 -2.3371547418121854e-79 < y < 0.509833754303126

    1. Initial program 11.7

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

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

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

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

      \[\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 3.455676482898611e+68 < y

    1. Initial program 61.7

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

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

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

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

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

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

      \[\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}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification11.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2045829589.78826594:\\ \;\;\;\;x - \log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right) \cdot \frac{1}{t}\\ \mathbf{elif}\;y \le -2.33715474181218539 \cdot 10^{-79}:\\ \;\;\;\;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}\;y \le 0.509833754303126052:\\ \;\;\;\;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}\;y \le 3.45567648289861118 \cdot 10^{68}:\\ \;\;\;\;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{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}\\ \end{array}\]

Reproduce

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