Kahan p9 Example

Percentage Accurate: 68.5% → 100.0%
Time: 8.6s
Alternatives: 14
Speedup: 4.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 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: 100.0% accurate, 0.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \frac{x - y}{\mathsf{hypot}\left(x, y\right) \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (/ (- x y) (* (hypot x y) (/ (hypot x y) (+ x y)))))
y = abs(y);
double code(double x, double y) {
	return (x - y) / (hypot(x, y) * (hypot(x, y) / (x + y)));
}
y = Math.abs(y);
public static double code(double x, double y) {
	return (x - y) / (Math.hypot(x, y) * (Math.hypot(x, y) / (x + y)));
}
y = abs(y)
def code(x, y):
	return (x - y) / (math.hypot(x, y) * (math.hypot(x, y) / (x + y)))
y = abs(y)
function code(x, y)
	return Float64(Float64(x - y) / Float64(hypot(x, y) * Float64(hypot(x, y) / Float64(x + y))))
end
y = abs(y)
function tmp = code(x, y)
	tmp = (x - y) / (hypot(x, y) * (hypot(x, y) / (x + y)));
end
NOTE: y should be positive before calling this function
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] * N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{x - y}{\mathsf{hypot}\left(x, y\right) \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}}
\end{array}
Derivation
  1. Initial program 62.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*63.4%

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
    2. fma-def63.4%

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

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

      \[\leadsto \frac{x - y}{\frac{\color{blue}{x \cdot x + y \cdot y}}{x + y}} \]
    2. div-inv63.2%

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

      \[\leadsto \frac{x - y}{\color{blue}{\left(\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}\right)} \cdot \frac{1}{x + y}} \]
    4. associate-*l*63.3%

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

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

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

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

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

      \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\mathsf{hypot}\left(x, y\right) \cdot \frac{1}{x + y}\right)} - 1\right)}} \]
    3. un-div-inv98.4%

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

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

      \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{hypot}\left(x, y\right)}{x + y}\right)\right)}} \]
    2. expm1-log1p99.9%

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

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

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

Alternative 2: 99.9% accurate, 0.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \frac{x + y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x - y}{\mathsf{hypot}\left(x, y\right)} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (* (/ (+ x y) (hypot x y)) (/ (- x y) (hypot x y))))
y = abs(y);
double code(double x, double y) {
	return ((x + y) / hypot(x, y)) * ((x - y) / hypot(x, y));
}
y = Math.abs(y);
public static double code(double x, double y) {
	return ((x + y) / Math.hypot(x, y)) * ((x - y) / Math.hypot(x, y));
}
y = abs(y)
def code(x, y):
	return ((x + y) / math.hypot(x, y)) * ((x - y) / math.hypot(x, y))
y = abs(y)
function code(x, y)
	return Float64(Float64(Float64(x + y) / hypot(x, y)) * Float64(Float64(x - y) / hypot(x, y)))
end
y = abs(y)
function tmp = code(x, y)
	tmp = ((x + y) / hypot(x, y)) * ((x - y) / hypot(x, y));
end
NOTE: y should be positive before calling this function
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}
y = |y|\\
\\
\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 62.9%

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

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

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

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

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

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

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

Alternative 3: 99.9% accurate, 0.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \frac{\left(x - y\right) \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y)))
y = abs(y);
double code(double x, double y) {
	return ((x - y) * ((x + y) / hypot(x, y))) / hypot(x, y);
}
y = Math.abs(y);
public static double code(double x, double y) {
	return ((x - y) * ((x + y) / Math.hypot(x, y))) / Math.hypot(x, y);
}
y = abs(y)
def code(x, y):
	return ((x - y) * ((x + y) / math.hypot(x, y))) / math.hypot(x, y)
y = abs(y)
function code(x, y)
	return Float64(Float64(Float64(x - y) * Float64(Float64(x + y) / hypot(x, y))) / hypot(x, y))
