Average Error: 20.4 → 8.9
Time: 3.3s
Precision: 64
\[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 -2.2208938072286916 \cdot 10^{-30}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.3739560176803406 \cdot 10^{-160}:\\ \;\;\;\;e^{e^{\log \left(\log \left(x - y\right) + \left(-2 \cdot \log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)\right)\right)}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le -4.89796425683335106 \cdot 10^{-179}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 7.00176504920879174 \cdot 10^{-156}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \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 -2.2208938072286916 \cdot 10^{-30}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -7.3739560176803406 \cdot 10^{-160}:\\
\;\;\;\;e^{e^{\log \left(\log \left(x - y\right) + \left(-2 \cdot \log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)\right)\right)}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}\\

\mathbf{elif}\;y \le -4.89796425683335106 \cdot 10^{-179}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 7.00176504920879174 \cdot 10^{-156}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;-1\\

\end{array}
double code(double x, double y) {
	return (((x - y) * (x + y)) / ((x * x) + (y * y)));
}
double code(double x, double y) {
	double VAR;
	if ((y <= -2.2208938072286916e-30)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((y <= -7.37395601768034e-160)) {
			VAR_1 = (exp(exp(log((log((x - y)) + -(2.0 * log(cbrt(((x * x) + (y * y))))))))) * ((x + y) / cbrt(((x * x) + (y * y)))));
		} else {
			double VAR_2;
			if ((y <= -4.897964256833351e-179)) {
				VAR_2 = -1.0;
			} else {
				double VAR_3;
				if ((y <= 7.001765049208792e-156)) {
					VAR_3 = 1.0;
				} else {
					VAR_3 = -1.0;
				}
				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.4
Target0.1
Herbie8.9
\[\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 3 regimes
  2. if y < -2.2208938072286916e-30 or -7.37395601768034e-160 < y < -4.897964256833351e-179 or 7.001765049208792e-156 < y

    1. Initial program 20.0

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

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

    if -2.2208938072286916e-30 < y < -7.37395601768034e-160

    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-cube-cbrt1.3

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

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt[3]{x \cdot x + y \cdot y} \cdot \sqrt[3]{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}}\]
    5. Using strategy rm
    6. Applied add-exp-log4.4

      \[\leadsto \frac{x - y}{\sqrt[3]{x \cdot x + y \cdot y} \cdot \color{blue}{e^{\log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)}}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}\]
    7. Applied add-exp-log5.3

      \[\leadsto \frac{x - y}{\color{blue}{e^{\log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)}} \cdot e^{\log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}\]
    8. Applied prod-exp5.3

      \[\leadsto \frac{x - y}{\color{blue}{e^{\log \left(\sqrt[3]{x \cdot x + y \cdot y}\right) + \log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)}}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}\]
    9. Applied add-exp-log5.5

      \[\leadsto \frac{\color{blue}{e^{\log \left(x - y\right)}}}{e^{\log \left(\sqrt[3]{x \cdot x + y \cdot y}\right) + \log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}\]
    10. Applied div-exp5.5

      \[\leadsto \color{blue}{e^{\log \left(x - y\right) - \left(\log \left(\sqrt[3]{x \cdot x + y \cdot y}\right) + \log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)\right)}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}\]
    11. Simplified5.5

      \[\leadsto e^{\color{blue}{\log \left(x - y\right) + \left(-2 \cdot \log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)\right)}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}\]
    12. Using strategy rm
    13. Applied add-exp-log5.8

      \[\leadsto e^{\color{blue}{e^{\log \left(\log \left(x - y\right) + \left(-2 \cdot \log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)\right)\right)}}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}\]

    if -4.897964256833351e-179 < y < 7.001765049208792e-156

    1. Initial program 30.2

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

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.2208938072286916 \cdot 10^{-30}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.3739560176803406 \cdot 10^{-160}:\\ \;\;\;\;e^{e^{\log \left(\log \left(x - y\right) + \left(-2 \cdot \log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)\right)\right)}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le -4.89796425683335106 \cdot 10^{-179}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 7.00176504920879174 \cdot 10^{-156}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1 (/ 2 (+ 1 (* (/ x y) (/ x y))))))

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