Kahan p9 Example

Percentage Accurate: 68.6% → 100.0%
Time: 8.0s
Alternatives: 10
Speedup: 2.9×

Specification

?
\[\left(0 < x \land x < 1\right) \land y < 1\]
\[\begin{array}{l} \\ \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \end{array} \]
(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
double code(double x, double y) {
	return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x - y) * (x + y)) / ((x * x) + (y * y))
end function
public static double code(double x, double y) {
	return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
def code(x, y):
	return ((x - y) * (x + y)) / ((x * x) + (y * y))
function code(x, y)
	return Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)))
end
function tmp = code(x, y)
	tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 68.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \end{array} \]
(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
double code(double x, double y) {
	return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x - y) * (x + y)) / ((x * x) + (y * y))
end function
public static double code(double x, double y) {
	return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
def code(x, y):
	return ((x - y) * (x + y)) / ((x * x) + (y * y))
function code(x, y)
	return Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)))
end
function tmp = code(x, y)
	tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\end{array}

Alternative 1: 100.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \end{array} \]
(FPCore (x y)
 :precision binary64
 (/ (/ (- x y) (hypot x y)) (/ (hypot x y) (+ x y))))
double code(double x, double y) {
	return ((x - y) / hypot(x, y)) / (hypot(x, y) / (x + y));
}
public static double code(double x, double y) {
	return ((x - y) / Math.hypot(x, y)) / (Math.hypot(x, y) / (x + y));
}
def code(x, y):
	return ((x - y) / math.hypot(x, y)) / (math.hypot(x, y) / (x + y))
function code(x, y)
	return Float64(Float64(Float64(x - y) / hypot(x, y)) / Float64(hypot(x, y) / Float64(x + y)))
end
function tmp = code(x, y)
	tmp = ((x - y) / hypot(x, y)) / (hypot(x, y) / (x + y));
end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}
\end{array}
Derivation
  1. Initial program 67.5%

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
  2. Step-by-step derivation
    1. add-sqr-sqrt67.5%

      \[\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}}} \]
    2. times-frac67.5%

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}} \]
    3. hypot-def67.5%

      \[\leadsto \frac{x - y}{\color{blue}{\mathsf{hypot}\left(x, y\right)}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}} \]
    4. hypot-def99.9%

      \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\color{blue}{\mathsf{hypot}\left(x, y\right)}} \]
  3. Applied egg-rr99.9%

    \[\leadsto \color{blue}{\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}} \]
  4. Step-by-step derivation
    1. clear-num99.9%

      \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
    2. un-div-inv100.0%

      \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
  5. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
  6. Final simplification100.0%

    \[\leadsto \frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]

Alternative 2: 99.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)} \end{array} \]
(FPCore (x y)
 :precision binary64
 (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y))))
double code(double x, double y) {
	return ((x - y) / hypot(x, y)) * ((x + y) / hypot(x, y));
}
public static double code(double x, double y) {
	return ((x - y) / Math.hypot(x, y)) * ((x + y) / Math.hypot(x, y));
}
def code(x, y):
	return ((x - y) / math.hypot(x, y)) * ((x + y) / math.hypot(x, y))
function code(x, y)
	return Float64(Float64(Float64(x - y) / hypot(x, y)) * Float64(Float64(x + y) / hypot(x, y)))
end
function tmp = code(x, y)
	tmp = ((x - y) / hypot(x, y)) * ((x + y) / hypot(x, y));
end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Derivation
  1. Initial program 67.5%

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
  2. Step-by-step derivation
    1. add-sqr-sqrt67.5%

      \[\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}}} \]
    2. times-frac67.5%

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}} \]
    3. hypot-def67.5%

      \[\leadsto \frac{x - y}{\color{blue}{\mathsf{hypot}\left(x, y\right)}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}} \]
    4. hypot-def99.9%

      \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\color{blue}{\mathsf{hypot}\left(x, y\right)}} \]
  3. Applied egg-rr99.9%

    \[\leadsto \color{blue}{\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}} \]
  4. Final simplification99.9%

    \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)} \]

Alternative 3: 92.7% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{if}\;t_0 \leq 2:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
   (if (<= t_0 2.0) t_0 (fma 2.0 (* (/ x y) (/ x y)) -1.0))))