end
y = abs(y)
function tmp = code(x, y)
	tmp = ((x - y) * ((x + y) / hypot(x, y))) / hypot(x, y);
end
NOTE: y should be positive before calling this function
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{\left(x - y\right) \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Derivation
  1. Initial program 62.9%

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

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

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

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

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

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

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

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

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

Alternative 4: 93.0% accurate, 0.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \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)}{1.5 \cdot \left(x \cdot \frac{x}{y}\right) - y}}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(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) (- (* 1.5 (* x (/ x y))) y))))))
y = abs(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) / ((1.5 * (x * (x / y))) - y));
	}
	return tmp;
}
y = Math.abs(y);
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) / ((1.5 * (x * (x / y))) - y));
	}
	return tmp;
}
y = abs(y)
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) / ((1.5 * (x * (x / y))) - y))
	return tmp
y = abs(y)
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(1.0 / Float64(hypot(x, y) / Float64(Float64(1.5 * Float64(x * Float64(x / y))) - y)));
	end
	return tmp
end
y = abs(y)
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) / ((1.5 * (x * (x / y))) - y));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
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[(1.0 / N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(N[(1.5 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\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)}{1.5 \cdot \left(x \cdot \frac{x}{y}\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} \]

    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. add-sqr-sqrt0.0%

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{1.5 \cdot \frac{{x}^{2}}{y} + -1 \cdot y}}{\mathsf{hypot}\left(x, y\right)} \]
    7. Step-by-step derivation
      1. fma-def13.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(1.5, \frac{\color{blue}{x \cdot x}}{y}, -1 \cdot y\right)}{\mathsf{hypot}\left(x, y\right)} \]
      3. associate-*r/15.1%

        \[\leadsto \frac{\mathsf{fma}\left(1.5, \color{blue}{x \cdot \frac{x}{y}}, -1 \cdot y\right)}{\mathsf{hypot}\left(x, y\right)} \]
      4. mul-1-neg15.1%

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

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

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

        \[\leadsto \color{blue}{{\left(\frac{\mathsf{hypot}\left(x, y\right)}{\mathsf{fma}\left(1.5, x \cdot \frac{x}{y}, -y\right)}\right)}^{-1}} \]
    10. Applied egg-rr15.1%

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

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

        \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{\color{blue}{1.5 \cdot \left(x \cdot \frac{x}{y}\right) - y}}} \]
    12. Simplified15.1%

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

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

Alternative 5: 93.0% accurate, 0.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \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.5 \cdot \left(x \cdot \frac{x}{y}\right) - y}{\mathsf{hypot}\left(x, y\right)}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
   (if (<= t_0 2.0) t_0 (/ (- (* 1.5 (* x (/ x y))) y) (hypot x y)))))
y = abs(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.5 * (x * (x / y))) - y) / hypot(x, y);
	}
	return tmp;
}
y = Math.abs(y);
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.5 * (x * (x / y))) - y) / Math.hypot(x, y);
	}
	return tmp;
}
y = abs(y)
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.5 * (x * (x / y))) - y) / math.hypot(x, y)
	return tmp
y = abs(y)
function code(x, y)
	t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)))
	tmp = 0.0
	if (t_0 <= 2.0)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(1.5 * Float64(x * Float64(x / y))) - y) / hypot(x, y));
	end
	return tmp
