Kahan p9 Example

Percentage Accurate: 68.5% → 99.9%
Time: 9.6s
Alternatives: 12
Speedup: 0.1×

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 12 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.5% 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: 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 65.6%

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. fma-define65.6%

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

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

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

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

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

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

      \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\color{blue}{\mathsf{hypot}\left(x, y\right)}} \]
  4. 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)}} \]
  5. Final simplification99.9%

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

Alternative 2: 47.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{-175}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{\frac{x}{y}}{\frac{y}{x}}, -1\right)\\ \mathbf{elif}\;y \leq 10^{-22}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{\mathsf{fma}\left(x, x, {y}^{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y 9e-205)
   (- 1.0 (/ (* 2.0 (* y (/ y x))) x))
   (if (<= y 2.25e-175)
     (fma 2.0 (/ (/ x y) (/ y x)) -1.0)
     (if (<= y 1e-22) (/ (* (- x y) (+ x y)) (fma x x (pow y 2.0))) -1.0))))
double code(double x, double y) {
	double tmp;
	if (y <= 9e-205) {
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
	} else if (y <= 2.25e-175) {
		tmp = fma(2.0, ((x / y) / (y / x)), -1.0);
	} else if (y <= 1e-22) {
		tmp = ((x - y) * (x + y)) / fma(x, x, pow(y, 2.0));
	} else {
		tmp = -1.0;
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (y <= 9e-205)
		tmp = Float64(1.0 - Float64(Float64(2.0 * Float64(y * Float64(y / x))) / x));
	elseif (y <= 2.25e-175)
		tmp = fma(2.0, Float64(Float64(x / y) / Float64(y / x)), -1.0);
	elseif (y <= 1e-22)
		tmp = Float64(Float64(Float64(x - y) * Float64(x + y)) / fma(x, x, (y ^ 2.0)));
	else
		tmp = -1.0;
	end
	return tmp
end
code[x_, y_] := If[LessEqual[y, 9e-205], N[(1.0 - N[(N[(2.0 * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.25e-175], N[(2.0 * N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[y, 1e-22], N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(x * x + N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\
\;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\

\mathbf{elif}\;y \leq 2.25 \cdot 10^{-175}:\\
\;\;\;\;\mathsf{fma}\left(2, \frac{\frac{x}{y}}{\frac{y}{x}}, -1\right)\\

\mathbf{elif}\;y \leq 10^{-22}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{\mathsf{fma}\left(x, x, {y}^{2}\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < 8.99999999999999912e-205

    1. Initial program 58.4%

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

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

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

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

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

      \[\leadsto \color{blue}{1 - \frac{\frac{-2 \cdot {y}^{2}}{-x}}{x}} \]
    7. Taylor expanded in y around 0 36.3%

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

        \[\leadsto 1 - \frac{2 \cdot \frac{\color{blue}{y \cdot y}}{x}}{x} \]
      2. associate-/l*36.9%

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

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

    if 8.99999999999999912e-205 < y < 2.24999999999999999e-175

    1. Initial program 14.3%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. fma-define14.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, {\left(\frac{x}{y}\right)}^{2}, -1\right)} \]
    8. Step-by-step derivation
      1. unpow286.3%

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

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

        \[\leadsto \mathsf{fma}\left(2, \color{blue}{\frac{\frac{x}{y}}{\frac{y}{x}}}, -1\right) \]
    9. Applied egg-rr86.3%

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

    if 2.24999999999999999e-175 < y < 1e-22

    1. Initial program 97.7%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. fma-define97.8%

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

        \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\mathsf{fma}\left(x, x, \color{blue}{{y}^{2}}\right)} \]
    4. Applied egg-rr97.8%

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\mathsf{fma}\left(x, x, {y}^{2}\right)}} \]

    if 1e-22 < y

    1. Initial program 100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{-175}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{\frac{x}{y}}{\frac{y}{x}}, -1\right)\\ \mathbf{elif}\;y \leq 10^{-22}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{\mathsf{fma}\left(x, x, {y}^{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 47.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{-176}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{\frac{x}{y}}{\frac{y}{x}}, -1\right)\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{-19}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y 9e-205)
   (- 1.0 (/ (* 2.0 (* y (/ y x))) x))
   (if (<= y 6.8e-176)
     (fma 2.0 (/ (/ x y) (/ y x)) -1.0)
     (if (<= y 3.1e-19) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) -1.0))))
double code(double x, double y) {
	double tmp;
	if (y <= 9e-205) {
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
	} else if (y <= 6.8e-176) {
		tmp = fma(2.0, ((x / y) / (y / x)), -1.0);
	} else if (y <= 3.1e-19) {
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
	} else {
		tmp = -1.0;
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (y <= 9e-205)
		tmp = Float64(1.0 - Float64(Float64(2.0 * Float64(y * Float64(y / x))) / x));
	elseif (y <= 6.8e-176)
		tmp = fma(2.0, Float64(Float64(x / y) / Float64(y / x)), -1.0);
	elseif (y <= 3.1e-19)
		tmp = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)));
	else
		tmp = -1.0;
	end
	return tmp
end
code[x_, y_] := If[LessEqual[y, 9e-205], N[(1.0 - N[(N[(2.0 * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.8e-176], N[(2.0 * N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[y, 3.1e-19], N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\
\;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\

\mathbf{elif}\;y \leq 6.8 \cdot 10^{-176}:\\
\;\;\;\;\mathsf{fma}\left(2, \frac{\frac{x}{y}}{\frac{y}{x}}, -1\right)\\

\mathbf{elif}\;y \leq 3.1 \cdot 10^{-19}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < 8.99999999999999912e-205

    1. Initial program 58.4%

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

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

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

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

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

      \[\leadsto \color{blue}{1 - \frac{\frac{-2 \cdot {y}^{2}}{-x}}{x}} \]
    7. Taylor expanded in y around 0 36.3%

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

        \[\leadsto 1 - \frac{2 \cdot \frac{\color{blue}{y \cdot y}}{x}}{x} \]
      2. associate-/l*36.9%

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

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

    if 8.99999999999999912e-205 < y < 6.7999999999999994e-176

    1. Initial program 14.3%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. fma-define14.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, {\left(\frac{x}{y}\right)}^{2}, -1\right)} \]
    8. Step-by-step derivation
      1. unpow286.3%

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

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

        \[\leadsto \mathsf{fma}\left(2, \color{blue}{\frac{\frac{x}{y}}{\frac{y}{x}}}, -1\right) \]
    9. Applied egg-rr86.3%

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

    if 6.7999999999999994e-176 < y < 3.0999999999999999e-19

    1. Initial program 97.7%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Add Preprocessing

    if 3.0999999999999999e-19 < y

    1. Initial program 100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{-176}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{\frac{x}{y}}{\frac{y}{x}}, -1\right)\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{-19}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 47.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-175}:\\ \;\;\;\;\frac{x - y}{y + x \cdot \left(\frac{x}{y} + -1\right)}\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-19}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y 9e-205)
   (- 1.0 (/ (* 2.0 (* y (/ y x))) x))
   (if (<= y 5.4e-175)
     (/ (- x y) (+ y (* x (+ (/ x y) -1.0))))
     (if (<= y 2e-19) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) -1.0))))
