Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3

Percentage Accurate: 51.3% → 99.9%
Time: 11.0s
Alternatives: 7
Speedup: 1.2×

Specification

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

\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t\_0}{x \cdot x + t\_0}
\end{array}
\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 7 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: 51.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t\_0}{x \cdot x + t\_0}
\end{array}
\end{array}

Alternative 1: 99.9% accurate, 0.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ y_m = \left|y\right| \\ \begin{array}{l} t_0 := \mathsf{hypot}\left(x\_m, y\_m \cdot 2\right)\\ \frac{\frac{x\_m + -2 \cdot y\_m}{t\_0} \cdot \mathsf{fma}\left(y\_m, 2, x\_m\right)}{t\_0} \end{array} \end{array} \]
x_m = (fabs.f64 x)
y_m = (fabs.f64 y)
(FPCore (x_m y_m)
 :precision binary64
 (let* ((t_0 (hypot x_m (* y_m 2.0))))
   (/ (* (/ (+ x_m (* -2.0 y_m)) t_0) (fma y_m 2.0 x_m)) t_0)))
x_m = fabs(x);
y_m = fabs(y);
double code(double x_m, double y_m) {
	double t_0 = hypot(x_m, (y_m * 2.0));
	return (((x_m + (-2.0 * y_m)) / t_0) * fma(y_m, 2.0, x_m)) / t_0;
}
x_m = abs(x)
y_m = abs(y)
function code(x_m, y_m)
	t_0 = hypot(x_m, Float64(y_m * 2.0))
	return Float64(Float64(Float64(Float64(x_m + Float64(-2.0 * y_m)) / t_0) * fma(y_m, 2.0, x_m)) / t_0)