double code(double x, double y) {
	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	double tmp;
	if (t_0 <= 2.0) {
		tmp = t_0;
	} else {
		tmp = fma(2.0, ((x / y) * (x / y)), -1.0);
	}
	return tmp;
}
function code(x, y)
	t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)))
	tmp = 0.0
	if (t_0 <= 2.0)
		tmp = t_0;
	else
		tmp = fma(2.0, Float64(Float64(x / y) * Float64(x / y)), -1.0);
	end
	return tmp
end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(2.0 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2

    1. Initial program 99.9%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]

    if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y)))

    1. Initial program 0.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/3.1%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def3.1%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified3.1%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in x around 0 55.4%

      \[\leadsto \color{blue}{2 \cdot \frac{{x}^{2}}{{y}^{2}} - 1} \]
    5. Step-by-step derivation
      1. fma-neg55.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(2, \frac{{x}^{2}}{{y}^{2}}, -1\right)} \]
      2. unpow255.4%

        \[\leadsto \mathsf{fma}\left(2, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right) \]
      3. unpow255.4%

        \[\leadsto \mathsf{fma}\left(2, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right) \]
      4. times-frac77.5%

        \[\leadsto \mathsf{fma}\left(2, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right) \]
      5. metadata-eval77.5%

        \[\leadsto \mathsf{fma}\left(2, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right) \]
    6. Simplified77.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \leq 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \end{array} \]

Alternative 4: 92.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{if}\;t_0 \leq 2:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x + y}{y}}{\frac{y}{x - y}}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
   (if (<= t_0 2.0) t_0 (/ (/ (+ x y) y) (/ y (- x y))))))
double code(double x, double y) {
	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	double tmp;
	if (t_0 <= 2.0) {
		tmp = t_0;
	} else {
		tmp = ((x + y) / y) / (y / (x - y));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
    if (t_0 <= 2.0d0) then
        tmp = t_0
    else
        tmp = ((x + y) / y) / (y / (x - y))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	double tmp;
	if (t_0 <= 2.0) {
		tmp = t_0;
	} else {
		tmp = ((x + y) / y) / (y / (x - y));
	}
	return tmp;
}
def code(x, y):
	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
	tmp = 0
	if t_0 <= 2.0:
		tmp = t_0
	else:
		tmp = ((x + y) / y) / (y / (x - y))
	return tmp
function code(x, y)
	t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)))
	tmp = 0.0
	if (t_0 <= 2.0)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(x + y) / y) / Float64(y / Float64(x - y)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	tmp = 0.0;
	if (t_0 <= 2.0)
		tmp = t_0;
	else
		tmp = ((x + y) / y) / (y / (x - y));
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision] / N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{x + y}{y}}{\frac{y}{x - y}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2

    1. Initial program 99.9%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]

    if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y)))

    1. Initial program 0.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/3.1%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def3.1%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified3.1%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in x around 0 3.1%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{{y}^{2}}} \]
    5. Step-by-step derivation
      1. unpow23.1%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    6. Simplified3.1%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    7. Step-by-step derivation
      1. clear-num3.1%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{\frac{y \cdot y}{x + y}}} \]
      2. un-div-inv3.1%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{y \cdot y}{x + y}}} \]
    8. Applied egg-rr3.1%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{y \cdot y}{x + y}}} \]
    9. Step-by-step derivation
      1. associate-/l*0.0%

        \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{y \cdot y}} \]
      2. times-frac77.1%

        \[\leadsto \color{blue}{\frac{x - y}{y} \cdot \frac{x + y}{y}} \]
    10. Simplified77.1%

      \[\leadsto \color{blue}{\frac{x - y}{y} \cdot \frac{x + y}{y}} \]
    11. Step-by-step derivation
      1. *-commutative77.1%

        \[\leadsto \color{blue}{\frac{x + y}{y} \cdot \frac{x - y}{y}} \]
      2. clear-num77.1%

        \[\leadsto \frac{x + y}{y} \cdot \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
      3. un-div-inv77.1%

        \[\leadsto \color{blue}{\frac{\frac{x + y}{y}}{\frac{y}{x - y}}} \]
    12. Applied egg-rr77.1%

      \[\leadsto \color{blue}{\frac{\frac{x + y}{y}}{\frac{y}{x - y}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \leq 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x + y}{y}}{\frac{y}{x - y}}\\ \end{array} \]

Alternative 5: 92.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -6.1 \cdot 10^{-24}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-162} \lor \neg \left(y \leq 5.6 \cdot 10^{-164}\right):\\ \;\;\;\;\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -6.1e-24)
   -1.0
   (if (or (<= y -1.6e-162) (not (<= y 5.6e-164)))
     (* (- x y) (/ (+ x y) (+ (* x x) (* y y))))
     (+ 1.0 (* -2.0 (* (/ y x) (/ y x)))))))