end
y = abs(y)
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.5 * (x * (x / y))) - y) / hypot(x, y);
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(N[(1.5 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\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.5 \cdot \left(x \cdot \frac{x}{y}\right) - y}{\mathsf{hypot}\left(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} \]

    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. add-sqr-sqrt0.0%

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{1.5 \cdot \frac{{x}^{2}}{y} + -1 \cdot y}}{\mathsf{hypot}\left(x, y\right)} \]
    7. Step-by-step derivation
      1. fma-def13.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(1.5, \frac{\color{blue}{x \cdot x}}{y}, -1 \cdot y\right)}{\mathsf{hypot}\left(x, y\right)} \]
      3. associate-*r/15.1%

        \[\leadsto \frac{\mathsf{fma}\left(1.5, \color{blue}{x \cdot \frac{x}{y}}, -1 \cdot y\right)}{\mathsf{hypot}\left(x, y\right)} \]
      4. mul-1-neg15.1%

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(1.5, x \cdot \frac{x}{y}, -y\right)}}{\mathsf{hypot}\left(x, y\right)} \]
    9. Taylor expanded in x around 0 13.9%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(1.5, \frac{\color{blue}{x \cdot x}}{y}, -1 \cdot y\right)}{\mathsf{hypot}\left(x, y\right)} \]
      3. associate-*r/15.1%

        \[\leadsto \frac{\mathsf{fma}\left(1.5, \color{blue}{x \cdot \frac{x}{y}}, -1 \cdot y\right)}{\mathsf{hypot}\left(x, y\right)} \]
      4. neg-mul-115.1%

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

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

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

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

Alternative 6: 92.9% accurate, 0.5× speedup?

\[\begin{array}{l} y = |y|\\ \\ \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{x \cdot \frac{x}{y}}{y} + \left(\frac{x}{y} \cdot \frac{x}{y} + -1\right)\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
   (if (<= t_0 2.0) t_0 (+ (/ (* x (/ x y)) y) (+ (* (/ x y) (/ x y)) -1.0)))))
y = abs(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 * (x / y)) / y) + (((x / y) * (x / y)) + -1.0);
	}
	return tmp;
}
NOTE: y should be positive before calling this function
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 * (x / y)) / y) + (((x / y) * (x / y)) + (-1.0d0))
    end if
    code = tmp
end function
y = Math.abs(y);
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 * (x / y)) / y) + (((x / y) * (x / y)) + -1.0);
	}
	return tmp;
}
y = abs(y)
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 * (x / y)) / y) + (((x / y) * (x / y)) + -1.0)
	return tmp
y = abs(y)
function code(x, y)
	t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)))
	tmp = 0.0
	if (t_0 <= 2.0)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(x * Float64(x / y)) / y) + Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0));
	end
	return tmp
end
y = abs(y)
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 * (x / y)) / y) + (((x / y) * (x / y)) + -1.0);
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] + N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\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{x \cdot \frac{x}{y}}{y} + \left(\frac{x}{y} \cdot \frac{x}{y} + -1\right)\\


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

    1. Initial program 100.0%

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

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

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 92.4% accurate, 0.5× speedup?

\[\begin{array}{l} y = |y|\\ \\ \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}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(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)))
y = abs(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;
	}
	return tmp;
}
NOTE: y should be positive before calling this function
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 = -1.0d0
    end if
    code = tmp
end function
y = Math.abs(y);
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;
	}
	return tmp;
}
y = abs(y)
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
	return tmp
y = abs(y)
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 = -1.0;
	end
	return tmp
end
y = abs(y)
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;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
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, -1.0]]
\begin{array}{l}
y = |y|\\
\\
\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}:\\
\;\;\;\;-1\\


\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} \]

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

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

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

Alternative 8: 93.0% accurate, 0.5× speedup?

\[\begin{array}{l} y = |y|\\ \\ \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{x - y}{y + \left(\frac{x}{y} \cdot \left(x + x\right) - x\right)}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
   (if (<= t_0 2.0) t_0 (/ (- x y) (+ y (- (* (/ x y) (+ x x)) x))))))