end
x_m = N[Abs[x], $MachinePrecision]
y_m = N[Abs[y], $MachinePrecision]
code[x$95$m_, y$95$m_] := Block[{t$95$0 = N[Sqrt[x$95$m ^ 2 + N[(y$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, N[(N[(N[(N[(x$95$m + N[(-2.0 * y$95$m), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] * N[(y$95$m * 2.0 + x$95$m), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|

\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x\_m, y\_m \cdot 2\right)\\
\frac{\frac{x\_m + -2 \cdot y\_m}{t\_0} \cdot \mathsf{fma}\left(y\_m, 2, x\_m\right)}{t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 54.3%

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

      \[\leadsto \frac{x \cdot x - \color{blue}{\sqrt{\left(y \cdot 4\right) \cdot y} \cdot \sqrt{\left(y \cdot 4\right) \cdot y}}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. difference-of-squares54.3%

      \[\leadsto \frac{\color{blue}{\left(x + \sqrt{\left(y \cdot 4\right) \cdot y}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    3. *-commutative54.3%

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

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

      \[\leadsto \frac{\left(x + \color{blue}{\sqrt{y \cdot y} \cdot \sqrt{4}}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    6. sqrt-unprod24.9%

      \[\leadsto \frac{\left(x + \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{4}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    7. add-sqr-sqrt40.3%

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

      \[\leadsto \frac{\left(x + y \cdot \color{blue}{2}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    9. *-commutative40.3%

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

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

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

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

      \[\leadsto \frac{\left(x + y \cdot 2\right) \cdot \left(x - \color{blue}{y} \cdot \sqrt{4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    14. metadata-eval54.3%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\mathsf{fma}\left(y, 2, x\right)}{\mathsf{hypot}\left(x, \color{blue}{\left(\sqrt{4} \cdot \sqrt{y}\right)} \cdot \sqrt{y}\right)} \cdot \frac{x - y \cdot 2}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \]
    10. metadata-eval25.4%

      \[\leadsto \frac{\mathsf{fma}\left(y, 2, x\right)}{\mathsf{hypot}\left(x, \left(\color{blue}{2} \cdot \sqrt{y}\right) \cdot \sqrt{y}\right)} \cdot \frac{x - y \cdot 2}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \]
    11. associate-*r*25.4%

      \[\leadsto \frac{\mathsf{fma}\left(y, 2, x\right)}{\mathsf{hypot}\left(x, \color{blue}{2 \cdot \left(\sqrt{y} \cdot \sqrt{y}\right)}\right)} \cdot \frac{x - y \cdot 2}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \]
    12. add-sqr-sqrt55.4%

      \[\leadsto \frac{\mathsf{fma}\left(y, 2, x\right)}{\mathsf{hypot}\left(x, 2 \cdot \color{blue}{y}\right)} \cdot \frac{x - y \cdot 2}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \]
    13. *-commutative55.4%

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

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

      \[\leadsto \color{blue}{\frac{x + y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \frac{\mathsf{fma}\left(y, 2, x\right)}{\mathsf{hypot}\left(x, y \cdot 2\right)}} \]
    2. associate-*r/100.0%

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

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

    \[\leadsto \color{blue}{\frac{\frac{x + -2 \cdot y}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \mathsf{fma}\left(y, 2, x\right)}{\mathsf{hypot}\left(x, y \cdot 2\right)}} \]
  9. Add Preprocessing

Alternative 2: 86.5% accurate, 0.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ y_m = \left|y\right| \\ \begin{array}{l} t_0 := y\_m \cdot \frac{2}{x\_m}\\ \mathbf{if}\;x\_m \cdot x\_m \leq 0:\\ \;\;\;\;-1\\ \mathbf{elif}\;x\_m \cdot x\_m \leq 10^{-151}:\\ \;\;\;\;\frac{\left(x\_m + y\_m \cdot 2\right) \cdot \left(x\_m - y\_m \cdot 2\right)}{x\_m \cdot x\_m + y\_m \cdot \left(y\_m \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - {t\_0}^{2}}{1 + t\_0 \cdot t\_0}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
y_m = (fabs.f64 y)
(FPCore (x_m y_m)
 :precision binary64
 (let* ((t_0 (* y_m (/ 2.0 x_m))))
   (if (<= (* x_m x_m) 0.0)
     -1.0
     (if (<= (* x_m x_m) 1e-151)
       (/
        (* (+ x_m (* y_m 2.0)) (- x_m (* y_m 2.0)))
        (+ (* x_m x_m) (* y_m (* y_m 4.0))))
       (/ (- 1.0 (pow t_0 2.0)) (+ 1.0 (* t_0 t_0)))))))
x_m = fabs(x);
y_m = fabs(y);
double code(double x_m, double y_m) {
	double t_0 = y_m * (2.0 / x_m);
	double tmp;
	if ((x_m * x_m) <= 0.0) {
		tmp = -1.0;
	} else if ((x_m * x_m) <= 1e-151) {
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)));
	} else {
		tmp = (1.0 - pow(t_0, 2.0)) / (1.0 + (t_0 * t_0));
	}
	return tmp;
}
x_m = abs(x)
y_m = abs(y)
real(8) function code(x_m, y_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = y_m * (2.0d0 / x_m)
    if ((x_m * x_m) <= 0.0d0) then
        tmp = -1.0d0
    else if ((x_m * x_m) <= 1d-151) then
        tmp = ((x_m + (y_m * 2.0d0)) * (x_m - (y_m * 2.0d0))) / ((x_m * x_m) + (y_m * (y_m * 4.0d0)))
    else
        tmp = (1.0d0 - (t_0 ** 2.0d0)) / (1.0d0 + (t_0 * t_0))
    end if
    code = tmp
end function
x_m = Math.abs(x);
y_m = Math.abs(y);
public static double code(double x_m, double y_m) {
	double t_0 = y_m * (2.0 / x_m);
	double tmp;
	if ((x_m * x_m) <= 0.0) {
		tmp = -1.0;
	} else if ((x_m * x_m) <= 1e-151) {
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)));
	} else {
		tmp = (1.0 - Math.pow(t_0, 2.0)) / (1.0 + (t_0 * t_0));
	}
	return tmp;
}
x_m = math.fabs(x)
y_m = math.fabs(y)
def code(x_m, y_m):
	t_0 = y_m * (2.0 / x_m)
	tmp = 0
	if (x_m * x_m) <= 0.0:
		tmp = -1.0
	elif (x_m * x_m) <= 1e-151:
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)))
	else:
		tmp = (1.0 - math.pow(t_0, 2.0)) / (1.0 + (t_0 * t_0))
	return tmp
x_m = abs(x)
y_m = abs(y)
function code(x_m, y_m)
	t_0 = Float64(y_m * Float64(2.0 / x_m))
	tmp = 0.0
	if (Float64(x_m * x_m) <= 0.0)
		tmp = -1.0;
	elseif (Float64(x_m * x_m) <= 1e-151)
		tmp = Float64(Float64(Float64(x_m + Float64(y_m * 2.0)) * Float64(x_m - Float64(y_m * 2.0))) / Float64(Float64(x_m * x_m) + Float64(y_m * Float64(y_m * 4.0))));
	else
		tmp = Float64(Float64(1.0 - (t_0 ^ 2.0)) / Float64(1.0 + Float64(t_0 * t_0)));
	end
	return tmp
end
x_m = abs(x);
y_m = abs(y);
function tmp_2 = code(x_m, y_m)
	t_0 = y_m * (2.0 / x_m);
	tmp = 0.0;
	if ((x_m * x_m) <= 0.0)
		tmp = -1.0;
	elseif ((x_m * x_m) <= 1e-151)
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)));
	else
		tmp = (1.0 - (t_0 ^ 2.0)) / (1.0 + (t_0 * t_0));
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
y_m = N[Abs[y], $MachinePrecision]
code[x$95$m_, y$95$m_] := Block[{t$95$0 = N[(y$95$m * N[(2.0 / x$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 0.0], -1.0, If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 1e-151], N[(N[(N[(x$95$m + N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision] * N[(x$95$m - N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(y$95$m * N[(y$95$m * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|

\\
\begin{array}{l}
t_0 := y\_m \cdot \frac{2}{x\_m}\\
\mathbf{if}\;x\_m \cdot x\_m \leq 0:\\
\;\;\;\;-1\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1 - {t\_0}^{2}}{1 + t\_0 \cdot t\_0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x x) < 0.0

    1. Initial program 53.4%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 91.5%

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

    if 0.0 < (*.f64 x x) < 9.9999999999999994e-152

    1. Initial program 77.6%

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

        \[\leadsto \frac{x \cdot x - \color{blue}{\sqrt{\left(y \cdot 4\right) \cdot y} \cdot \sqrt{\left(y \cdot 4\right) \cdot y}}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      2. difference-of-squares77.8%

        \[\leadsto \frac{\color{blue}{\left(x + \sqrt{\left(y \cdot 4\right) \cdot y}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      3. *-commutative77.8%

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

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

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

        \[\leadsto \frac{\left(x + \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{4}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      7. add-sqr-sqrt55.0%

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

        \[\leadsto \frac{\left(x + y \cdot \color{blue}{2}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      9. *-commutative55.0%

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

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

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

        \[\leadsto \frac{\left(x + y \cdot 2\right) \cdot \left(x - \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      13. add-sqr-sqrt77.8%

        \[\leadsto \frac{\left(x + y \cdot 2\right) \cdot \left(x - \color{blue}{y} \cdot \sqrt{4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      14. metadata-eval77.8%

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

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

    if 9.9999999999999994e-152 < (*.f64 x x)

    1. Initial program 49.4%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 49.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{{x}^{2} - y \cdot \left(y \cdot 4\right)}{{x}^{2}} \cdot \frac{1}{1 + {\left(y \cdot \frac{2}{x}\right)}^{2}}} \]
    10. Step-by-step derivation
      1. associate-*r/49.4%

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

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

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

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

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

Alternative 3: 81.2% accurate, 0.2× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \cdot x\_m \leq 0:\\ \;\;\;\;-1\\ \mathbf{elif}\;x\_m \cdot x\_m \leq 5 \cdot 10^{+216}:\\ \;\;\;\;\frac{\left(x\_m + y\_m \cdot 2\right) \cdot \left(x\_m - y\_m \cdot 2\right)}{x\_m \cdot x\_m + y\_m \cdot \left(y\_m \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x\_m}{\mathsf{hypot}\left(x\_m, y\_m \cdot 2\right)}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
y_m = (fabs.f64 y)
(FPCore (x_m y_m)
 :precision binary64
 (if (<= (* x_m x_m) 0.0)
   -1.0
   (if (<= (* x_m x_m) 5e+216)
     (/
      (* (+ x_m (* y_m 2.0)) (- x_m (* y_m 2.0)))
      (+ (* x_m x_m) (* y_m (* y_m 4.0))))
     (/ x_m (hypot x_m (* y_m 2.0))))))
x_m = fabs(x);
y_m = fabs(y);
double code(double x_m, double y_m) {
	double tmp;
	if ((x_m * x_m) <= 0.0) {
		tmp = -1.0;
	} else if ((x_m * x_m) <= 5e+216) {
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)));
	} else {
		tmp = x_m / hypot(x_m, (y_m * 2.0));
	}
	return tmp;
}
x_m = Math.abs(x);
y_m = Math.abs(y);
public static double code(double x_m, double y_m) {
	double tmp;
	if ((x_m * x_m) <= 0.0) {
		tmp = -1.0;
	} else if ((x_m * x_m) <= 5e+216) {
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)));
	} else {
		tmp = x_m / Math.hypot(x_m, (y_m * 2.0));
	}
	return tmp;
}
x_m = math.fabs(x)
y_m = math.fabs(y)
def code(x_m, y_m):
	tmp = 0
	if (x_m * x_m) <= 0.0:
		tmp = -1.0
	elif (x_m * x_m) <= 5e+216:
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)))
	else:
		tmp = x_m / math.hypot(x_m, (y_m * 2.0))
	return tmp
x_m = abs(x)
y_m = abs(y)
function code(x_m, y_m)
	tmp = 0.0
	if (Float64(x_m * x_m) <= 0.0)
		tmp = -1.0;
	elseif (Float64(x_m * x_m) <= 5e+216)
		tmp = Float64(Float64(Float64(x_m + Float64(y_m * 2.0)) * Float64(x_m - Float64(y_m * 2.0))) / Float64(Float64(x_m * x_m) + Float64(y_m * Float64(y_m * 4.0))));
	else
		tmp = Float64(x_m / hypot(x_m, Float64(y_m * 2.0)));
	end
	return tmp
end
x_m = abs(x);
y_m = abs(y);
function tmp_2 = code(x_m, y_m)
	tmp = 0.0;
	if ((x_m * x_m) <= 0.0)
		tmp = -1.0;
	elseif ((x_m * x_m) <= 5e+216)
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)));
	else
		tmp = x_m / hypot(x_m, (y_m * 2.0));
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
y_m = N[Abs[y], $MachinePrecision]
code[x$95$m_, y$95$m_] := If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 0.0], -1.0, If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 5e+216], N[(N[(N[(x$95$m + N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision] * N[(x$95$m - N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(y$95$m * N[(y$95$m * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m / N[Sqrt[x$95$m ^ 2 + N[(y$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \cdot x\_m \leq 0:\\
\;\;\;\;-1\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{\mathsf{hypot}\left(x\_m, y\_m \cdot 2\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x x) < 0.0

    1. Initial program 53.4%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 91.5%

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

    if 0.0 < (*.f64 x x) < 4.9999999999999998e216

    1. Initial program 81.7%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt81.7%

        \[\leadsto \frac{x \cdot x - \color{blue}{\sqrt{\left(y \cdot 4\right) \cdot y} \cdot \sqrt{\left(y \cdot 4\right) \cdot y}}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      2. difference-of-squares81.8%

        \[\leadsto \frac{\color{blue}{\left(x + \sqrt{\left(y \cdot 4\right) \cdot y}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      3. *-commutative81.8%

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

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

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

        \[\leadsto \frac{\left(x + \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{4}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      7. add-sqr-sqrt67.2%

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

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

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

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

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

        \[\leadsto \frac{\left(x + y \cdot 2\right) \cdot \left(x - \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      13. add-sqr-sqrt81.8%

        \[\leadsto \frac{\left(x + y \cdot 2\right) \cdot \left(x - \color{blue}{y} \cdot \sqrt{4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      14. metadata-eval81.8%

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

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

    if 4.9999999999999998e216 < (*.f64 x x)

    1. Initial program 20.5%

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

        \[\leadsto \frac{x \cdot x - \color{blue}{\sqrt{\left(y \cdot 4\right) \cdot y} \cdot \sqrt{\left(y \cdot 4\right) \cdot y}}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      2. difference-of-squares20.5%

        \[\leadsto \frac{\color{blue}{\left(x + \sqrt{\left(y \cdot 4\right) \cdot y}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      3. *-commutative20.5%

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

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

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

        \[\leadsto \frac{\left(x + \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{4}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      7. add-sqr-sqrt20.5%

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

        \[\leadsto \frac{\left(x + y \cdot \color{blue}{2}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      9. *-commutative20.5%

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

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

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

        \[\leadsto \frac{\left(x + y \cdot 2\right) \cdot \left(x - \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      13. add-sqr-sqrt20.5%

        \[\leadsto \frac{\left(x + y \cdot 2\right) \cdot \left(x - \color{blue}{y} \cdot \sqrt{4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      14. metadata-eval20.5%

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(y, 2, x\right)}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \frac{x - y \cdot 2}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \]
      5. add-sqr-sqrt22.9%

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(y, 2, x\right)}{\mathsf{hypot}\left(x, \left(\color{blue}{2} \cdot \sqrt{y}\right) \cdot \sqrt{y}\right)} \cdot \frac{x - y \cdot 2}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \]
      11. associate-*r*15.0%

        \[\leadsto \frac{\mathsf{fma}\left(y, 2, x\right)}{\mathsf{hypot}\left(x, \color{blue}{2 \cdot \left(\sqrt{y} \cdot \sqrt{y}\right)}\right)} \cdot \frac{x - y \cdot 2}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \]
      12. add-sqr-sqrt22.9%

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

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

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

        \[\leadsto \color{blue}{\frac{x + y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \frac{\mathsf{fma}\left(y, 2, x\right)}{\mathsf{hypot}\left(x, y \cdot 2\right)}} \]
      2. associate-*r/99.9%

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

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

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

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

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

Alternative 4: 81.2% accurate, 0.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \cdot x\_m \leq 0:\\ \;\;\;\;-1\\ \mathbf{elif}\;x\_m \cdot x\_m \leq 5 \cdot 10^{+216}:\\ \;\;\;\;\frac{\left(x\_m + y\_m \cdot 2\right) \cdot \left(x\_m - y\_m \cdot 2\right)}{x\_m \cdot x\_m + y\_m \cdot \left(y\_m \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
y_m = (fabs.f64 y)
(FPCore (x_m y_m)
 :precision binary64
 (if (<= (* x_m x_m) 0.0)
   -1.0
   (if (<= (* x_m x_m) 5e+216)
     (/
      (* (+ x_m (* y_m 2.0)) (- x_m (* y_m 2.0)))
      (+ (* x_m x_m) (* y_m (* y_m 4.0))))
     1.0)))
x_m = fabs(x);
y_m = fabs(y);
double code(double x_m, double y_m) {
	double tmp;
	if ((x_m * x_m) <= 0.0) {
		tmp = -1.0;
	} else if ((x_m * x_m) <= 5e+216) {
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = abs(x)
y_m = abs(y)
real(8) function code(x_m, y_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    real(8) :: tmp
    if ((x_m * x_m) <= 0.0d0) then
        tmp = -1.0d0
    else if ((x_m * x_m) <= 5d+216) then
        tmp = ((x_m + (y_m * 2.0d0)) * (x_m - (y_m * 2.0d0))) / ((x_m * x_m) + (y_m * (y_m * 4.0d0)))
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
x_m = Math.abs(x);
y_m = Math.abs(y);
public static double code(double x_m, double y_m) {
	double tmp;
	if ((x_m * x_m) <= 0.0) {
		tmp = -1.0;
	} else if ((x_m * x_m) <= 5e+216) {
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = math.fabs(x)
y_m = math.fabs(y)
def code(x_m, y_m):
	tmp = 0
	if (x_m * x_m) <= 0.0:
		tmp = -1.0
	elif (x_m * x_m) <= 5e+216:
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)))
	else:
		tmp = 1.0
	return tmp
x_m = abs(x)
y_m = abs(y)
function code(x_m, y_m)
	tmp = 0.0
	if (Float64(x_m * x_m) <= 0.0)
		tmp = -1.0;
	elseif (Float64(x_m * x_m) <= 5e+216)
		tmp = Float64(Float64(Float64(x_m + Float64(y_m * 2.0)) * Float64(x_m - Float64(y_m * 2.0))) / Float64(Float64(x_m * x_m) + Float64(y_m * Float64(y_m * 4.0))));
	else
		tmp = 1.0;
	end
	return tmp
end
x_m = abs(x);
y_m = abs(y);
function tmp_2 = code(x_m, y_m)
	tmp = 0.0;
	if ((x_m * x_m) <= 0.0)
		tmp = -1.0;
	elseif ((x_m * x_m) <= 5e+216)
		tmp = ((x_m + (y_m * 2.0)) * (x_m - (y_m * 2.0))) / ((x_m * x_m) + (y_m * (y_m * 4.0)));
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
y_m = N[Abs[y], $MachinePrecision]
code[x$95$m_, y$95$m_] := If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 0.0], -1.0, If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 5e+216], N[(N[(N[(x$95$m + N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision] * N[(x$95$m - N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(y$95$m * N[(y$95$m * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \cdot x\_m \leq 0:\\
\;\;\;\;-1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x x) < 0.0

    1. Initial program 53.4%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 91.5%

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

    if 0.0 < (*.f64 x x) < 4.9999999999999998e216

    1. Initial program 81.7%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt81.7%

        \[\leadsto \frac{x \cdot x - \color{blue}{\sqrt{\left(y \cdot 4\right) \cdot y} \cdot \sqrt{\left(y \cdot 4\right) \cdot y}}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      2. difference-of-squares81.8%

        \[\leadsto \frac{\color{blue}{\left(x + \sqrt{\left(y \cdot 4\right) \cdot y}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      3. *-commutative81.8%

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

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

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

        \[\leadsto \frac{\left(x + \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{4}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      7. add-sqr-sqrt67.2%

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

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

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

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

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

        \[\leadsto \frac{\left(x + y \cdot 2\right) \cdot \left(x - \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      13. add-sqr-sqrt81.8%

        \[\leadsto \frac{\left(x + y \cdot 2\right) \cdot \left(x - \color{blue}{y} \cdot \sqrt{4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      14. metadata-eval81.8%

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

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

    if 4.9999999999999998e216 < (*.f64 x x)

    1. Initial program 20.5%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 84.1%

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

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

Alternative 5: 81.2% accurate, 0.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ y_m = \left|y\right| \\ \begin{array}{l} t_0 := y\_m \cdot \left(y\_m \cdot 4\right)\\ \mathbf{if}\;x\_m \cdot x\_m \leq 0:\\ \;\;\;\;-1\\ \mathbf{elif}\;x\_m \cdot x\_m \leq 5.8 \cdot 10^{+216}:\\ \;\;\;\;\frac{x\_m \cdot x\_m - t\_0}{x\_m \cdot x\_m + t\_0}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
y_m = (fabs.f64 y)
(FPCore (x_m y_m)
 :precision binary64
 (let* ((t_0 (* y_m (* y_m 4.0))))
   (if (<= (* x_m x_m) 0.0)
     -1.0
     (if (<= (* x_m x_m) 5.8e+216)
       (/ (- (* x_m x_m) t_0) (+ (* x_m x_m) t_0))
       1.0))))
x_m = fabs(x);
y_m = fabs(y);
double code(double x_m, double y_m) {
	double t_0 = y_m * (y_m * 4.0);
	double tmp;
	if ((x_m * x_m) <= 0.0) {
		tmp = -1.0;
	} else if ((x_m * x_m) <= 5.8e+216) {
		tmp = ((x_m * x_m) - t_0) / ((x_m * x_m) + t_0);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = abs(x)
y_m = abs(y)
real(8) function code(x_m, y_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = y_m * (y_m * 4.0d0)
    if ((x_m * x_m) <= 0.0d0) then
        tmp = -1.0d0
    else if ((x_m * x_m) <= 5.8d+216) then
        tmp = ((x_m * x_m) - t_0) / ((x_m * x_m) + t_0)
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
x_m = Math.abs(x);
y_m = Math.abs(y);
public static double code(double x_m, double y_m) {
	double t_0 = y_m * (y_m * 4.0);
	double tmp;
	if ((x_m * x_m) <= 0.0) {
		tmp = -1.0;
	} else if ((x_m * x_m) <= 5.8e+216) {
		tmp = ((x_m * x_m) - t_0) / ((x_m * x_m) + t_0);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = math.fabs(x)
y_m = math.fabs(y)
def code(x_m, y_m):
	t_0 = y_m * (y_m * 4.0)
	tmp = 0
	if (x_m * x_m) <= 0.0:
		tmp = -1.0
	elif (x_m * x_m) <= 5.8e+216:
		tmp = ((x_m * x_m) - t_0) / ((x_m * x_m) + t_0)
	else:
		tmp = 1.0
	return tmp
x_m = abs(x)
y_m = abs(y)
function code(x_m, y_m)
	t_0 = Float64(y_m * Float64(y_m * 4.0))
	tmp = 0.0
	if (Float64(x_m * x_m) <= 0.0)
		tmp = -1.0;
	elseif (Float64(x_m * x_m) <= 5.8e+216)
		tmp = Float64(Float64(Float64(x_m * x_m) - t_0) / Float64(Float64(x_m * x_m) + t_0));
	else
		tmp = 1.0;
	end
	return tmp
end
x_m = abs(x);
y_m = abs(y);
function tmp_2 = code(x_m, y_m)
	t_0 = y_m * (y_m * 4.0);
	tmp = 0.0;
	if ((x_m * x_m) <= 0.0)
		tmp = -1.0;
	elseif ((x_m * x_m) <= 5.8e+216)
		tmp = ((x_m * x_m) - t_0) / ((x_m * x_m) + t_0);
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
y_m = N[Abs[y], $MachinePrecision]
code[x$95$m_, y$95$m_] := Block[{t$95$0 = N[(y$95$m * N[(y$95$m * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 0.0], -1.0, If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 5.8e+216], N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x$95$m * x$95$m), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], 1.0]]]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|

\\
\begin{array}{l}
t_0 := y\_m \cdot \left(y\_m \cdot 4\right)\\
\mathbf{if}\;x\_m \cdot x\_m \leq 0:\\
\;\;\;\;-1\\

\mathbf{elif}\;x\_m \cdot x\_m \leq 5.8 \cdot 10^{+216}:\\
\;\;\;\;\frac{x\_m \cdot x\_m - t\_0}{x\_m \cdot x\_m + t\_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x x) < 0.0

    1. Initial program 53.4%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 91.5%

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

    if 0.0 < (*.f64 x x) < 5.8000000000000002e216

    1. Initial program 81.7%

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

    if 5.8000000000000002e216 < (*.f64 x x)

    1. Initial program 20.5%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 84.1%

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

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

Alternative 6: 72.8% accurate, 1.2× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 4.5 \cdot 10^{-156}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x\_m \leq 7 \cdot 10^{-145}:\\ \;\;\;\;1\\ \mathbf{elif}\;x\_m \leq 3.4 \cdot 10^{-76}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
y_m = (fabs.f64 y)
(FPCore (x_m y_m)
 :precision binary64
 (if (<= x_m 4.5e-156)
   -1.0
   (if (<= x_m 7e-145) 1.0 (if (<= x_m 3.4e-76) -1.0 1.0))))
x_m = fabs(x);
y_m = fabs(y);
double code(double x_m, double y_m) {
	double tmp;
	if (x_m <= 4.5e-156) {
		tmp = -1.0;
	} else if (x_m <= 7e-145) {
		tmp = 1.0;
	} else if (x_m <= 3.4e-76) {
		tmp = -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = abs(x)
y_m = abs(y)
real(8) function code(x_m, y_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    real(8) :: tmp
    if (x_m <= 4.5d-156) then
        tmp = -1.0d0
    else if (x_m <= 7d-145) then
        tmp = 1.0d0
    else if (x_m <= 3.4d-76) then
        tmp = -1.0d0
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
x_m = Math.abs(x);
y_m = Math.abs(y);
public static double code(double x_m, double y_m) {
	double tmp;
	if (x_m <= 4.5e-156) {
		tmp = -1.0;
	} else if (x_m <= 7e-145) {
		tmp = 1.0;
	} else if (x_m <= 3.4e-76) {
		tmp = -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = math.fabs(x)
y_m = math.fabs(y)
def code(x_m, y_m):
	tmp = 0
	if x_m <= 4.5e-156:
		tmp = -1.0
	elif x_m <= 7e-145:
		tmp = 1.0
	elif x_m <= 3.4e-76:
		tmp = -1.0
	else:
		tmp = 1.0
	return tmp
x_m = abs(x)
y_m = abs(y)
function code(x_m, y_m)
	tmp = 0.0
	if (x_m <= 4.5e-156)
		tmp = -1.0;
	elseif (x_m <= 7e-145)
		tmp = 1.0;
	elseif (x_m <= 3.4e-76)
		tmp = -1.0;
	else
		tmp = 1.0;
	end
	return tmp
end
x_m = abs(x);
y_m = abs(y);
function tmp_2 = code(x_m, y_m)
	tmp = 0.0;
	if (x_m <= 4.5e-156)
		tmp = -1.0;
	elseif (x_m <= 7e-145)
		tmp = 1.0;
	elseif (x_m <= 3.4e-76)
		tmp = -1.0;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
y_m = N[Abs[y], $MachinePrecision]
code[x$95$m_, y$95$m_] := If[LessEqual[x$95$m, 4.5e-156], -1.0, If[LessEqual[x$95$m, 7e-145], 1.0, If[LessEqual[x$95$m, 3.4e-76], -1.0, 1.0]]]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 4.5 \cdot 10^{-156}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x\_m \leq 7 \cdot 10^{-145}:\\
\;\;\;\;1\\

\mathbf{elif}\;x\_m \leq 3.4 \cdot 10^{-76}:\\
\;\;\;\;-1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 4.49999999999999986e-156 or 6.99999999999999994e-145 < x < 3.3999999999999999e-76

    1. Initial program 57.4%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 55.8%

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

    if 4.49999999999999986e-156 < x < 6.99999999999999994e-145 or 3.3999999999999999e-76 < x

    1. Initial program 47.5%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 75.4%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 49.9% accurate, 19.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ y_m = \left|y\right| \\ -1 \end{array} \]
x_m = (fabs.f64 x)
y_m = (fabs.f64 y)
(FPCore (x_m y_m) :precision binary64 -1.0)
x_m = fabs(x);
y_m = fabs(y);
double code(double x_m, double y_m) {
	return -1.0;
}
x_m = abs(x)
y_m = abs(y)
real(8) function code(x_m, y_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    code = -1.0d0
end function
x_m = Math.abs(x);
y_m = Math.abs(y);
public static double code(double x_m, double y_m) {
	return -1.0;
}
x_m = math.fabs(x)
y_m = math.fabs(y)
def code(x_m, y_m):
	return -1.0
x_m = abs(x)
y_m = abs(y)
function code(x_m, y_m)
	return -1.0
end
x_m = abs(x);
y_m = abs(y);
function tmp = code(x_m, y_m)
	tmp = -1.0;
end
x_m = N[Abs[x], $MachinePrecision]
y_m = N[Abs[y], $MachinePrecision]
code[x$95$m_, y$95$m_] := -1.0
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|

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

    \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 45.7%

    \[\leadsto \color{blue}{-1} \]
  4. Add Preprocessing

Developer target: 51.7% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(y \cdot y\right) \cdot 4\\ t_1 := x \cdot x + t\_0\\ t_2 := \frac{t\_0}{t\_1}\\ t_3 := \left(y \cdot 4\right) \cdot y\\ \mathbf{if}\;\frac{x \cdot x - t\_3}{x \cdot x + t\_3} < 0.9743233849626781:\\ \;\;\;\;\frac{x \cdot x}{t\_1} - t\_2\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{t\_1}}\right)}^{2} - t\_2\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* (* y y) 4.0))
        (t_1 (+ (* x x) t_0))
        (t_2 (/ t_0 t_1))
        (t_3 (* (* y 4.0) y)))
   (if (< (/ (- (* x x) t_3) (+ (* x x) t_3)) 0.9743233849626781)
     (- (/ (* x x) t_1) t_2)
     (- (pow (/ x (sqrt t_1)) 2.0) t_2))))
double code(double x, double y) {
	double t_0 = (y * y) * 4.0;
	double t_1 = (x * x) + t_0;
	double t_2 = t_0 / t_1;
	double t_3 = (y * 4.0) * y;
	double tmp;
	if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781) {
		tmp = ((x * x) / t_1) - t_2;
	} else {
		tmp = pow((x / sqrt(t_1)), 2.0) - t_2;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = (y * y) * 4.0d0
    t_1 = (x * x) + t_0
    t_2 = t_0 / t_1
    t_3 = (y * 4.0d0) * y
    if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781d0) then
        tmp = ((x * x) / t_1) - t_2
    else
        tmp = ((x / sqrt(t_1)) ** 2.0d0) - t_2
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = (y * y) * 4.0;
	double t_1 = (x * x) + t_0;
	double t_2 = t_0 / t_1;
	double t_3 = (y * 4.0) * y;
	double tmp;
	if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781) {
		tmp = ((x * x) / t_1) - t_2;
	} else {
		tmp = Math.pow((x / Math.sqrt(t_1)), 2.0) - t_2;
	}
	return tmp;
}
def code(x, y):
	t_0 = (y * y) * 4.0
	t_1 = (x * x) + t_0
	t_2 = t_0 / t_1
	t_3 = (y * 4.0) * y
	tmp = 0
	if (((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781:
		tmp = ((x * x) / t_1) - t_2
	else:
		tmp = math.pow((x / math.sqrt(t_1)), 2.0) - t_2
	return tmp
function code(x, y)
	t_0 = Float64(Float64(y * y) * 4.0)
	t_1 = Float64(Float64(x * x) + t_0)
	t_2 = Float64(t_0 / t_1)
	t_3 = Float64(Float64(y * 4.0) * y)
	tmp = 0.0
	if (Float64(Float64(Float64(x * x) - t_3) / Float64(Float64(x * x) + t_3)) < 0.9743233849626781)
		tmp = Float64(Float64(Float64(x * x) / t_1) - t_2);
	else
		tmp = Float64((Float64(x / sqrt(t_1)) ^ 2.0) - t_2);
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = (y * y) * 4.0;
	t_1 = (x * x) + t_0;
	t_2 = t_0 / t_1;
	t_3 = (y * 4.0) * y;
	tmp = 0.0;
	if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781)
		tmp = ((x * x) / t_1) - t_2;
	else
		tmp = ((x / sqrt(t_1)) ^ 2.0) - t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * y), $MachinePrecision] * 4.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, If[Less[N[(N[(N[(x * x), $MachinePrecision] - t$95$3), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$3), $MachinePrecision]), $MachinePrecision], 0.9743233849626781], N[(N[(N[(x * x), $MachinePrecision] / t$95$1), $MachinePrecision] - t$95$2), $MachinePrecision], N[(N[Power[N[(x / N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] - t$95$2), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(y \cdot y\right) \cdot 4\\
t_1 := x \cdot x + t\_0\\
t_2 := \frac{t\_0}{t\_1}\\
t_3 := \left(y \cdot 4\right) \cdot y\\
\mathbf{if}\;\frac{x \cdot x - t\_3}{x \cdot x + t\_3} < 0.9743233849626781:\\
\;\;\;\;\frac{x \cdot x}{t\_1} - t\_2\\

\mathbf{else}:\\
\;\;\;\;{\left(\frac{x}{\sqrt{t\_1}}\right)}^{2} - t\_2\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024092 
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :alt
  (if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

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