Kahan p9 Example

Percentage Accurate: 68.6% → 100.0%
Time: 10.6s
Alternatives: 15
Speedup: 1.5×

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 15 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 68.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-define68.7%

      \[\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-sqrt68.7%

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

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

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

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

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

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

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

      \[\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}}} \]
  6. 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}}} \]
  7. Final simplification100.0%

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

Alternative 2: 92.6% 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, {\left(\frac{x}{y}\right)}^{2}, -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 (pow (/ x y) 2.0) -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, pow((x / y), 2.0), -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(x / y) ^ 2.0), -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[Power[N[(x / y), $MachinePrecision], 2.0], $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, {\left(\frac{x}{y}\right)}^{2}, -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 100.0%

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

    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. Add Preprocessing
    3. Step-by-step derivation
      1. fma-define0.0%

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

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

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

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

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

        \[\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. Taylor expanded in x around 0 52.5%

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

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

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

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

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

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

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

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

    \[\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, {\left(\frac{x}{y}\right)}^{2}, -1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 76.8% 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 0.5:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({\left(\frac{y}{x}\right)}^{2}, -2, 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 0.5) t_0 (fma (pow (/ y x) 2.0) -2.0 1.0))))
double code(double x, double y) {
	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	double tmp;
	if (t_0 <= 0.5) {
		tmp = t_0;
	} else {
		tmp = fma(pow((y / x), 2.0), -2.0, 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 <= 0.5)
		tmp = t_0;
	else
		tmp = fma((Float64(y / x) ^ 2.0), -2.0, 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, 0.5], t$95$0, N[(N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision] * -2.0 + 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 0.5:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\left(\frac{y}{x}\right)}^{2}, -2, 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))) < 0.5

    1. Initial program 100.0%

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

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

    1. Initial program 43.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-define43.7%

        \[\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-sqrt43.7%

        \[\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-frac44.7%

        \[\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-define44.7%

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

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

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

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

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

        \[\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}}} \]
    6. 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}}} \]
    7. Taylor expanded in y around 0 44.6%

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

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

        \[\leadsto \color{blue}{\frac{{y}^{2}}{{x}^{2}} \cdot -2} + 1 \]
      3. fma-define44.6%

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

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

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

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

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

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

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

