Average Error: 20.4 → 5.5
Time: 2.5s
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 -1.3396749332313781 \cdot 10^{154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.35822598373593517 \cdot 10^{-156}:\\ \;\;\;\;\sqrt[3]{\sqrt[3]{{\left({\left(\frac{y + x}{x \cdot x + y \cdot y} \cdot \left(x - y\right)\right)}^{3}\right)}^{3}}}\\ \mathbf{elif}\;y \le 6.6501588139279482 \cdot 10^{-174}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.47259879968152251 \cdot 10^{-162}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{y + x}{x \cdot x + y \cdot y} \cdot \left(x - y\right)\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 -1.3396749332313781 \cdot 10^{154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -7.35822598373593517 \cdot 10^{-156}:\\
\;\;\;\;\sqrt[3]{\sqrt[3]{{\left({\left(\frac{y + x}{x \cdot x + y \cdot y} \cdot \left(x - y\right)\right)}^{3}\right)}^{3}}}\\

\mathbf{elif}\;y \le 6.6501588139279482 \cdot 10^{-174}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 2.47259879968152251 \cdot 10^{-162}:\\
\;\;\;\;-1\\

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

\end{array}
double code(double x, double y) {
	return (((double) (((double) (x - y)) * ((double) (x + y)))) / ((double) (((double) (x * x)) + ((double) (y * y)))));
}
double code(double x, double y) {
	double VAR;
	if ((y <= -1.3396749332313781e+154)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((y <= -7.358225983735935e-156)) {
			VAR_1 = ((double) cbrt(((double) cbrt(((double) pow(((double) pow(((double) ((((double) (y + x)) / ((double) (((double) (x * x)) + ((double) (y * y))))) * ((double) (x - y)))), 3.0)), 3.0))))));
		} else {
			double VAR_2;
			if ((y <= 6.650158813927948e-174)) {
				VAR_2 = 1.0;
			} else {
				double VAR_3;
				if ((y <= 2.4725987996815225e-162)) {
					VAR_3 = -1.0;
				} else {
					VAR_3 = ((double) cbrt(((double) pow(((double) ((((double) (y + x)) / ((double) (((double) (x * x)) + ((double) (y * y))))) * ((double) (x - y)))), 3.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.0
Herbie5.5
\[\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 < -1.3396749332313781e154 or 6.6501588139279482e-174 < y < 2.47259879968152251e-162

    1. Initial program 61.3

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

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

    if -1.3396749332313781e154 < y < -7.35822598373593517e-156

    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-cbrt-cube38.3

      \[\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-cube38.7

      \[\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-cube38.9

      \[\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-unprod38.8

      \[\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-undiv38.7

      \[\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.0

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\frac{x + y}{x \cdot x + y \cdot y} \cdot \left(x - y\right)\right)}^{3}}}\]
    9. Using strategy rm
    10. Applied add-cbrt-cube0.0

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

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

    if -7.35822598373593517e-156 < y < 6.6501588139279482e-174

    1. Initial program 29.5

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

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

    if 2.47259879968152251e-162 < y

    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-cbrt-cube35.6

      \[\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-cube35.7

      \[\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-cube35.8

      \[\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-unprod35.1

      \[\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.0

      \[\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.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3396749332313781 \cdot 10^{154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.35822598373593517 \cdot 10^{-156}:\\ \;\;\;\;\sqrt[3]{\sqrt[3]{{\left({\left(\frac{y + x}{x \cdot x + y \cdot y} \cdot \left(x - y\right)\right)}^{3}\right)}^{3}}}\\ \mathbf{elif}\;y \le 6.6501588139279482 \cdot 10^{-174}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.47259879968152251 \cdot 10^{-162}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{y + x}{x \cdot x + y \cdot y} \cdot \left(x - y\right)\right)}^{3}}\\ \end{array}\]

Reproduce

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