double code(double x, double y) {
	double tmp;
	if (y <= 9e-205) {
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
	} else if (y <= 5.4e-175) {
		tmp = (x - y) / (y + (x * ((x / y) + -1.0)));
	} else if (y <= 2e-19) {
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
	} 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 <= 9d-205) then
        tmp = 1.0d0 - ((2.0d0 * (y * (y / x))) / x)
    else if (y <= 5.4d-175) then
        tmp = (x - y) / (y + (x * ((x / y) + (-1.0d0))))
    else if (y <= 2d-19) then
        tmp = ((x - y) * (x + y)) / ((x * x) + (y * y))
    else
        tmp = -1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= 9e-205) {
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
	} else if (y <= 5.4e-175) {
		tmp = (x - y) / (y + (x * ((x / y) + -1.0)));
	} else if (y <= 2e-19) {
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
	} else {
		tmp = -1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 9e-205:
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x)
	elif y <= 5.4e-175:
		tmp = (x - y) / (y + (x * ((x / y) + -1.0)))
	elif y <= 2e-19:
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y))
	else:
		tmp = -1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 9e-205)
		tmp = Float64(1.0 - Float64(Float64(2.0 * Float64(y * Float64(y / x))) / x));
	elseif (y <= 5.4e-175)
		tmp = Float64(Float64(x - y) / Float64(y + Float64(x * Float64(Float64(x / y) + -1.0))));
	elseif (y <= 2e-19)
		tmp = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)));
	else
		tmp = -1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 9e-205)
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
	elseif (y <= 5.4e-175)
		tmp = (x - y) / (y + (x * ((x / y) + -1.0)));
	elseif (y <= 2e-19)
		tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 9e-205], N[(1.0 - N[(N[(2.0 * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.4e-175], N[(N[(x - y), $MachinePrecision] / N[(y + N[(x * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2e-19], N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\
\;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < 8.99999999999999912e-205

    1. Initial program 58.4%

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

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

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

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

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

      \[\leadsto \color{blue}{1 - \frac{\frac{-2 \cdot {y}^{2}}{-x}}{x}} \]
    7. Taylor expanded in y around 0 36.3%

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

        \[\leadsto 1 - \frac{2 \cdot \frac{\color{blue}{y \cdot y}}{x}}{x} \]
      2. associate-/l*36.9%

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

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

    if 8.99999999999999912e-205 < y < 5.39999999999999998e-175

    1. Initial program 14.3%

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

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

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

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1 + \frac{x}{y}}{y}} \]
    6. Taylor expanded in y around 0 83.5%

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

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

        \[\leadsto \color{blue}{\frac{x - y}{\frac{y}{\frac{x + y}{y}}}} \]
      3. div-inv84.0%

        \[\leadsto \frac{x - y}{\color{blue}{y \cdot \frac{1}{\frac{x + y}{y}}}} \]
      4. clear-num84.0%

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

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

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

    if 5.39999999999999998e-175 < y < 2e-19

    1. Initial program 97.7%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Add Preprocessing

    if 2e-19 < y

    1. Initial program 100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-175}:\\ \;\;\;\;\frac{x - y}{y + x \cdot \left(\frac{x}{y} + -1\right)}\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-19}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 43.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 8.5 \cdot 10^{-205} \lor \neg \left(y \leq 9 \cdot 10^{-175}\right) \land y \leq 4.5 \cdot 10^{-168}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{y + x \cdot \left(\frac{x}{y} + -1\right)}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y 8.5e-205) (and (not (<= y 9e-175)) (<= y 4.5e-168)))
   (- 1.0 (/ (* 2.0 (* y (/ y x))) x))
   (/ (- x y) (+ y (* x (+ (/ x y) -1.0))))))
double code(double x, double y) {
	double tmp;
	if ((y <= 8.5e-205) || (!(y <= 9e-175) && (y <= 4.5e-168))) {
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
	} else {
		tmp = (x - y) / (y + (x * ((x / y) + -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 <= 8.5d-205) .or. (.not. (y <= 9d-175)) .and. (y <= 4.5d-168)) then
        tmp = 1.0d0 - ((2.0d0 * (y * (y / x))) / x)
    else
        tmp = (x - y) / (y + (x * ((x / y) + (-1.0d0))))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y <= 8.5e-205) || (!(y <= 9e-175) && (y <= 4.5e-168))) {
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
	} else {
		tmp = (x - y) / (y + (x * ((x / y) + -1.0)));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= 8.5e-205) or (not (y <= 9e-175) and (y <= 4.5e-168)):
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x)
	else:
		tmp = (x - y) / (y + (x * ((x / y) + -1.0)))
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= 8.5e-205) || (!(y <= 9e-175) && (y <= 4.5e-168)))
		tmp = Float64(1.0 - Float64(Float64(2.0 * Float64(y * Float64(y / x))) / x));
	else
		tmp = Float64(Float64(x - y) / Float64(y + Float64(x * Float64(Float64(x / y) + -1.0))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= 8.5e-205) || (~((y <= 9e-175)) && (y <= 4.5e-168)))
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
	else
		tmp = (x - y) / (y + (x * ((x / y) + -1.0)));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, 8.5e-205], And[N[Not[LessEqual[y, 9e-175]], $MachinePrecision], LessEqual[y, 4.5e-168]]], N[(1.0 - N[(N[(2.0 * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] / N[(y + N[(x * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.5 \cdot 10^{-205} \lor \neg \left(y \leq 9 \cdot 10^{-175}\right) \land y \leq 4.5 \cdot 10^{-168}:\\
\;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 8.5000000000000005e-205 or 8.99999999999999996e-175 < y < 4.5000000000000001e-168

    1. Initial program 58.6%

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

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

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

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

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

      \[\leadsto \color{blue}{1 - \frac{\frac{-2 \cdot {y}^{2}}{-x}}{x}} \]
    7. Taylor expanded in y around 0 36.8%

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

        \[\leadsto 1 - \frac{2 \cdot \frac{\color{blue}{y \cdot y}}{x}}{x} \]
      2. associate-/l*37.4%

        \[\leadsto 1 - \frac{2 \cdot \color{blue}{\left(y \cdot \frac{y}{x}\right)}}{x} \]
    9. Applied egg-rr37.4%

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

    if 8.5000000000000005e-205 < y < 8.99999999999999996e-175 or 4.5000000000000001e-168 < y

    1. Initial program 89.6%

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

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

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

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1 + \frac{x}{y}}{y}} \]
    6. Taylor expanded in y around 0 71.8%

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

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

        \[\leadsto \color{blue}{\frac{x - y}{\frac{y}{\frac{x + y}{y}}}} \]
      3. div-inv71.9%

        \[\leadsto \frac{x - y}{\color{blue}{y \cdot \frac{1}{\frac{x + y}{y}}}} \]
      4. clear-num71.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 8.5 \cdot 10^{-205} \lor \neg \left(y \leq 9 \cdot 10^{-175}\right) \land y \leq 4.5 \cdot 10^{-168}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{y + x \cdot \left(\frac{x}{y} + -1\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 41.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-174} \lor \neg \left(y \leq 4.4 \cdot 10^{-168}\right):\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y 9e-205)
   1.0
   (if (or (<= y 1.5e-174) (not (<= y 4.4e-168)))
     (* (- x y) (/ (+ 1.0 (/ x y)) y))
     1.0)))
double code(double x, double y) {
	double tmp;
	if (y <= 9e-205) {
		tmp = 1.0;
	} else if ((y <= 1.5e-174) || !(y <= 4.4e-168)) {
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	} 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 <= 9d-205) then
        tmp = 1.0d0
    else if ((y <= 1.5d-174) .or. (.not. (y <= 4.4d-168))) then
        tmp = (x - y) * ((1.0d0 + (x / y)) / y)
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= 9e-205) {
		tmp = 1.0;
	} else if ((y <= 1.5e-174) || !(y <= 4.4e-168)) {
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 9e-205:
		tmp = 1.0
	elif (y <= 1.5e-174) or not (y <= 4.4e-168):
		tmp = (x - y) * ((1.0 + (x / y)) / y)
	else:
		tmp = 1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 9e-205)
		tmp = 1.0;
	elseif ((y <= 1.5e-174) || !(y <= 4.4e-168))
		tmp = Float64(Float64(x - y) * Float64(Float64(1.0 + Float64(x / y)) / y));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 9e-205)
		tmp = 1.0;
	elseif ((y <= 1.5e-174) || ~((y <= 4.4e-168)))
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 9e-205], 1.0, If[Or[LessEqual[y, 1.5e-174], N[Not[LessEqual[y, 4.4e-168]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq 1.5 \cdot 10^{-174} \lor \neg \left(y \leq 4.4 \cdot 10^{-168}\right):\\
\;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 8.99999999999999912e-205 or 1.50000000000000011e-174 < y < 4.3999999999999996e-168

    1. Initial program 58.6%

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

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

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

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

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

    if 8.99999999999999912e-205 < y < 1.50000000000000011e-174 or 4.3999999999999996e-168 < y

    1. Initial program 89.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-174} \lor \neg \left(y \leq 4.4 \cdot 10^{-168}\right):\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 43.0% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq 9 \cdot 10^{-205} \lor \neg \left(y \leq 8.8 \cdot 10^{-176}\right) \land y \leq 5.2 \cdot 10^{-168}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{y}{x}}{x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 8.99999999999999912e-205 or 8.7999999999999994e-176 < y < 5.2000000000000002e-168

    1. Initial program 58.6%

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

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

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

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

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

    if 8.99999999999999912e-205 < y < 8.7999999999999994e-176 or 5.2000000000000002e-168 < y

    1. Initial program 89.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205} \lor \neg \left(y \leq 8.8 \cdot 10^{-176}\right) \land y \leq 5.2 \cdot 10^{-168}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{y}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 43.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205} \lor \neg \left(y \leq 7.2 \cdot 10^{-175}\right) \land y \leq 4.8 \cdot 10^{-168}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{y \cdot \frac{y}{x + y}}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y 9e-205) (and (not (<= y 7.2e-175)) (<= y 4.8e-168)))
   (- 1.0 (/ (* 2.0 (* y (/ y x))) x))
   (/ (- x y) (* y (/ y (+ x y))))))