double code(double x, double y) {
	double tmp;
	if (y <= -6.1e-24) {
		tmp = -1.0;
	} else if ((y <= -1.6e-162) || !(y <= 5.6e-164)) {
		tmp = (x - y) * ((x + y) / ((x * x) + (y * y)));
	} else {
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-6.1d-24)) then
        tmp = -1.0d0
    else if ((y <= (-1.6d-162)) .or. (.not. (y <= 5.6d-164))) then
        tmp = (x - y) * ((x + y) / ((x * x) + (y * y)))
    else
        tmp = 1.0d0 + ((-2.0d0) * ((y / x) * (y / x)))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -6.1e-24) {
		tmp = -1.0;
	} else if ((y <= -1.6e-162) || !(y <= 5.6e-164)) {
		tmp = (x - y) * ((x + y) / ((x * x) + (y * y)));
	} else {
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -6.1e-24:
		tmp = -1.0
	elif (y <= -1.6e-162) or not (y <= 5.6e-164):
		tmp = (x - y) * ((x + y) / ((x * x) + (y * y)))
	else:
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)))
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -6.1e-24)
		tmp = -1.0;
	elseif ((y <= -1.6e-162) || !(y <= 5.6e-164))
		tmp = Float64(Float64(x - y) * Float64(Float64(x + y) / Float64(Float64(x * x) + Float64(y * y))));
	else
		tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / x) * Float64(y / x))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -6.1e-24)
		tmp = -1.0;
	elseif ((y <= -1.6e-162) || ~((y <= 5.6e-164)))
		tmp = (x - y) * ((x + y) / ((x * x) + (y * y)));
	else
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -6.1e-24], -1.0, If[Or[LessEqual[y, -1.6e-162], N[Not[LessEqual[y, 5.6e-164]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-2.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.1 \cdot 10^{-24}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -1.6 \cdot 10^{-162} \lor \neg \left(y \leq 5.6 \cdot 10^{-164}\right):\\
\;\;\;\;\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -6.10000000000000036e-24

    1. Initial program 53.1%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/54.3%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def54.3%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified54.3%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in x around 0 100.0%

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

    if -6.10000000000000036e-24 < y < -1.59999999999999988e-162 or 5.6000000000000002e-164 < y

    1. Initial program 99.9%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/96.8%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def96.8%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified96.8%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Step-by-step derivation
      1. fma-def96.8%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y + x \cdot x}} \]
    5. Applied egg-rr96.8%

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

    if -1.59999999999999988e-162 < y < 5.6000000000000002e-164

    1. Initial program 53.8%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/54.5%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def54.5%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified54.5%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in y around 0 53.8%

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{{y}^{2}}{{x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow253.8%

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}} \]
      2. unpow253.8%

        \[\leadsto 1 + -2 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}} \]
    6. Simplified53.8%

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{y \cdot y}{x \cdot x}} \]
    7. Step-by-step derivation
      1. times-frac79.1%

        \[\leadsto 1 + -2 \cdot \color{blue}{\left(\frac{y}{x} \cdot \frac{y}{x}\right)} \]
    8. Applied egg-rr79.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -6.1 \cdot 10^{-24}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-162} \lor \neg \left(y \leq 5.6 \cdot 10^{-164}\right):\\ \;\;\;\;\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\ \end{array} \]

Alternative 6: 83.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.55 \cdot 10^{-169} \lor \neg \left(y \leq 9.5 \cdot 10^{-153}\right):\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\ \mathbf{else}:\\ \;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -1.55e-169) (not (<= y 9.5e-153)))
   (+ (* (/ x y) (/ x y)) -1.0)
   (+ 1.0 (* -2.0 (* (/ y x) (/ y x))))))
