Average Error: 14.8 → 0.2
Time: 1.8s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.390909119607474 \cdot 10^{-45} \lor \neg \left(x \le 7.09985068380016666 \cdot 10^{-27}\right):\\ \;\;\;\;\frac{x}{x - y} \cdot \left(y \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \left(y \cdot \frac{1}{x - y}\right)\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -1.390909119607474 \cdot 10^{-45} \lor \neg \left(x \le 7.09985068380016666 \cdot 10^{-27}\right):\\
\;\;\;\;\frac{x}{x - y} \cdot \left(y \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot 2\right) \cdot \left(y \cdot \frac{1}{x - y}\right)\\

\end{array}
double code(double x, double y) {
	return (((x * 2.0) * y) / (x - y));
}
double code(double x, double y) {
	double temp;
	if (((x <= -1.390909119607474e-45) || !(x <= 7.099850683800167e-27))) {
		temp = ((x / (x - y)) * (y * 2.0));
	} else {
		temp = ((x * 2.0) * (y * (1.0 / (x - y))));
	}
	return temp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.8
Target0.4
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;x \lt -1.7210442634149447 \cdot 10^{81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \lt 83645045635564432:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -1.390909119607474e-45 or 7.099850683800167e-27 < x

    1. Initial program 14.4

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied associate-/l*13.0

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied div-inv13.2

      \[\leadsto \frac{x \cdot 2}{\color{blue}{\left(x - y\right) \cdot \frac{1}{y}}}\]
    6. Applied times-frac0.4

      \[\leadsto \color{blue}{\frac{x}{x - y} \cdot \frac{2}{\frac{1}{y}}}\]
    7. Simplified0.3

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

    if -1.390909119607474e-45 < x < 7.099850683800167e-27

    1. Initial program 15.4

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity15.4

      \[\leadsto \frac{\left(x \cdot 2\right) \cdot y}{\color{blue}{1 \cdot \left(x - y\right)}}\]
    4. Applied times-frac0.0

      \[\leadsto \color{blue}{\frac{x \cdot 2}{1} \cdot \frac{y}{x - y}}\]
    5. Simplified0.0

      \[\leadsto \color{blue}{\left(x \cdot 2\right)} \cdot \frac{y}{x - y}\]
    6. Using strategy rm
    7. Applied div-inv0.2

      \[\leadsto \left(x \cdot 2\right) \cdot \color{blue}{\left(y \cdot \frac{1}{x - y}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.390909119607474 \cdot 10^{-45} \lor \neg \left(x \le 7.09985068380016666 \cdot 10^{-27}\right):\\ \;\;\;\;\frac{x}{x - y} \cdot \left(y \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \left(y \cdot \frac{1}{x - y}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020057 +o rules:numerics
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"
  :precision binary64

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2 x) (- x y)) y) (if (< x 83645045635564432) (/ (* x 2) (/ (- x y) y)) (* (/ (* 2 x) (- x y)) y)))

  (/ (* (* x 2) y) (- x y)))