double code(double x, double y) {
	double tmp;
	if ((y <= 9e-205) || (!(y <= 7.2e-175) && (y <= 4.8e-168))) {
		tmp = 1.0 - ((2.0 * (y * (y / x))) / 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 <= 9d-205) .or. (.not. (y <= 7.2d-175)) .and. (y <= 4.8d-168)) then
        tmp = 1.0d0 - ((2.0d0 * (y * (y / x))) / 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 <= 9e-205) || (!(y <= 7.2e-175) && (y <= 4.8e-168))) {
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
	} else {
		tmp = (x - y) / (y * (y / (x + y)));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= 9e-205) or (not (y <= 7.2e-175) and (y <= 4.8e-168)):
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x)
	else:
		tmp = (x - y) / (y * (y / (x + y)))
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= 9e-205) || (!(y <= 7.2e-175) && (y <= 4.8e-168)))
		tmp = Float64(1.0 - Float64(Float64(2.0 * Float64(y * Float64(y / x))) / x));
	else
		tmp = Float64(Float64(x - y) / Float64(y * Float64(y / Float64(x + y))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= 9e-205) || (~((y <= 7.2e-175)) && (y <= 4.8e-168)))
		tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
	else
		tmp = (x - y) / (y * (y / (x + y)));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, 9e-205], And[N[Not[LessEqual[y, 7.2e-175]], $MachinePrecision], LessEqual[y, 4.8e-168]]], N[(1.0 - N[(N[(2.0 * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] / N[(y * N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 9 \cdot 10^{-205} \lor \neg \left(y \leq 7.2 \cdot 10^{-175}\right) \land y \leq 4.8 \cdot 10^{-168}:\\
\;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 8.99999999999999912e-205 or 7.2e-175 < y < 4.7999999999999999e-168

    1. Initial program 58.6%

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

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

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

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

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

      \[\leadsto \color{blue}{1 - \frac{\frac{-2 \cdot {y}^{2}}{-x}}{x}} \]
    7. Taylor expanded in y around 0 36.8%

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

        \[\leadsto 1 - \frac{2 \cdot \frac{\color{blue}{y \cdot y}}{x}}{x} \]
      2. associate-/l*37.4%

        \[\leadsto 1 - \frac{2 \cdot \color{blue}{\left(y \cdot \frac{y}{x}\right)}}{x} \]
    9. Applied egg-rr37.4%

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

    if 8.99999999999999912e-205 < y < 7.2e-175 or 4.7999999999999999e-168 < y

    1. Initial program 89.6%

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

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

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

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1 + \frac{x}{y}}{y}} \]
    6. Taylor expanded in y around 0 71.8%

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

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

        \[\leadsto \color{blue}{\frac{x - y}{\frac{y}{\frac{x + y}{y}}}} \]
      3. div-inv71.9%

        \[\leadsto \frac{x - y}{\color{blue}{y \cdot \frac{1}{\frac{x + y}{y}}}} \]
      4. clear-num71.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205} \lor \neg \left(y \leq 7.2 \cdot 10^{-175}\right) \land y \leq 4.8 \cdot 10^{-168}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{y \cdot \frac{y}{x + y}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 43.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x - y\right) \cdot \frac{1 + \frac{y}{x}}{x}\\ \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 8.8 \cdot 10^{-176}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-168}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{\frac{x + y}{y}}{y}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* (- x y) (/ (+ 1.0 (/ y x)) x))))
   (if (<= y 9e-205)
     t_0
     (if (<= y 8.8e-176)
       (* (- x y) (/ (+ 1.0 (/ x y)) y))
       (if (<= y 4.4e-168) t_0 (* (- x y) (/ (/ (+ x y) y) y)))))))
