Average Error: 15.4 → 3.9
Time: 4.3s
Precision: binary64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \leq -1.9395487420113406 \cdot 10^{-117}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;y \leq 2.068588027991875 \cdot 10^{-183}:\\ \;\;\;\;2 \cdot \frac{{y}^{2}}{x} + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \leq -1.9395487420113406 \cdot 10^{-117}:\\
\;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\

\mathbf{elif}\;y \leq 2.068588027991875 \cdot 10^{-183}:\\
\;\;\;\;2 \cdot \frac{{y}^{2}}{x} + y \cdot 2\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\

\end{array}
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
(FPCore (x y)
 :precision binary64
 (if (<= y -1.9395487420113406e-117)
   (* (* x 2.0) (/ y (- x y)))
   (if (<= y 2.068588027991875e-183)
     (+ (* 2.0 (/ (pow y 2.0) x)) (* y 2.0))
     (/ (* x 2.0) (/ (- x y) y)))))
double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
double code(double x, double y) {
	double tmp;
	if (y <= -1.9395487420113406e-117) {
		tmp = (x * 2.0) * (y / (x - y));
	} else if (y <= 2.068588027991875e-183) {
		tmp = (2.0 * (pow(y, 2.0) / x)) + (y * 2.0);
	} else {
		tmp = (x * 2.0) / ((x - y) / y);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.4
Target0.4
Herbie3.9
\[\begin{array}{l} \mathbf{if}\;x < -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x < 8.364504563556443 \cdot 10^{+16}:\\ \;\;\;\;\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 3 regimes
  2. if y < -1.93954874201134064e-117

    1. Initial program 14.0

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

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

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

    if -1.93954874201134064e-117 < y < 2.0685880279918749e-183

    1. Initial program 20.2

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Taylor expanded around inf 8.6

      \[\leadsto \color{blue}{2 \cdot \frac{{y}^{2}}{x} + 2 \cdot y}\]

    if 2.0685880279918749e-183 < y

    1. Initial program 13.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.9395487420113406 \cdot 10^{-117}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;y \leq 2.068588027991875 \cdot 10^{-183}:\\ \;\;\;\;2 \cdot \frac{{y}^{2}}{x} + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \end{array}\]

Reproduce

herbie shell --seed 2021093 
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"
  :precision binary64

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 8.364504563556443e+16) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))

  (/ (* (* x 2.0) y) (- x y)))