Alternative 4: 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 68.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-define68.7%

      \[\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-sqrt68.7%

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

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

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

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

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

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

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

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

Alternative 5: 92.2% 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}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \left(\frac{x}{y} - {\left(\frac{x}{y}\right)}^{2}\right)}{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) (/ (+ 1.0 (- (/ x y) (pow (/ x y) 2.0))) 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) * ((1.0 + ((x / y) - pow((x / y), 2.0))) / 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) * ((1.0d0 + ((x / y) - ((x / y) ** 2.0d0))) / 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) * ((1.0 + ((x / y) - Math.pow((x / y), 2.0))) / 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) * ((1.0 + ((x / y) - math.pow((x / y), 2.0))) / 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(x - y) * Float64(Float64(1.0 + Float64(Float64(x / y) - (Float64(x / y) ^ 2.0))) / 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) * ((1.0 + ((x / y) - ((x / y) ^ 2.0))) / 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[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(N[(x / y), $MachinePrecision] - N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $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}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{1 + \left(\frac{x}{y} - {\left(\frac{x}{y}\right)}^{2}\right)}{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 100.0%

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

    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-/l*3.1%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-define3.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. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity3.1%

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

        \[\leadsto \left(x - y\right) \cdot \frac{1 \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-frac3.1%

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

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

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

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

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}\right)} \]
    7. Taylor expanded in y around inf 52.4%

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

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

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

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

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

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

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

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

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

    \[\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}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \left(\frac{x}{y} - {\left(\frac{x}{y}\right)}^{2}\right)}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 72.6% 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}:\\ \;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{x - y}} \cdot \left(1 + \frac{x}{y}\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 (* (/ 1.0 (/ (hypot x y) (- x y))) (+ 1.0 (/ 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 = (1.0 / (hypot(x, y) / (x - y))) * (1.0 + (x / y));
	}
	return tmp;
}
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 = (1.0 / (Math.hypot(x, y) / (x - y))) * (1.0 + (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 = (1.0 / (math.hypot(x, y) / (x - y))) * (1.0 + (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(1.0 / Float64(hypot(x, y) / Float64(x - y))) * Float64(1.0 + 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 = (1.0 / (hypot(x, y) / (x - y))) * (1.0 + (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[(1.0 / N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + 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{1}{\frac{\mathsf{hypot}\left(x, y\right)}{x - y}} \cdot \left(1 + \frac{x}{y}\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 100.0%

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

    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. Add Preprocessing
    3. Step-by-step derivation
      1. fma-define0.0%

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

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

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

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

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

        \[\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. Taylor expanded in x around 0 14.1%

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(\frac{\mathsf{hypot}\left(x, y\right)}{x - y}\right)}^{-1}} \cdot \left(\frac{x}{y} + 1\right) \]
    10. Step-by-step derivation
      1. unpow-114.1%

        \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{x - y}}} \cdot \left(\frac{x}{y} + 1\right) \]
    11. Simplified14.1%

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

    \[\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{1}{\frac{\mathsf{hypot}\left(x, y\right)}{x - y}} \cdot \left(1 + \frac{x}{y}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 55.6% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.3 \cdot 10^{-161}:\\
\;\;\;\;\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(1 + \frac{x}{y}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 4.29999999999999967e-161

    1. Initial program 53.0%

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

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

        \[\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-frac53.3%

        \[\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-define53.3%

        \[\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-define53.3%

        \[\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-define53.3%

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

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

      \[\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 24.4%

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

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

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

    if 4.29999999999999967e-161 < x

    1. Initial program 82.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*81.5%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 4.3 \cdot 10^{-161}:\\ \;\;\;\;\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(1 + \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 71.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2.7 \cdot 10^{-61}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(\frac{y}{x} + 1\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x 2.7e-61)
   (* (- x y) (/ (+ 1.0 (/ x y)) y))
   (* (/ (- x y) (hypot x y)) (+ (/ y x) 1.0))))
double code(double x, double y) {
	double tmp;
	if (x <= 2.7e-61) {
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	} else {
		tmp = ((x - y) / hypot(x, y)) * ((y / x) + 1.0);
	}
	return tmp;
}
public static double code(double x, double y) {
	double tmp;
	if (x <= 2.7e-61) {
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	} else {
		tmp = ((x - y) / Math.hypot(x, y)) * ((y / x) + 1.0);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= 2.7e-61:
		tmp = (x - y) * ((1.0 + (x / y)) / y)
	else:
		tmp = ((x - y) / math.hypot(x, y)) * ((y / x) + 1.0)
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= 2.7e-61)
		tmp = Float64(Float64(x - y) * Float64(Float64(1.0 + Float64(x / y)) / y));
	else
		tmp = Float64(Float64(Float64(x - y) / hypot(x, y)) * Float64(Float64(y / x) + 1.0));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= 2.7e-61)
		tmp = (x - y) * ((1.0 + (x / y)) / y);
	else
		tmp = ((x - y) / hypot(x, y)) * ((y / x) + 1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, 2.7e-61], N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(y / x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.7 \cdot 10^{-61}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2.69999999999999993e-61

    1. Initial program 65.2%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified64.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 76.5%

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

    if 2.69999999999999993e-61 < x

    1. Initial program 83.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-define83.7%

        \[\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-sqrt83.7%

        \[\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-frac84.2%

        \[\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-define84.2%

        \[\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-define84.2%

        \[\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-define84.2%

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

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

      \[\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 inf 65.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.7 \cdot 10^{-61}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(\frac{y}{x} + 1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 43.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x - y}{\mathsf{hypot}\left(x, y\right)}\\ \mathbf{if}\;y \leq 5.2 \cdot 10^{-198}:\\ \;\;\;\;t\_0 \cdot \left(\frac{y}{x} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(1 + \frac{x}{y}\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (- x y) (hypot x y))))
   (if (<= y 5.2e-198) (* t_0 (+ (/ y x) 1.0)) (* t_0 (+ 1.0 (/ x y))))))
double code(double x, double y) {
	double t_0 = (x - y) / hypot(x, y);
	double tmp;
	if (y <= 5.2e-198) {
		tmp = t_0 * ((y / x) + 1.0);
	} else {
		tmp = t_0 * (1.0 + (x / y));
	}
	return tmp;
}
public static double code(double x, double y) {
	double t_0 = (x - y) / Math.hypot(x, y);
	double tmp;
	if (y <= 5.2e-198) {
		tmp = t_0 * ((y / x) + 1.0);
	} else {
		tmp = t_0 * (1.0 + (x / y));
	}
	return tmp;
}
def code(x, y):
	t_0 = (x - y) / math.hypot(x, y)
	tmp = 0
	if y <= 5.2e-198:
		tmp = t_0 * ((y / x) + 1.0)
	else:
		tmp = t_0 * (1.0 + (x / y))
	return tmp
function code(x, y)
	t_0 = Float64(Float64(x - y) / hypot(x, y))
	tmp = 0.0
	if (y <= 5.2e-198)
		tmp = Float64(t_0 * Float64(Float64(y / x) + 1.0));
	else
		tmp = Float64(t_0 * Float64(1.0 + Float64(x / y)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = (x - y) / hypot(x, y);
	tmp = 0.0;
	if (y <= 5.2e-198)
		tmp = t_0 * ((y / x) + 1.0);
	else
		tmp = t_0 * (1.0 + (x / y));
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 5.2e-198], N[(t$95$0 * N[(N[(y / x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 5.20000000000000014e-198

    1. Initial program 64.2%

      \[\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-define64.2%

        \[\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-sqrt64.2%

        \[\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-frac64.2%

        \[\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-define64.2%

        \[\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-define64.3%

        \[\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-define64.3%

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

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

      \[\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 inf 35.1%

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

    if 5.20000000000000014e-198 < y

    1. Initial program 85.4%

      \[\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-define85.4%

        \[\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-sqrt85.4%

        \[\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-frac85.4%

        \[\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-define85.4%

        \[\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-define85.5%

        \[\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-define85.5%

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

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

      \[\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 72.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 5.2 \cdot 10^{-198}:\\ \;\;\;\;\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(\frac{y}{x} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(1 + \frac{x}{y}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 70.9% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.2 \cdot 10^{-60}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.20000000000000005e-60

    1. Initial program 65.2%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified64.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 76.5%

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

    if 1.20000000000000005e-60 < x

    1. Initial program 83.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-define83.7%

        \[\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-sqrt83.7%

        \[\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-frac84.2%

        \[\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-define84.2%

        \[\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-define84.2%

        \[\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-define84.2%

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

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

      \[\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 inf 65.4%

      \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \color{blue}{\left(1 + \frac{y}{x}\right)} \]
    6. Taylor expanded in x around inf 64.9%

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

        \[\leadsto 1 + \color{blue}{\left(\left(-1 \cdot \frac{{y}^{2}}{{x}^{2}} + \left(-0.5 \cdot \frac{{y}^{2}}{{x}^{2}} + \frac{y}{x}\right)\right) + -1 \cdot \frac{y}{x}\right)} \]
      2. associate-+r+64.9%

        \[\leadsto 1 + \left(\color{blue}{\left(\left(-1 \cdot \frac{{y}^{2}}{{x}^{2}} + -0.5 \cdot \frac{{y}^{2}}{{x}^{2}}\right) + \frac{y}{x}\right)} + -1 \cdot \frac{y}{x}\right) \]
      3. distribute-rgt-out64.9%

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

        \[\leadsto 1 + \left(\left(\frac{{y}^{2}}{{x}^{2}} \cdot \color{blue}{-1.5} + \frac{y}{x}\right) + -1 \cdot \frac{y}{x}\right) \]
      5. *-commutative64.9%

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

        \[\leadsto 1 + \color{blue}{\left(-1.5 \cdot \frac{{y}^{2}}{{x}^{2}} + \left(\frac{y}{x} + -1 \cdot \frac{y}{x}\right)\right)} \]
      7. unpow264.9%

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

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

        \[\leadsto 1 + \left(-1.5 \cdot \color{blue}{\left(\frac{y}{x} \cdot \frac{y}{x}\right)} + \left(\frac{y}{x} + -1 \cdot \frac{y}{x}\right)\right) \]
      10. unpow264.9%

        \[\leadsto 1 + \left(-1.5 \cdot \color{blue}{{\left(\frac{y}{x}\right)}^{2}} + \left(\frac{y}{x} + -1 \cdot \frac{y}{x}\right)\right) \]
      11. distribute-rgt1-in64.9%

        \[\leadsto 1 + \left(-1.5 \cdot {\left(\frac{y}{x}\right)}^{2} + \color{blue}{\left(-1 + 1\right) \cdot \frac{y}{x}}\right) \]
      12. metadata-eval64.9%

        \[\leadsto 1 + \left(-1.5 \cdot {\left(\frac{y}{x}\right)}^{2} + \color{blue}{0} \cdot \frac{y}{x}\right) \]
      13. mul0-lft65.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.2 \cdot 10^{-60}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + {\left(\frac{y}{x}\right)}^{2} \cdot -1.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 92.2% accurate, 0.4× 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}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{-1 + x \cdot \left(\frac{1}{y} + \frac{2}{x}\right)}{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) (/ (+ -1.0 (* x (+ (/ 1.0 y) (/ 2.0 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) * ((-1.0 + (x * ((1.0 / y) + (2.0 / 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) * (((-1.0d0) + (x * ((1.0d0 / y) + (2.0d0 / 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) * ((-1.0 + (x * ((1.0 / y) + (2.0 / 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) * ((-1.0 + (x * ((1.0 / y) + (2.0 / 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(x - y) * Float64(Float64(-1.0 + Float64(x * Float64(Float64(1.0 / y) + Float64(2.0 / 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) * ((-1.0 + (x * ((1.0 / y) + (2.0 / 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[(x - y), $MachinePrecision] * N[(N[(-1.0 + N[(x * N[(N[(1.0 / y), $MachinePrecision] + N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $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}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{-1 + x \cdot \left(\frac{1}{y} + \frac{2}{x}\right)}{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 100.0%

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

    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-/l*3.1%

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}} \]
      2. fma-define3.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. Add Preprocessing
    5. Taylor expanded in y around inf 79.0%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1 + \frac{x}{y}}{y}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u78.4%

        \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 + \frac{x}{y}\right)\right)}}{y} \]
      2. expm1-undefine78.4%

        \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{e^{\mathsf{log1p}\left(1 + \frac{x}{y}\right)} - 1}}{y} \]
    7. Applied egg-rr78.4%

      \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{e^{\mathsf{log1p}\left(1 + \frac{x}{y}\right)} - 1}}{y} \]
    8. Step-by-step derivation
      1. sub-neg78.4%

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

        \[\leadsto \left(x - y\right) \cdot \frac{e^{\color{blue}{\log \left(1 + \left(1 + \frac{x}{y}\right)\right)}} + \left(-1\right)}{y} \]
      3. rem-exp-log79.0%

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

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

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

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

      \[\leadsto \left(x - y\right) \cdot \frac{\color{blue}{\left(2 + \frac{x}{y}\right) + -1}}{y} \]
    10. Taylor expanded in x around inf 78.7%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x \cdot \color{blue}{\left(\frac{1}{y} + 2 \cdot \frac{1}{x}\right)} + -1}{y} \]
      2. associate-*r/78.7%

        \[\leadsto \left(x - y\right) \cdot \frac{x \cdot \left(\frac{1}{y} + \color{blue}{\frac{2 \cdot 1}{x}}\right) + -1}{y} \]
      3. metadata-eval78.7%

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

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

    \[\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}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{-1 + x \cdot \left(\frac{1}{y} + \frac{2}{x}\right)}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 83.6% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.3 \cdot 10^{-162}:\\
\;\;\;\;\frac{x - y}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2.2999999999999998e-162

    1. Initial program 53.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*53.0%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified53.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 x around 0 84.9%

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{y}} \]
    6. Step-by-step derivation
      1. un-div-inv85.2%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
    7. Applied egg-rr85.2%

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

    if 2.2999999999999998e-162 < x

    1. Initial program 82.0%

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification83.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.3 \cdot 10^{-162}:\\ \;\;\;\;\frac{x - y}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 69.9% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.95 \cdot 10^{-60}:\\
\;\;\;\;-1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.9500000000000001e-60

    1. Initial program 65.2%

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

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified64.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 75.9%

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

    if 1.9500000000000001e-60 < x

    1. Initial program 83.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*83.7%

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

        \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    3. Simplified83.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 inf 63.6%

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

        \[\leadsto \color{blue}{\frac{x - y}{x}} \]
    7. Applied egg-rr63.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.95 \cdot 10^{-60}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 65.8% accurate, 3.0× speedup?

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

\\
\frac{x - y}{y}
\end{array}
Derivation
  1. Initial program 68.7%

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

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

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

    \[\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 68.1%

    \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{y}} \]
  6. Step-by-step derivation
    1. un-div-inv68.2%

      \[\leadsto \color{blue}{\frac{x - y}{y}} \]
  7. Applied egg-rr68.2%

    \[\leadsto \color{blue}{\frac{x - y}{y}} \]
  8. Final simplification68.2%

    \[\leadsto \frac{x - y}{y} \]
  9. Add Preprocessing

Alternative 15: 65.6% 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 68.7%

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

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

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

    \[\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 68.2%

    \[\leadsto \color{blue}{-1} \]
  6. Final simplification68.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 2024066 
(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))))