y = abs(y);
double code(double x, double y) {
	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	double tmp;
	if (t_0 <= 2.0) {
		tmp = t_0;
	} else {
		tmp = (x - y) / (y + (((x / y) * (x + x)) - x));
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
    if (t_0 <= 2.0d0) then
        tmp = t_0
    else
        tmp = (x - y) / (y + (((x / y) * (x + x)) - x))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	double tmp;
	if (t_0 <= 2.0) {
		tmp = t_0;
	} else {
		tmp = (x - y) / (y + (((x / y) * (x + x)) - x));
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
	tmp = 0
	if t_0 <= 2.0:
		tmp = t_0
	else:
		tmp = (x - y) / (y + (((x / y) * (x + x)) - x))
	return tmp
y = abs(y)
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(y + Float64(Float64(Float64(x / y) * Float64(x + x)) - x)));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
	tmp = 0.0;
	if (t_0 <= 2.0)
		tmp = t_0;
	else
		tmp = (x - y) / (y + (((x / y) * (x + x)) - x));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
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[(y + N[(N[(N[(x / y), $MachinePrecision] * N[(x + x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\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{x - y}{y + \left(\frac{x}{y} \cdot \left(x + x\right) - x\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} \]

    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}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def3.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{x - y}{y + \left(\frac{x}{\frac{y}{x}} + \left(\frac{{x}^{2}}{y} + \color{blue}{\left(-x\right)}\right)\right)} \]
      12. unsub-neg75.7%

        \[\leadsto \frac{x - y}{y + \left(\frac{x}{\frac{y}{x}} + \color{blue}{\left(\frac{{x}^{2}}{y} - x\right)}\right)} \]
      13. unpow275.7%

        \[\leadsto \frac{x - y}{y + \left(\frac{x}{\frac{y}{x}} + \left(\frac{\color{blue}{x \cdot x}}{y} - x\right)\right)} \]
      14. associate-/l*76.5%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{x - y}{y + \color{blue}{\left(\frac{x}{y} \cdot \left(x + x\right) - x\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.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}:\\ \;\;\;\;\frac{x - y}{y + \left(\frac{x}{y} \cdot \left(x + x\right) - x\right)}\\ \end{array} \]

Alternative 9: 83.6% accurate, 1.1× speedup?

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

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


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

    1. Initial program 58.1%

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

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

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

        \[\leadsto 1 + -2 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}} \]
    4. Simplified27.7%

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

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

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

    if 5.50000000000000036e-127 < 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*99.8%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def99.8%

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

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

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

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

Alternative 10: 83.0% accurate, 1.4× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 5.5 \cdot 10^{-127}:\\ \;\;\;\;\left(1 + \frac{y}{x}\right) - \frac{y}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{y}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 5.5e-127) (- (+ 1.0 (/ y x)) (/ y x)) (/ (- x y) y)))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 5.5e-127) {
		tmp = (1.0 + (y / x)) - (y / x);
	} else {
		tmp = (x - y) / y;
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 5.5d-127) then
        tmp = (1.0d0 + (y / x)) - (y / x)
    else
        tmp = (x - y) / y
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 5.5e-127) {
		tmp = (1.0 + (y / x)) - (y / x);
	} else {
		tmp = (x - y) / y;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 5.5e-127:
		tmp = (1.0 + (y / x)) - (y / x)
	else:
		tmp = (x - y) / y
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 5.5e-127)
		tmp = Float64(Float64(1.0 + Float64(y / x)) - Float64(y / x));
	else
		tmp = Float64(Float64(x - y) / y);
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 5.5e-127)
		tmp = (1.0 + (y / x)) - (y / x);
	else
		tmp = (x - y) / y;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 5.5e-127], N[(N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision] - N[(y / x), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.5 \cdot 10^{-127}:\\
\;\;\;\;\left(1 + \frac{y}{x}\right) - \frac{y}{x}\\

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


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

    1. Initial program 58.1%

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

      \[\leadsto \color{blue}{\frac{y}{x} + \left(1 + -1 \cdot \frac{y}{x}\right)} \]
    3. Step-by-step derivation
      1. associate-+r+36.4%

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

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

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

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

    if 5.50000000000000036e-127 < 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*99.8%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def99.8%

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

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

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

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

Alternative 11: 82.8% accurate, 2.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.22 \cdot 10^{-119}:\\ \;\;\;\;\frac{x - y}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y) :precision binary64 (if (<= y 1.22e-119) (/ (- x y) x) -1.0))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 1.22e-119) {
		tmp = (x - y) / x;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 1.22d-119) then
        tmp = (x - y) / x
    else
        tmp = -1.0d0
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 1.22e-119) {
		tmp = (x - y) / x;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 1.22e-119:
		tmp = (x - y) / x
	else:
		tmp = -1.0
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 1.22e-119)
		tmp = Float64(Float64(x - y) / x);
	else
		tmp = -1.0;
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1.22e-119)
		tmp = (x - y) / x;
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 1.22e-119], N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision], -1.0]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.22 \cdot 10^{-119}:\\
\;\;\;\;\frac{x - y}{x}\\

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


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

    1. Initial program 58.1%

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

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def58.7%

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

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

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

    if 1.22e-119 < y

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.22 \cdot 10^{-119}:\\ \;\;\;\;\frac{x - y}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternative 12: 82.8% accurate, 2.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.22 \cdot 10^{-119}:\\ \;\;\;\;\frac{x - y}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{y}\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 1.22e-119) (/ (- x y) x) (/ (- x y) y)))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 1.22e-119) {
		tmp = (x - y) / x;
	} else {
		tmp = (x - y) / y;
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 1.22d-119) then
        tmp = (x - y) / x
    else
        tmp = (x - y) / y
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 1.22e-119) {
		tmp = (x - y) / x;
	} else {
		tmp = (x - y) / y;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 1.22e-119:
		tmp = (x - y) / x
	else:
		tmp = (x - y) / y
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 1.22e-119)
		tmp = Float64(Float64(x - y) / x);
	else
		tmp = Float64(Float64(x - y) / y);
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1.22e-119)
		tmp = (x - y) / x;
	else
		tmp = (x - y) / y;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 1.22e-119], N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.22 \cdot 10^{-119}:\\
