Average Error: 12.3 → 1.7
Time: 2.8s
Precision: binary64
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ t_1 := \frac{y}{y - z}\\ \mathbf{if}\;t_0 \leq 4.628153082683992 \cdot 10^{-8}:\\ \;\;\;\;\frac{x}{t_1}\\ \mathbf{elif}\;t_0 \leq 1.6573330669499205 \cdot 10^{+300}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\mathsf{log1p}\left(\mathsf{expm1}\left(t_1\right)\right)}\\ \end{array} \]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y - z\right)}{y}\\
t_1 := \frac{y}{y - z}\\
\mathbf{if}\;t_0 \leq 4.628153082683992 \cdot 10^{-8}:\\
\;\;\;\;\frac{x}{t_1}\\

\mathbf{elif}\;t_0 \leq 1.6573330669499205 \cdot 10^{+300}:\\
\;\;\;\;x - \frac{x \cdot z}{y}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\mathsf{log1p}\left(\mathsf{expm1}\left(t_1\right)\right)}\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (* x (- y z)) y)) (t_1 (/ y (- y z))))
   (if (<= t_0 4.628153082683992e-8)
     (/ x t_1)
     (if (<= t_0 1.6573330669499205e+300)
       (- x (/ (* x z) y))
       (/ x (log1p (expm1 t_1)))))))
double code(double x, double y, double z) {
	return (x * (y - z)) / y;
}
double code(double x, double y, double z) {
	double t_0 = (x * (y - z)) / y;
	double t_1 = y / (y - z);
	double tmp;
	if (t_0 <= 4.628153082683992e-8) {
		tmp = x / t_1;
	} else if (t_0 <= 1.6573330669499205e+300) {
		tmp = x - ((x * z) / y);
	} else {
		tmp = x / log1p(expm1(t_1));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.3
Target2.9
Herbie1.7
\[\begin{array}{l} \mathbf{if}\;z < -2.060202331921739 \cdot 10^{+104}:\\ \;\;\;\;x - \frac{z \cdot x}{y}\\ \mathbf{elif}\;z < 1.6939766013828526 \cdot 10^{+213}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < 4.62815308268399195e-8

    1. Initial program 10.6

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Applied associate-/l*_binary642.2

      \[\leadsto \color{blue}{\frac{x}{\frac{y}{y - z}}} \]
    3. Applied *-un-lft-identity_binary642.2

      \[\leadsto \frac{x}{\color{blue}{1 \cdot \frac{y}{y - z}}} \]
    4. Applied associate-/r*_binary642.2

      \[\leadsto \color{blue}{\frac{\frac{x}{1}}{\frac{y}{y - z}}} \]

    if 4.62815308268399195e-8 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.65733306694992055e300

    1. Initial program 0.2

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Taylor expanded in y around 0 0.2

      \[\leadsto \color{blue}{x - \frac{z \cdot x}{y}} \]

    if 1.65733306694992055e300 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 60.4

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Applied associate-/l*_binary640.9

      \[\leadsto \color{blue}{\frac{x}{\frac{y}{y - z}}} \]
    3. Applied log1p-expm1-u_binary640.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq 4.628153082683992 \cdot 10^{-8}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 1.6573330669499205 \cdot 10^{+300}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{y}{y - z}\right)\right)}\\ \end{array} \]

Reproduce

herbie shell --seed 2021313 
(FPCore (x y z)
  :name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))

  (/ (* x (- y z)) y))