Average Error: 13.0 → 0.9
Time: 2.4s
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{x}{\frac{y}{y - z}}\\ \mathbf{if}\;t_0 \leq -5.479237903309544 \cdot 10^{+281}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_2 := x - \frac{x \cdot z}{y}\\ \mathbf{if}\;t_0 \leq -1.3096297358974076 \cdot 10^{-144}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;t_0 \leq 6.41878949445327 \cdot 10^{+301}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array}\\ \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{x}{\frac{y}{y - z}}\\
\mathbf{if}\;t_0 \leq -5.479237903309544 \cdot 10^{+281}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_2 := x - \frac{x \cdot z}{y}\\
\mathbf{if}\;t_0 \leq -1.3096297358974076 \cdot 10^{-144}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;x - \frac{z}{\frac{y}{x}}\\

\mathbf{elif}\;t_0 \leq 6.41878949445327 \cdot 10^{+301}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}\\


\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 (/ x (/ y (- y z)))))
   (if (<= t_0 -5.479237903309544e+281)
     t_1
     (let* ((t_2 (- x (/ (* x z) y))))
       (if (<= t_0 -1.3096297358974076e-144)
         t_2
         (if (<= t_0 0.0)
           (- x (/ z (/ y x)))
           (if (<= t_0 6.41878949445327e+301) t_2 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 = x / (y / (y - z));
	double tmp;
	if (t_0 <= -5.479237903309544e+281) {
		tmp = t_1;
	} else {
		double t_2 = x - ((x * z) / y);
		double tmp_1;
		if (t_0 <= -1.3096297358974076e-144) {
			tmp_1 = t_2;
		} else if (t_0 <= 0.0) {
			tmp_1 = x - (z / (y / x));
		} else if (t_0 <= 6.41878949445327e+301) {
			tmp_1 = t_2;
		} else {
			tmp_1 = t_1;
		}
		tmp = tmp_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

Original13.0
Target3.2
Herbie0.9
\[\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) < -5.4792379033095441e281 or 6.4187894944532703e301 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 57.9

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

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

    if -5.4792379033095441e281 < (/.f64 (*.f64 x (-.f64 y z)) y) < -1.3096297358974076e-144 or -0.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < 6.4187894944532703e301

    1. Initial program 0.4

      \[\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.3096297358974076e-144 < (/.f64 (*.f64 x (-.f64 y z)) y) < -0.0

    1. Initial program 20.5

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

      \[\leadsto \color{blue}{x - \frac{z \cdot x}{y}} \]
    3. Applied associate-/l*_binary643.6

      \[\leadsto x - \color{blue}{\frac{z}{\frac{y}{x}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq -5.479237903309544 \cdot 10^{+281}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq -1.3096297358974076 \cdot 10^{-144}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 0:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 6.41878949445327 \cdot 10^{+301}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \end{array} \]

Reproduce

herbie shell --seed 2021280 
(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))