\;\;\;\;\frac{x - y}{x}\\

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


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

    1. Initial program 58.1%

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

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def58.7%

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

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

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

    if 1.22e-119 < 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*99.8%

        \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}} \]
      2. fma-def99.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.22 \cdot 10^{-119}:\\ \;\;\;\;\frac{x - y}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{y}\\ \end{array} \]

Alternative 13: 82.6% accurate, 4.9× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.2 \cdot 10^{-125}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y) :precision binary64 (if (<= y 1.2e-125) 1.0 -1.0))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 1.2e-125) {
		tmp = 1.0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 1.2d-125) then
        tmp = 1.0d0
    else
        tmp = -1.0d0
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 1.2e-125) {
		tmp = 1.0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 1.2e-125:
		tmp = 1.0
	else:
		tmp = -1.0
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 1.2e-125)
		tmp = 1.0;
	else
		tmp = -1.0;
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1.2e-125)
		tmp = 1.0;
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 1.2e-125], 1.0, -1.0]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.2 \cdot 10^{-125}:\\
\;\;\;\;1\\

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


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

    1. Initial program 58.1%

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

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

    if 1.2000000000000001e-125 < y

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.2 \cdot 10^{-125}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternative 14: 66.4% accurate, 15.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ -1 \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y) :precision binary64 -1.0)
y = abs(y);
double code(double x, double y) {
	return -1.0;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = -1.0d0
end function
y = Math.abs(y);
public static double code(double x, double y) {
	return -1.0;
}
y = abs(y)
def code(x, y):
	return -1.0
y = abs(y)
function code(x, y)
	return -1.0
end
y = abs(y)
function tmp = code(x, y)
	tmp = -1.0;
end
NOTE: y should be positive before calling this function
code[x_, y_] := -1.0
\begin{array}{l}
y = |y|\\
\\
-1
\end{array}
Derivation
  1. Initial program 62.9%

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

    \[\leadsto \color{blue}{-1} \]
  3. Final simplification65.1%

    \[\leadsto -1 \]

Developer target: 99.9% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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

  :herbie-target
  (if (and (< 0.5 (fabs (/ x y))) (< (fabs (/ x y)) 2.0)) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

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