Average Error: 25.7 → 0.3
Time: 21.1s
Precision: binary64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
\[\begin{array}{l} t_1 := \left(1 - y\right) + y \cdot e^{z}\\ \mathbf{if}\;t_1 \leq 0.9999999999999987:\\ \;\;\;\;x - \mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right) \cdot \frac{1}{t}\\ \mathbf{elif}\;t_1 \leq 1:\\ \;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_2 := \sqrt[3]{\mathsf{expm1}\left(z\right)}\\ x - \frac{\mathsf{log1p}\left(t_2 \cdot \left(y \cdot \left(t_2 \cdot t_2\right)\right)\right)}{t} \end{array}\\ \end{array} \]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
t_1 := \left(1 - y\right) + y \cdot e^{z}\\
\mathbf{if}\;t_1 \leq 0.9999999999999987:\\
\;\;\;\;x - \mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right) \cdot \frac{1}{t}\\

\mathbf{elif}\;t_1 \leq 1:\\
\;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_2 := \sqrt[3]{\mathsf{expm1}\left(z\right)}\\
x - \frac{\mathsf{log1p}\left(t_2 \cdot \left(y \cdot \left(t_2 \cdot t_2\right)\right)\right)}{t}
\end{array}\\


\end{array}
(FPCore (x y z t)
 :precision binary64
 (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ (- 1.0 y) (* y (exp z)))))
   (if (<= t_1 0.9999999999999987)
     (- x (* (log1p (* y (expm1 z))) (/ 1.0 t)))
     (if (<= t_1 1.0)
       (- x (* (expm1 z) (/ y t)))
       (let* ((t_2 (cbrt (expm1 z))))
         (- x (/ (log1p (* t_2 (* y (* t_2 t_2)))) t)))))))
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 t_1 = (1.0 - y) + (y * exp(z));
	double tmp;
	if (t_1 <= 0.9999999999999987) {
		tmp = x - (log1p(y * expm1(z)) * (1.0 / t));
	} else if (t_1 <= 1.0) {
		tmp = x - (expm1(z) * (y / t));
	} else {
		double t_2 = cbrt(expm1(z));
		tmp = x - (log1p(t_2 * (y * (t_2 * t_2))) / t);
	}
	return tmp;
}

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.7
Target16.7
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;z < -2.8874623088207947 \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 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z))) < 0.99999999999999867

    1. Initial program 63.0

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Simplified0.1

      \[\leadsto \color{blue}{x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}} \]
    3. Applied div-inv_binary640.1

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

    if 0.99999999999999867 < (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z))) < 1

    1. Initial program 13.0

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Simplified1.2

      \[\leadsto \color{blue}{x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}} \]
    3. Applied add-cube-cbrt_binary641.4

      \[\leadsto x - \color{blue}{\left(\sqrt[3]{\frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}} \cdot \sqrt[3]{\frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}}\right) \cdot \sqrt[3]{\frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}}} \]
    4. Taylor expanded in y around 0 6.6

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

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

    if 1 < (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))

    1. Initial program 3.5

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Simplified2.2

      \[\leadsto \color{blue}{x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}} \]
    3. Applied add-cube-cbrt_binary642.2

      \[\leadsto x - \frac{\mathsf{log1p}\left(y \cdot \color{blue}{\left(\left(\sqrt[3]{\mathsf{expm1}\left(z\right)} \cdot \sqrt[3]{\mathsf{expm1}\left(z\right)}\right) \cdot \sqrt[3]{\mathsf{expm1}\left(z\right)}\right)}\right)}{t} \]
    4. Applied associate-*r*_binary642.2

      \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\left(y \cdot \left(\sqrt[3]{\mathsf{expm1}\left(z\right)} \cdot \sqrt[3]{\mathsf{expm1}\left(z\right)}\right)\right) \cdot \sqrt[3]{\mathsf{expm1}\left(z\right)}}\right)}{t} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(1 - y\right) + y \cdot e^{z} \leq 0.9999999999999987:\\ \;\;\;\;x - \mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right) \cdot \frac{1}{t}\\ \mathbf{elif}\;\left(1 - y\right) + y \cdot e^{z} \leq 1:\\ \;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{log1p}\left(\sqrt[3]{\mathsf{expm1}\left(z\right)} \cdot \left(y \cdot \left(\sqrt[3]{\mathsf{expm1}\left(z\right)} \cdot \sqrt[3]{\mathsf{expm1}\left(z\right)}\right)\right)\right)}{t}\\ \end{array} \]

Reproduce

herbie shell --seed 2022077 
(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.0 z) (* z z)))) (- x (/ (log (+ 1.0 (* z y))) t)))

  (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))