double code(double x, double y) {
	double t_0 = (x - y) * ((1.0 + (y / x)) / x);
	double tmp;
	if (y <= 9e-205) {
		tmp = t_0;
	} else if (y <= 8.8e-176) {
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	} else if (y <= 4.4e-168) {
		tmp = t_0;
	} else {
		tmp = (x - y) * (((x + y) / y) / 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) * ((1.0d0 + (y / x)) / x)
    if (y <= 9d-205) then
        tmp = t_0
    else if (y <= 8.8d-176) then
        tmp = (x - y) * ((1.0d0 + (x / y)) / y)
    else if (y <= 4.4d-168) then
        tmp = t_0
    else
        tmp = (x - y) * (((x + y) / y) / y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = (x - y) * ((1.0 + (y / x)) / x);
	double tmp;
	if (y <= 9e-205) {
		tmp = t_0;
	} else if (y <= 8.8e-176) {
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	} else if (y <= 4.4e-168) {
		tmp = t_0;
	} else {
		tmp = (x - y) * (((x + y) / y) / y);
	}
	return tmp;
}
def code(x, y):
	t_0 = (x - y) * ((1.0 + (y / x)) / x)
	tmp = 0
	if y <= 9e-205:
		tmp = t_0
	elif y <= 8.8e-176:
		tmp = (x - y) * ((1.0 + (x / y)) / y)
	elif y <= 4.4e-168:
		tmp = t_0
	else:
		tmp = (x - y) * (((x + y) / y) / y)
	return tmp
function code(x, y)
	t_0 = Float64(Float64(x - y) * Float64(Float64(1.0 + Float64(y / x)) / x))
	tmp = 0.0
	if (y <= 9e-205)
		tmp = t_0;
	elseif (y <= 8.8e-176)
		tmp = Float64(Float64(x - y) * Float64(Float64(1.0 + Float64(x / y)) / y));
	elseif (y <= 4.4e-168)
		tmp = t_0;
	else
		tmp = Float64(Float64(x - y) * Float64(Float64(Float64(x + y) / y) / y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = (x - y) * ((1.0 + (y / x)) / x);
	tmp = 0.0;
	if (y <= 9e-205)
		tmp = t_0;
	elseif (y <= 8.8e-176)
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	elseif (y <= 4.4e-168)
		tmp = t_0;
	else
		tmp = (x - y) * (((x + y) / y) / y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 9e-205], t$95$0, If[LessEqual[y, 8.8e-176], N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.4e-168], t$95$0, N[(N[(x - y), $MachinePrecision] * N[(N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x - y\right) \cdot \frac{1 + \frac{y}{x}}{x}\\
\mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;y \leq 4.4 \cdot 10^{-168}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < 8.99999999999999912e-205 or 8.7999999999999994e-176 < y < 4.3999999999999996e-168

    1. Initial program 58.6%

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

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

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

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

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

    if 8.99999999999999912e-205 < y < 8.7999999999999994e-176

    1. Initial program 14.3%

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

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

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

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

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

    if 4.3999999999999996e-168 < 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-/l*98.8%

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

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

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1 + \frac{x}{y}}{y}} \]
    6. Taylor expanded in y around 0 70.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{y}{x}}{x}\\ \mathbf{elif}\;y \leq 8.8 \cdot 10^{-176}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-168}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{y}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{\frac{x + y}{y}}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 43.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{-176}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{-168}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{\frac{x + y}{y}}{y}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- 1.0 (/ (* 2.0 (* y (/ y x))) x))))
   (if (<= y 9e-205)
     t_0
     (if (<= y 8.2e-176)
       (* (- x y) (/ (+ 1.0 (/ x y)) y))
       (if (<= y 4.7e-168) t_0 (* (- x y) (/ (/ (+ x y) y) y)))))))