double code(double x, double y) {
	double tmp;
	if ((y <= -1.55e-169) || !(y <= 9.5e-153)) {
		tmp = ((x / y) * (x / y)) + -1.0;
	} else {
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((y <= (-1.55d-169)) .or. (.not. (y <= 9.5d-153))) then
        tmp = ((x / y) * (x / y)) + (-1.0d0)
    else
        tmp = 1.0d0 + ((-2.0d0) * ((y / x) * (y / x)))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y <= -1.55e-169) || !(y <= 9.5e-153)) {
		tmp = ((x / y) * (x / y)) + -1.0;
	} else {
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -1.55e-169) or not (y <= 9.5e-153):
		tmp = ((x / y) * (x / y)) + -1.0
	else:
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)))
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -1.55e-169) || !(y <= 9.5e-153))
		tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0);
	else
		tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / x) * Float64(y / x))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= -1.55e-169) || ~((y <= 9.5e-153)))
		tmp = ((x / y) * (x / y)) + -1.0;
	else
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -1.55e-169], N[Not[LessEqual[y, 9.5e-153]], $MachinePrecision]], N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 + N[(-2.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{-169} \lor \neg \left(y \leq 9.5 \cdot 10^{-153}\right):\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.5500000000000001e-169 or 9.50000000000000031e-153 < y

    1. Initial program 72.2%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/72.3%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def72.3%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified72.3%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in x around 0 58.3%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{{y}^{2}}} \]
    5. Step-by-step derivation
      1. unpow258.3%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    6. Simplified58.3%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    7. Step-by-step derivation
      1. clear-num58.4%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{\frac{y \cdot y}{x + y}}} \]
      2. un-div-inv58.5%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{y \cdot y}{x + y}}} \]
    8. Applied egg-rr58.5%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{y \cdot y}{x + y}}} \]
    9. Step-by-step derivation
      1. associate-/l*58.3%

        \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{y \cdot y}} \]
      2. times-frac86.0%

        \[\leadsto \color{blue}{\frac{x - y}{y} \cdot \frac{x + y}{y}} \]
    10. Simplified86.0%

      \[\leadsto \color{blue}{\frac{x - y}{y} \cdot \frac{x + y}{y}} \]
    11. Taylor expanded in x around 0 84.8%

      \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} - 1} \]
    12. Step-by-step derivation
      1. sub-neg84.8%

        \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} + \left(-1\right)} \]
      2. unpow284.8%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{{y}^{2}} + \left(-1\right) \]
      3. unpow284.8%

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(-1\right) \]
      4. metadata-eval84.8%

        \[\leadsto \frac{x \cdot x}{y \cdot y} + \color{blue}{-1} \]
    13. Simplified84.8%

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + -1} \]
    14. Step-by-step derivation
      1. times-frac86.0%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + -1 \]
    15. Applied egg-rr86.0%

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

    if -1.5500000000000001e-169 < y < 9.50000000000000031e-153

    1. Initial program 57.8%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/57.0%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def57.0%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified57.0%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in y around 0 55.2%

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{{y}^{2}}{{x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow255.2%

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}} \]
      2. unpow255.2%

        \[\leadsto 1 + -2 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}} \]
    6. Simplified55.2%

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{y \cdot y}{x \cdot x}} \]
    7. Step-by-step derivation
      1. times-frac79.5%

        \[\leadsto 1 + -2 \cdot \color{blue}{\left(\frac{y}{x} \cdot \frac{y}{x}\right)} \]
    8. Applied egg-rr79.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.55 \cdot 10^{-169} \lor \neg \left(y \leq 9.5 \cdot 10^{-153}\right):\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\ \mathbf{else}:\\ \;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\ \end{array} \]

Alternative 7: 83.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.95 \cdot 10^{-169}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-153}:\\ \;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x + y}{y}}{\frac{y}{x - y}}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -1.95e-169)
   (+ (* (/ x y) (/ x y)) -1.0)
   (if (<= y 7.8e-153)
     (+ 1.0 (* -2.0 (* (/ y x) (/ y x))))
     (/ (/ (+ x y) y) (/ y (- x y))))))
