Average Error: 20.1 → 5.6
Time: 2.7s
Precision: binary64
\[0.0 \lt x \lt 1 \land y \lt 1\]
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -4.75850372698848152 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.3410769194630859 \cdot 10^{-140}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le 3.58789802840366625 \cdot 10^{-232}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.6348364519402426 \cdot 10^{-211}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.29090338816018215 \cdot 10^{-163}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \end{array}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -4.75850372698848152 \cdot 10^{153}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -2.3410769194630859 \cdot 10^{-140}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}\\

\mathbf{elif}\;y \le 3.58789802840366625 \cdot 10^{-232}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 2.6348364519402426 \cdot 10^{-211}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 1.29090338816018215 \cdot 10^{-163}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\

\end{array}
double code(double x, double y) {
	return ((double) (((double) (((double) (x - y)) * ((double) (x + y)))) / ((double) (((double) (x * x)) + ((double) (y * y))))));
}
double code(double x, double y) {
	double VAR;
	if ((y <= -4.7585037269884815e+153)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((y <= -2.341076919463086e-140)) {
			VAR_1 = ((double) (((double) (((double) (x - y)) * ((double) (x + y)))) / ((double) (((double) sqrt(((double) (((double) (x * x)) + ((double) (y * y)))))) * ((double) sqrt(((double) (((double) (x * x)) + ((double) (y * y))))))))));
		} else {
			double VAR_2;
			if ((y <= 3.587898028403666e-232)) {
				VAR_2 = 1.0;
			} else {
				double VAR_3;
				if ((y <= 2.6348364519402426e-211)) {
					VAR_3 = -1.0;
				} else {
					double VAR_4;
					if ((y <= 1.2909033881601822e-163)) {
						VAR_4 = 1.0;
					} else {
						VAR_4 = ((double) cbrt(((double) pow(((double) (((double) (((double) (x - y)) * ((double) (x + y)))) / ((double) (((double) (x * x)) + ((double) (y * y)))))), 3.0))));
					}
					VAR_3 = VAR_4;
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.1
Target0.1
Herbie5.6
\[\begin{array}{l} \mathbf{if}\;0.5 \lt \left|\frac{x}{y}\right| \lt 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if y < -4.75850372698848152e153 or 3.58789802840366625e-232 < y < 2.6348364519402426e-211

    1. Initial program 60.5

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

      \[\leadsto \color{blue}{-1}\]

    if -4.75850372698848152e153 < y < -2.3410769194630859e-140

    1. Initial program 0.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.0

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

    if -2.3410769194630859e-140 < y < 3.58789802840366625e-232 or 2.6348364519402426e-211 < y < 1.29090338816018215e-163

    1. Initial program 27.1

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

      \[\leadsto \color{blue}{1}\]

    if 1.29090338816018215e-163 < y

    1. Initial program 0.2

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-cbrt-cube36.5

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}}\]
    4. Applied add-cbrt-cube36.5

      \[\leadsto \frac{\left(x - y\right) \cdot \color{blue}{\sqrt[3]{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    5. Applied add-cbrt-cube36.7

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(x - y\right) \cdot \left(x - y\right)\right) \cdot \left(x - y\right)}} \cdot \sqrt[3]{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    6. Applied cbrt-unprod36.0

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(\left(x - y\right) \cdot \left(x - y\right)\right) \cdot \left(x - y\right)\right) \cdot \left(\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)\right)}}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    7. Applied cbrt-undiv35.9

      \[\leadsto \color{blue}{\sqrt[3]{\frac{\left(\left(\left(x - y\right) \cdot \left(x - y\right)\right) \cdot \left(x - y\right)\right) \cdot \left(\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)\right)}{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}}\]
    8. Simplified0.2

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -4.75850372698848152 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.3410769194630859 \cdot 10^{-140}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le 3.58789802840366625 \cdot 10^{-232}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.6348364519402426 \cdot 10^{-211}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.29090338816018215 \cdot 10^{-163}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020150 
(FPCore (x y)
  :name "Kahan p9 Example"
  :precision binary64
  :pre (and (< 0.0 x 1.0) (< y 1.0))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))