Average Error: 12.7 → 0.2
Time: 3.2s
Precision: binary64
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := x - \frac{x \cdot z}{y}\\ t_1 := \frac{x \cdot \left(y - z\right)}{y}\\ t_2 := x \cdot \frac{y - z}{y}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq -3.9680877061023717 \cdot 10^{-53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;t_1 \leq 9.966738429679642 \cdot 10^{+297}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := x - \frac{x \cdot z}{y}\\
t_1 := \frac{x \cdot \left(y - z\right)}{y}\\
t_2 := x \cdot \frac{y - z}{y}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq -3.9680877061023717 \cdot 10^{-53}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;t_1 \leq 9.966738429679642 \cdot 10^{+297}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- x (/ (* x z) y)))
        (t_1 (/ (* x (- y z)) y))
        (t_2 (* x (/ (- y z) y))))
   (if (<= t_1 (- INFINITY))
     t_2
     (if (<= t_1 -3.9680877061023717e-53)
       t_0
       (if (<= t_1 0.0)
         (/ x (/ y (- y z)))
         (if (<= t_1 9.966738429679642e+297) t_0 t_2))))))
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 - ((x * z) / y);
	double t_1 = (x * (y - z)) / y;
	double t_2 = x * ((y - z) / y);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = t_2;
	} else if (t_1 <= -3.9680877061023717e-53) {
		tmp = t_0;
	} else if (t_1 <= 0.0) {
		tmp = x / (y / (y - z));
	} else if (t_1 <= 9.966738429679642e+297) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	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.7
Target2.9
Herbie0.2
\[\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) < -inf.0 or 9.9667384296796421e297 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 62.3

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Applied egg-rr0.6

      \[\leadsto \color{blue}{x \cdot \left(\left(y - z\right) \cdot \frac{1}{y}\right)} \]
    3. Applied egg-rr0.4

      \[\leadsto x \cdot \color{blue}{\left(0 + \frac{y - z}{y}\right)} \]

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -3.96808770610237167e-53 or -0.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < 9.9667384296796421e297

    1. Initial program 0.3

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

    1. Initial program 14.8

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Applied egg-rr0.1

      \[\leadsto \color{blue}{\frac{x}{1} \cdot \frac{y - z}{y}} \]
    3. Applied egg-rr0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq -\infty:\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq -3.9680877061023717 \cdot 10^{-53}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 0:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 9.966738429679642 \cdot 10^{+297}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \end{array} \]

Reproduce

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