double code(double x, double y) {
	double tmp;
	if (y <= -1.95e-169) {
		tmp = ((x / y) * (x / y)) + -1.0;
	} else if (y <= 7.8e-153) {
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
	} else {
		tmp = ((x + y) / y) / (y / (x - y));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-1.95d-169)) then
        tmp = ((x / y) * (x / y)) + (-1.0d0)
    else if (y <= 7.8d-153) then
        tmp = 1.0d0 + ((-2.0d0) * ((y / x) * (y / x)))
    else
        tmp = ((x + y) / y) / (y / (x - y))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -1.95e-169) {
		tmp = ((x / y) * (x / y)) + -1.0;
	} else if (y <= 7.8e-153) {
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
	} else {
		tmp = ((x + y) / y) / (y / (x - y));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -1.95e-169:
		tmp = ((x / y) * (x / y)) + -1.0
	elif y <= 7.8e-153:
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)))
	else:
		tmp = ((x + y) / y) / (y / (x - y))
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -1.95e-169)
		tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0);
	elseif (y <= 7.8e-153)
		tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / x) * Float64(y / x))));
	else
		tmp = Float64(Float64(Float64(x + y) / y) / Float64(y / Float64(x - y)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -1.95e-169)
		tmp = ((x / y) * (x / y)) + -1.0;
	elseif (y <= 7.8e-153)
		tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
	else
		tmp = ((x + y) / y) / (y / (x - y));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -1.95e-169], N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[y, 7.8e-153], N[(1.0 + N[(-2.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision] / N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{-169}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\

\mathbf{elif}\;y \leq 7.8 \cdot 10^{-153}:\\
\;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{x + y}{y}}{\frac{y}{x - y}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.94999999999999988e-169

    1. Initial program 64.4%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/64.6%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def64.6%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified64.6%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in x around 0 54.5%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{{y}^{2}}} \]
    5. Step-by-step derivation
      1. unpow254.5%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    6. Simplified54.5%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    7. Step-by-step derivation
      1. clear-num54.6%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{\frac{y \cdot y}{x + y}}} \]
      2. un-div-inv54.6%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{y \cdot y}{x + y}}} \]
    8. Applied egg-rr54.6%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{y \cdot y}{x + y}}} \]
    9. Step-by-step derivation
      1. associate-/l*54.3%

        \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{y \cdot y}} \]
      2. times-frac89.8%

        \[\leadsto \color{blue}{\frac{x - y}{y} \cdot \frac{x + y}{y}} \]
    10. Simplified89.8%

      \[\leadsto \color{blue}{\frac{x - y}{y} \cdot \frac{x + y}{y}} \]
    11. Taylor expanded in x around 0 88.4%

      \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} - 1} \]
    12. Step-by-step derivation
      1. sub-neg88.4%

        \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} + \left(-1\right)} \]
      2. unpow288.4%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{{y}^{2}} + \left(-1\right) \]
      3. unpow288.4%

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(-1\right) \]
      4. metadata-eval88.4%

        \[\leadsto \frac{x \cdot x}{y \cdot y} + \color{blue}{-1} \]
    13. Simplified88.4%

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + -1} \]
    14. Step-by-step derivation
      1. times-frac89.9%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + -1 \]
    15. Applied egg-rr89.9%

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

    if -1.94999999999999988e-169 < y < 7.8000000000000004e-153

    1. Initial program 57.8%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/57.0%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def57.0%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified57.0%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in y around 0 55.2%

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{{y}^{2}}{{x}^{2}}} \]
    5. Step-by-step derivation
      1. unpow255.2%

        \[\leadsto 1 + -2 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}} \]
      2. unpow255.2%

        \[\leadsto 1 + -2 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}} \]
    6. Simplified55.2%

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{y \cdot y}{x \cdot x}} \]
    7. Step-by-step derivation
      1. times-frac79.5%

        \[\leadsto 1 + -2 \cdot \color{blue}{\left(\frac{y}{x} \cdot \frac{y}{x}\right)} \]
    8. Applied egg-rr79.5%

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

    if 7.8000000000000004e-153 < y

    1. Initial program 99.8%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/99.5%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def99.6%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in x around 0 72.0%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{{y}^{2}}} \]
    5. Step-by-step derivation
      1. unpow272.0%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    6. Simplified72.0%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    7. Step-by-step derivation
      1. clear-num72.0%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{\frac{y \cdot y}{x + y}}} \]
      2. un-div-inv72.2%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{y \cdot y}{x + y}}} \]
    8. Applied egg-rr72.2%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{y \cdot y}{x + y}}} \]
    9. Step-by-step derivation
      1. associate-/l*72.3%

        \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{y \cdot y}} \]
      2. times-frac72.3%

        \[\leadsto \color{blue}{\frac{x - y}{y} \cdot \frac{x + y}{y}} \]
    10. Simplified72.3%

      \[\leadsto \color{blue}{\frac{x - y}{y} \cdot \frac{x + y}{y}} \]
    11. Step-by-step derivation
      1. *-commutative72.3%

        \[\leadsto \color{blue}{\frac{x + y}{y} \cdot \frac{x - y}{y}} \]
      2. clear-num72.3%

        \[\leadsto \frac{x + y}{y} \cdot \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
      3. un-div-inv72.3%

        \[\leadsto \color{blue}{\frac{\frac{x + y}{y}}{\frac{y}{x - y}}} \]
    12. Applied egg-rr72.3%

      \[\leadsto \color{blue}{\frac{\frac{x + y}{y}}{\frac{y}{x - y}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification83.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.95 \cdot 10^{-169}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-153}:\\ \;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x + y}{y}}{\frac{y}{x - y}}\\ \end{array} \]