double code(double x, double y) {
	double t_0 = 1.0 - ((2.0 * (y * (y / x))) / x);
	double tmp;
	if (y <= 9e-205) {
		tmp = t_0;
	} else if (y <= 8.2e-176) {
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	} else if (y <= 4.7e-168) {
		tmp = t_0;
	} else {
		tmp = (x - y) * (((x + y) / y) / 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 = 1.0d0 - ((2.0d0 * (y * (y / x))) / x)
    if (y <= 9d-205) then
        tmp = t_0
    else if (y <= 8.2d-176) then
        tmp = (x - y) * ((1.0d0 + (x / y)) / y)
    else if (y <= 4.7d-168) then
        tmp = t_0
    else
        tmp = (x - y) * (((x + y) / y) / y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = 1.0 - ((2.0 * (y * (y / x))) / x);
	double tmp;
	if (y <= 9e-205) {
		tmp = t_0;
	} else if (y <= 8.2e-176) {
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	} else if (y <= 4.7e-168) {
		tmp = t_0;
	} else {
		tmp = (x - y) * (((x + y) / y) / y);
	}
	return tmp;
}
def code(x, y):
	t_0 = 1.0 - ((2.0 * (y * (y / x))) / x)
	tmp = 0
	if y <= 9e-205:
		tmp = t_0
	elif y <= 8.2e-176:
		tmp = (x - y) * ((1.0 + (x / y)) / y)
	elif y <= 4.7e-168:
		tmp = t_0
	else:
		tmp = (x - y) * (((x + y) / y) / y)
	return tmp
function code(x, y)
	t_0 = Float64(1.0 - Float64(Float64(2.0 * Float64(y * Float64(y / x))) / x))
	tmp = 0.0
	if (y <= 9e-205)
		tmp = t_0;
	elseif (y <= 8.2e-176)
		tmp = Float64(Float64(x - y) * Float64(Float64(1.0 + Float64(x / y)) / y));
	elseif (y <= 4.7e-168)
		tmp = t_0;
	else
		tmp = Float64(Float64(x - y) * Float64(Float64(Float64(x + y) / y) / y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = 1.0 - ((2.0 * (y * (y / x))) / x);
	tmp = 0.0;
	if (y <= 9e-205)
		tmp = t_0;
	elseif (y <= 8.2e-176)
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	elseif (y <= 4.7e-168)
		tmp = t_0;
	else
		tmp = (x - y) * (((x + y) / y) / y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(N[(2.0 * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 9e-205], t$95$0, If[LessEqual[y, 8.2e-176], N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.7e-168], t$95$0, N[(N[(x - y), $MachinePrecision] * N[(N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\
\mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;y \leq 4.7 \cdot 10^{-168}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < 8.99999999999999912e-205 or 8.2000000000000005e-176 < y < 4.70000000000000026e-168

    1. Initial program 58.6%

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

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

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

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

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

      \[\leadsto \color{blue}{1 - \frac{\frac{-2 \cdot {y}^{2}}{-x}}{x}} \]
    7. Taylor expanded in y around 0 36.8%

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

        \[\leadsto 1 - \frac{2 \cdot \frac{\color{blue}{y \cdot y}}{x}}{x} \]
      2. associate-/l*37.4%

        \[\leadsto 1 - \frac{2 \cdot \color{blue}{\left(y \cdot \frac{y}{x}\right)}}{x} \]
    9. Applied egg-rr37.4%

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

    if 8.99999999999999912e-205 < y < 8.2000000000000005e-176

    1. Initial program 14.3%

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

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

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

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

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

    if 4.70000000000000026e-168 < 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-/l*98.8%

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

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

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1 + \frac{x}{y}}{y}} \]
    6. Taylor expanded in y around 0 70.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{-176}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{-168}:\\ \;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{\frac{x + y}{y}}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 41.6% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 10^{-175}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-168}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y 9e-205) 1.0 (if (<= y 1e-175) -1.0 (if (<= y 4.4e-168) 1.0 -1.0))))
double code(double x, double y) {
	double tmp;
	if (y <= 9e-205) {
		tmp = 1.0;
	} else if (y <= 1e-175) {
		tmp = -1.0;
	} else if (y <= 4.4e-168) {
		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 <= 9d-205) then
        tmp = 1.0d0
    else if (y <= 1d-175) then
        tmp = -1.0d0
    else if (y <= 4.4d-168) 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 <= 9e-205) {
		tmp = 1.0;
	} else if (y <= 1e-175) {
		tmp = -1.0;
	} else if (y <= 4.4e-168) {
		tmp = 1.0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 9e-205:
		tmp = 1.0
	elif y <= 1e-175:
		tmp = -1.0
	elif y <= 4.4e-168:
		tmp = 1.0
	else:
		tmp = -1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 9e-205)
		tmp = 1.0;
	elseif (y <= 1e-175)
		tmp = -1.0;
	elseif (y <= 4.4e-168)
		tmp = 1.0;
	else
		tmp = -1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 9e-205)
		tmp = 1.0;
	elseif (y <= 1e-175)
		tmp = -1.0;
	elseif (y <= 4.4e-168)
		tmp = 1.0;
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 9e-205], 1.0, If[LessEqual[y, 1e-175], -1.0, If[LessEqual[y, 4.4e-168], 1.0, -1.0]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq 10^{-175}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 4.4 \cdot 10^{-168}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 8.99999999999999912e-205 or 1e-175 < y < 4.3999999999999996e-168

    1. Initial program 58.6%

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

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

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

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

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

    if 8.99999999999999912e-205 < y < 1e-175 or 4.3999999999999996e-168 < y

    1. Initial program 89.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-205}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 10^{-175}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-168}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 65.8% 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 65.6%

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

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

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

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

    \[\leadsto \color{blue}{-1} \]
  6. Final simplification66.2%

    \[\leadsto -1 \]
  7. Add Preprocessing

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 2024055 
(FPCore (x y)
  :name "Kahan p9 Example"
  :precision binary64
  :pre (and (and (< 0.0 x) (< x 1.0)) (< y 1.0))

  :alt
  (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))))