Alternative 8: 83.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -4.9 \cdot 10^{-170} \lor \neg \left(y \leq 1.52 \cdot 10^{-152}\right):\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -4.9e-170) (not (<= y 1.52e-152)))
   (+ (* (/ x y) (/ x y)) -1.0)
   1.0))
double code(double x, double y) {
	double tmp;
	if ((y <= -4.9e-170) || !(y <= 1.52e-152)) {
		tmp = ((x / y) * (x / y)) + -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((y <= (-4.9d-170)) .or. (.not. (y <= 1.52d-152))) then
        tmp = ((x / y) * (x / y)) + (-1.0d0)
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y <= -4.9e-170) || !(y <= 1.52e-152)) {
		tmp = ((x / y) * (x / y)) + -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -4.9e-170) or not (y <= 1.52e-152):
		tmp = ((x / y) * (x / y)) + -1.0
	else:
		tmp = 1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -4.9e-170) || !(y <= 1.52e-152))
		tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0);
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= -4.9e-170) || ~((y <= 1.52e-152)))
		tmp = ((x / y) * (x / y)) + -1.0;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -4.9e-170], N[Not[LessEqual[y, 1.52e-152]], $MachinePrecision]], N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.9 \cdot 10^{-170} \lor \neg \left(y \leq 1.52 \cdot 10^{-152}\right):\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -4.8999999999999996e-170 or 1.52000000000000009e-152 < y

    1. Initial program 72.2%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/72.3%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def72.3%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified72.3%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in x around 0 58.3%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{{y}^{2}}} \]
    5. Step-by-step derivation
      1. unpow258.3%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    6. Simplified58.3%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{y \cdot y}} \]
    7. Step-by-step derivation
      1. clear-num58.4%

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{\frac{y \cdot y}{x + y}}} \]
      2. un-div-inv58.5%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{y \cdot y}{x + y}}} \]
    8. Applied egg-rr58.5%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{y \cdot y}{x + y}}} \]
    9. Step-by-step derivation
      1. associate-/l*58.3%

        \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{y \cdot y}} \]
      2. times-frac86.0%

        \[\leadsto \color{blue}{\frac{x - y}{y} \cdot \frac{x + y}{y}} \]
    10. Simplified86.0%

      \[\leadsto \color{blue}{\frac{x - y}{y} \cdot \frac{x + y}{y}} \]
    11. Taylor expanded in x around 0 84.8%

      \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} - 1} \]
    12. Step-by-step derivation
      1. sub-neg84.8%

        \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} + \left(-1\right)} \]
      2. unpow284.8%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{{y}^{2}} + \left(-1\right) \]
      3. unpow284.8%

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot y}} + \left(-1\right) \]
      4. metadata-eval84.8%

        \[\leadsto \frac{x \cdot x}{y \cdot y} + \color{blue}{-1} \]
    13. Simplified84.8%

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y} + -1} \]
    14. Step-by-step derivation
      1. times-frac86.0%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + -1 \]
    15. Applied egg-rr86.0%

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

    if -4.8999999999999996e-170 < y < 1.52000000000000009e-152

    1. Initial program 57.8%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/57.0%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def57.0%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified57.0%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in x around inf 78.0%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification83.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.9 \cdot 10^{-170} \lor \neg \left(y \leq 1.52 \cdot 10^{-152}\right):\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 9: 82.6% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.6 \cdot 10^{-169}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-151}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -1.6e-169) -1.0 (if (<= y 5.5e-151) 1.0 -1.0)))
double code(double x, double y) {
	double tmp;
	if (y <= -1.6e-169) {
		tmp = -1.0;
	} else if (y <= 5.5e-151) {
		tmp = 1.0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-1.6d-169)) then
        tmp = -1.0d0
    else if (y <= 5.5d-151) then
        tmp = 1.0d0
    else
        tmp = -1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -1.6e-169) {
		tmp = -1.0;
	} else if (y <= 5.5e-151) {
		tmp = 1.0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -1.6e-169:
		tmp = -1.0
	elif y <= 5.5e-151:
		tmp = 1.0
	else:
		tmp = -1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -1.6e-169)
		tmp = -1.0;
	elseif (y <= 5.5e-151)
		tmp = 1.0;
	else
		tmp = -1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -1.6e-169)
		tmp = -1.0;
	elseif (y <= 5.5e-151)
		tmp = 1.0;
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -1.6e-169], -1.0, If[LessEqual[y, 5.5e-151], 1.0, -1.0]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{-169}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 5.5 \cdot 10^{-151}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.59999999999999997e-169 or 5.4999999999999998e-151 < y

    1. Initial program 72.2%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/72.3%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def72.3%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified72.3%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in x around 0 85.1%

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

    if -1.59999999999999997e-169 < y < 5.4999999999999998e-151

    1. Initial program 57.8%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Step-by-step derivation
      1. associate-*r/57.0%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-def57.0%

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified57.0%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    4. Taylor expanded in x around inf 78.0%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification82.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.6 \cdot 10^{-169}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-151}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternative 10: 66.5% accurate, 15.0× speedup?

\[\begin{array}{l} \\ -1 \end{array} \]
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
	return -1.0;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = -1.0d0
end function
public static double code(double x, double y) {
	return -1.0;
}
def code(x, y):
	return -1.0
function code(x, y)
	return -1.0
end
function tmp = code(x, y)
	tmp = -1.0;
end
code[x_, y_] := -1.0
\begin{array}{l}

\\
-1
\end{array}
Derivation
  1. Initial program 67.5%

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
  2. Step-by-step derivation
    1. associate-*r/67.3%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
    2. fma-def67.3%

      \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
  3. Simplified67.3%

    \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
  4. Taylor expanded in x around 0 64.4%

    \[\leadsto \color{blue}{-1} \]
  5. Final simplification64.4%

    \[\leadsto -1 \]

Developer target: 99.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;0.5 < t_0 \land t_0 < 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} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (fabs (/ x y))))
   (if (and (< 0.5 t_0) (< t_0 2.0))
     (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
     (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))))
double code(double x, double y) {
	double t_0 = fabs((x / y));
	double tmp;
	if ((0.5 < t_0) && (t_0 < 2.0)) {
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
	} else {
		tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (x / y))));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = abs((x / y))
    if ((0.5d0 < t_0) .and. (t_0 < 2.0d0)) then
        tmp = ((x - y) * (x + y)) / ((x * x) + (y * y))
    else
        tmp = 1.0d0 - (2.0d0 / (1.0d0 + ((x / y) * (x / y))))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = Math.abs((x / y));
	double tmp;
	if ((0.5 < t_0) && (t_0 < 2.0)) {
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
	} else {
		tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (x / y))));
	}
	return tmp;
}
def code(x, y):
	t_0 = math.fabs((x / y))
	tmp = 0
	if (0.5 < t_0) and (t_0 < 2.0):
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y))
	else:
		tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (x / y))))
	return tmp
function code(x, y)
	t_0 = abs(Float64(x / y))
	tmp = 0.0
	if ((0.5 < t_0) && (t_0 < 2.0))
		tmp = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)));
	else
		tmp = Float64(1.0 - Float64(2.0 / Float64(1.0 + Float64(Float64(x / y) * Float64(x / y)))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = abs((x / y));
	tmp = 0.0;
	if ((0.5 < t_0) && (t_0 < 2.0))
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
	else
		tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (x / y))));
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision]}, If[And[Less[0.5, t$95$0], Less[t$95$0, 2.0]], N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(2.0 / N[(1.0 + N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|\frac{x}{y}\right|\\
\mathbf{if}\;0.5 < t_0 \land t_0 < 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}
\end{array}

Reproduce

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

  :herbie-target
  (if (and (< 0.5 (fabs (/ x y))) (< (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))))