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

Percentage Accurate: 50.6% → 99.9%
Time: 5.7s
Alternatives: 7
Speedup: 2.6×

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: 50.6% 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} \\ \begin{array}{l} t_0 := \mathsf{hypot}\left(x, 2 \cdot y\right)\\ \frac{\mathsf{fma}\left(2, y, x\right)}{t_0} \cdot \frac{x + y \cdot -2}{t_0} \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (hypot x (* 2.0 y))))
   (* (/ (fma 2.0 y x) t_0) (/ (+ x (* y -2.0)) t_0))))
double code(double x, double y) {
	double t_0 = hypot(x, (2.0 * y));
	return (fma(2.0, y, x) / t_0) * ((x + (y * -2.0)) / t_0);
}
function code(x, y)
	t_0 = hypot(x, Float64(2.0 * y))
	return Float64(Float64(fma(2.0, y, x) / t_0) * Float64(Float64(x + Float64(y * -2.0)) / t_0))
end
code[x_, y_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(2.0 * y), $MachinePrecision] ^ 2], $MachinePrecision]}, N[(N[(N[(2.0 * y + x), $MachinePrecision] / t$95$0), $MachinePrecision] * N[(N[(x + N[(y * -2.0), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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

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

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

      \[\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*53.1%

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

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

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

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

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

      \[\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*37.9%

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

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

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

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

      \[\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} \]
  3. Applied egg-rr53.1%

    \[\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} \]
  4. Step-by-step derivation
    1. add-sqr-sqrt53.1%

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

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

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

      \[\leadsto \frac{\color{blue}{2 \cdot y} + 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}} \]
    5. fma-def54.2%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(2, y, 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}} \]
    6. add-sqr-sqrt54.2%

      \[\leadsto \frac{\mathsf{fma}\left(2, y, 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}} \]
    7. hypot-def54.2%

      \[\leadsto \frac{\mathsf{fma}\left(2, y, 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}} \]
    8. sqrt-prod21.7%

      \[\leadsto \frac{\mathsf{fma}\left(2, y, 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}} \]
    9. *-commutative21.7%

      \[\leadsto \frac{\mathsf{fma}\left(2, y, 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}} \]
    10. sqrt-prod21.7%

      \[\leadsto \frac{\mathsf{fma}\left(2, y, 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}} \]
    11. metadata-eval21.7%

      \[\leadsto \frac{\mathsf{fma}\left(2, y, 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}} \]
    12. associate-*r*21.7%

      \[\leadsto \frac{\mathsf{fma}\left(2, y, 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}} \]
    13. add-sqr-sqrt54.2%

      \[\leadsto \frac{\mathsf{fma}\left(2, y, 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}} \]
  5. Applied egg-rr100.0%

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

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

Alternative 2: 65.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\ t_2 := x \cdot x + t_0\\ \mathbf{if}\;x \leq 7 \cdot 10^{-161}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{-50}:\\ \;\;\;\;\frac{x \cdot x - t_0}{t_2}\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+93}:\\ \;\;\;\;\frac{\left(x + 2 \cdot y\right) \cdot \left(x - 2 \cdot y\right)}{t_2}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* y (* y 4.0)))
        (t_1 (+ (* 0.5 (* (/ x y) (/ x y))) -1.0))
        (t_2 (+ (* x x) t_0)))
   (if (<= x 7e-161)
     t_1
     (if (<= x 1.22e-50)
       (/ (- (* x x) t_0) t_2)
       (if (<= x 6.5e-14)
         t_1
         (if (<= x 5e+93)
           (/ (* (+ x (* 2.0 y)) (- x (* 2.0 y))) t_2)
           (+ 1.0 (/ -8.0 (/ (/ x y) (/ y x))))))))))
double code(double x, double y) {
	double t_0 = y * (y * 4.0);
	double t_1 = (0.5 * ((x / y) * (x / y))) + -1.0;
	double t_2 = (x * x) + t_0;
	double tmp;
	if (x <= 7e-161) {
		tmp = t_1;
	} else if (x <= 1.22e-50) {
		tmp = ((x * x) - t_0) / t_2;
	} else if (x <= 6.5e-14) {
		tmp = t_1;
	} else if (x <= 5e+93) {
		tmp = ((x + (2.0 * y)) * (x - (2.0 * y))) / t_2;
	} else {
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
	}
	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) :: tmp
    t_0 = y * (y * 4.0d0)
    t_1 = (0.5d0 * ((x / y) * (x / y))) + (-1.0d0)
    t_2 = (x * x) + t_0
    if (x <= 7d-161) then
        tmp = t_1
    else if (x <= 1.22d-50) then
        tmp = ((x * x) - t_0) / t_2
    else if (x <= 6.5d-14) then
        tmp = t_1
    else if (x <= 5d+93) then
        tmp = ((x + (2.0d0 * y)) * (x - (2.0d0 * y))) / t_2
    else
        tmp = 1.0d0 + ((-8.0d0) / ((x / y) / (y / x)))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = y * (y * 4.0);
	double t_1 = (0.5 * ((x / y) * (x / y))) + -1.0;
	double t_2 = (x * x) + t_0;
	double tmp;
	if (x <= 7e-161) {
		tmp = t_1;
	} else if (x <= 1.22e-50) {
		tmp = ((x * x) - t_0) / t_2;
	} else if (x <= 6.5e-14) {
		tmp = t_1;
	} else if (x <= 5e+93) {
		tmp = ((x + (2.0 * y)) * (x - (2.0 * y))) / t_2;
	} else {
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
	}
	return tmp;
}
def code(x, y):
	t_0 = y * (y * 4.0)
	t_1 = (0.5 * ((x / y) * (x / y))) + -1.0
	t_2 = (x * x) + t_0
	tmp = 0
	if x <= 7e-161:
		tmp = t_1
	elif x <= 1.22e-50:
		tmp = ((x * x) - t_0) / t_2
	elif x <= 6.5e-14:
		tmp = t_1
	elif x <= 5e+93:
		tmp = ((x + (2.0 * y)) * (x - (2.0 * y))) / t_2
	else:
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)))
	return tmp
function code(x, y)
	t_0 = Float64(y * Float64(y * 4.0))
	t_1 = Float64(Float64(0.5 * Float64(Float64(x / y) * Float64(x / y))) + -1.0)
	t_2 = Float64(Float64(x * x) + t_0)
	tmp = 0.0
	if (x <= 7e-161)
		tmp = t_1;
	elseif (x <= 1.22e-50)
		tmp = Float64(Float64(Float64(x * x) - t_0) / t_2);
	elseif (x <= 6.5e-14)
		tmp = t_1;
	elseif (x <= 5e+93)
		tmp = Float64(Float64(Float64(x + Float64(2.0 * y)) * Float64(x - Float64(2.0 * y))) / t_2);
	else
		tmp = Float64(1.0 + Float64(-8.0 / Float64(Float64(x / y) / Float64(y / x))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = y * (y * 4.0);
	t_1 = (0.5 * ((x / y) * (x / y))) + -1.0;
	t_2 = (x * x) + t_0;
	tmp = 0.0;
	if (x <= 7e-161)
		tmp = t_1;
	elseif (x <= 1.22e-50)
		tmp = ((x * x) - t_0) / t_2;
	elseif (x <= 6.5e-14)
		tmp = t_1;
	elseif (x <= 5e+93)
		tmp = ((x + (2.0 * y)) * (x - (2.0 * y))) / t_2;
	else
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]}, If[LessEqual[x, 7e-161], t$95$1, If[LessEqual[x, 1.22e-50], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / t$95$2), $MachinePrecision], If[LessEqual[x, 6.5e-14], t$95$1, If[LessEqual[x, 5e+93], N[(N[(N[(x + N[(2.0 * y), $MachinePrecision]), $MachinePrecision] * N[(x - N[(2.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision], N[(1.0 + N[(-8.0 / N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\
t_2 := x \cdot x + t_0\\
\mathbf{if}\;x \leq 7 \cdot 10^{-161}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 1.22 \cdot 10^{-50}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_2}\\

\mathbf{elif}\;x \leq 6.5 \cdot 10^{-14}:\\
\;\;\;\;t_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < 7.00000000000000039e-161 or 1.22000000000000007e-50 < x < 6.5000000000000001e-14

    1. Initial program 52.0%

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x}}{{y}^{2}} - 1 \]
      2. unpow250.9%

        \[\leadsto 0.5 \cdot \frac{x \cdot x}{\color{blue}{y \cdot y}} - 1 \]
      3. times-frac61.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x}{y} \cdot \frac{x}{y}\right)} - 1 \]
    4. Applied egg-rr61.7%

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

    if 7.00000000000000039e-161 < x < 1.22000000000000007e-50

    1. Initial program 86.2%

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

    if 6.5000000000000001e-14 < x < 5.0000000000000001e93

    1. Initial program 92.5%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt92.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-squares92.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. *-commutative92.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*92.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-prod92.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-unprod48.1%

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

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

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

        \[\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*70.7%

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

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

        \[\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-sqrt92.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-eval92.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} \]
    3. Applied egg-rr92.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} \]

    if 5.0000000000000001e93 < x

    1. Initial program 18.5%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt18.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-squares18.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. *-commutative18.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*18.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-prod18.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-unprod0.0%

        \[\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-sqrt18.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-eval18.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. *-commutative18.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*18.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-prod18.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-unprod0.0%

        \[\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-sqrt18.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-eval18.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} \]
    3. Applied egg-rr18.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} \]
    4. Taylor expanded in y around 0 63.3%

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

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

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

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

        \[\leadsto 1 + \frac{-8}{\frac{x \cdot x}{\color{blue}{y \cdot y}}} \]
      5. times-frac72.1%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 7 \cdot 10^{-161}:\\ \;\;\;\;0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{-50}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-14}:\\ \;\;\;\;0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+93}:\\ \;\;\;\;\frac{\left(x + 2 \cdot y\right) \cdot \left(x - 2 \cdot y\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\ \end{array} \]

Alternative 3: 65.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ t_2 := 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\ \mathbf{if}\;x \leq 1.5 \cdot 10^{-161}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.28 \cdot 10^{-14}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+93}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* y (* y 4.0)))
        (t_1 (/ (- (* x x) t_0) (+ (* x x) t_0)))
        (t_2 (+ (* 0.5 (* (/ x y) (/ x y))) -1.0)))
   (if (<= x 1.5e-161)
     t_2
     (if (<= x 3.7e-51)
       t_1
       (if (<= x 1.28e-14)
         t_2
         (if (<= x 4.5e+93) t_1 (+ 1.0 (/ -8.0 (/ (/ x y) (/ y x))))))))))
double code(double x, double y) {
	double t_0 = y * (y * 4.0);
	double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
	double t_2 = (0.5 * ((x / y) * (x / y))) + -1.0;
	double tmp;
	if (x <= 1.5e-161) {
		tmp = t_2;
	} else if (x <= 3.7e-51) {
		tmp = t_1;
	} else if (x <= 1.28e-14) {
		tmp = t_2;
	} else if (x <= 4.5e+93) {
		tmp = t_1;
	} else {
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
	}
	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) :: tmp
    t_0 = y * (y * 4.0d0)
    t_1 = ((x * x) - t_0) / ((x * x) + t_0)
    t_2 = (0.5d0 * ((x / y) * (x / y))) + (-1.0d0)
    if (x <= 1.5d-161) then
        tmp = t_2
    else if (x <= 3.7d-51) then
        tmp = t_1
    else if (x <= 1.28d-14) then
        tmp = t_2
    else if (x <= 4.5d+93) then
        tmp = t_1
    else
        tmp = 1.0d0 + ((-8.0d0) / ((x / y) / (y / x)))
    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) / ((x * x) + t_0);
	double t_2 = (0.5 * ((x / y) * (x / y))) + -1.0;
	double tmp;
	if (x <= 1.5e-161) {
		tmp = t_2;
	} else if (x <= 3.7e-51) {
		tmp = t_1;
	} else if (x <= 1.28e-14) {
		tmp = t_2;
	} else if (x <= 4.5e+93) {
		tmp = t_1;
	} else {
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
	}
	return tmp;
}
def code(x, y):
	t_0 = y * (y * 4.0)
	t_1 = ((x * x) - t_0) / ((x * x) + t_0)
	t_2 = (0.5 * ((x / y) * (x / y))) + -1.0
	tmp = 0
	if x <= 1.5e-161:
		tmp = t_2
	elif x <= 3.7e-51:
		tmp = t_1
	elif x <= 1.28e-14:
		tmp = t_2
	elif x <= 4.5e+93:
		tmp = t_1
	else:
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)))
	return tmp
function code(x, y)
	t_0 = Float64(y * Float64(y * 4.0))
	t_1 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0))
	t_2 = Float64(Float64(0.5 * Float64(Float64(x / y) * Float64(x / y))) + -1.0)
	tmp = 0.0
	if (x <= 1.5e-161)
		tmp = t_2;
	elseif (x <= 3.7e-51)
		tmp = t_1;
	elseif (x <= 1.28e-14)
		tmp = t_2;
	elseif (x <= 4.5e+93)
		tmp = t_1;
	else
		tmp = Float64(1.0 + Float64(-8.0 / Float64(Float64(x / y) / Float64(y / x))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = y * (y * 4.0);
	t_1 = ((x * x) - t_0) / ((x * x) + t_0);
	t_2 = (0.5 * ((x / y) * (x / y))) + -1.0;
	tmp = 0.0;
	if (x <= 1.5e-161)
		tmp = t_2;
	elseif (x <= 3.7e-51)
		tmp = t_1;
	elseif (x <= 1.28e-14)
		tmp = t_2;
	elseif (x <= 4.5e+93)
		tmp = t_1;
	else
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[x, 1.5e-161], t$95$2, If[LessEqual[x, 3.7e-51], t$95$1, If[LessEqual[x, 1.28e-14], t$95$2, If[LessEqual[x, 4.5e+93], t$95$1, N[(1.0 + N[(-8.0 / N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
t_2 := 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\
\mathbf{if}\;x \leq 1.5 \cdot 10^{-161}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;x \leq 3.7 \cdot 10^{-51}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 1.28 \cdot 10^{-14}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;x \leq 4.5 \cdot 10^{+93}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 1.49999999999999994e-161 or 3.69999999999999973e-51 < x < 1.28e-14

    1. Initial program 52.0%

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x}}{{y}^{2}} - 1 \]
      2. unpow250.9%

        \[\leadsto 0.5 \cdot \frac{x \cdot x}{\color{blue}{y \cdot y}} - 1 \]
      3. times-frac61.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x}{y} \cdot \frac{x}{y}\right)} - 1 \]
    4. Applied egg-rr61.7%

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

    if 1.49999999999999994e-161 < x < 3.69999999999999973e-51 or 1.28e-14 < x < 4.49999999999999991e93

    1. Initial program 89.3%

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

    if 4.49999999999999991e93 < x

    1. Initial program 18.5%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt18.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-squares18.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. *-commutative18.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*18.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-prod18.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-unprod0.0%

        \[\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-sqrt18.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-eval18.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. *-commutative18.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*18.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-prod18.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-unprod0.0%

        \[\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-sqrt18.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-eval18.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} \]
    3. Applied egg-rr18.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} \]
    4. Taylor expanded in y around 0 63.3%

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

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

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

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

        \[\leadsto 1 + \frac{-8}{\frac{x \cdot x}{\color{blue}{y \cdot y}}} \]
      5. times-frac72.1%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.5 \cdot 10^{-161}:\\ \;\;\;\;0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-51}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 1.28 \cdot 10^{-14}:\\ \;\;\;\;0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+93}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\ \end{array} \]

Alternative 4: 63.5% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.8 \cdot 10^{-73} \lor \neg \left(y \leq 1.55 \cdot 10^{-57}\right) \land y \leq 3600:\\
\;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 9.80000000000000057e-73 or 1.54999999999999988e-57 < y < 3600

    1. Initial program 55.4%

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

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

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

        \[\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*55.4%

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

        \[\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-unprod15.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-sqrt36.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-eval36.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. *-commutative36.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*36.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-prod36.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-unprod15.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-sqrt55.4%

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

        \[\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} \]
    3. Applied egg-rr55.4%

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

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

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

        \[\leadsto 1 + \color{blue}{\frac{-8}{\frac{{x}^{2}}{{y}^{2}}}} \]
      3. unpow251.4%

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

        \[\leadsto 1 + \frac{-8}{\frac{x \cdot x}{\color{blue}{y \cdot y}}} \]
      5. times-frac57.2%

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

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

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

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

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

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

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

    if 9.80000000000000057e-73 < y < 1.54999999999999988e-57 or 3600 < y

    1. Initial program 44.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9.8 \cdot 10^{-73} \lor \neg \left(y \leq 1.55 \cdot 10^{-57}\right) \land y \leq 3600:\\ \;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternative 5: 63.7% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 57.7%

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

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

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

        \[\leadsto 0.5 \cdot \frac{x \cdot x}{\color{blue}{y \cdot y}} - 1 \]
      3. times-frac63.1%

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

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

    if 3.69999999999999999e-12 < x

    1. Initial program 43.2%

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

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

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

        \[\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*43.2%

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

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

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

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

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

        \[\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*35.9%

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

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

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

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

        \[\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} \]
    3. Applied egg-rr43.2%

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

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

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

        \[\leadsto 1 + \color{blue}{\frac{-8}{\frac{{x}^{2}}{{y}^{2}}}} \]
      3. unpow263.9%

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

        \[\leadsto 1 + \frac{-8}{\frac{x \cdot x}{\color{blue}{y \cdot y}}} \]
      5. times-frac69.8%

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

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

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

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

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

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

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

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

Alternative 6: 62.5% accurate, 2.6× speedup?

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

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

\mathbf{elif}\;y \leq 1.25 \cdot 10^{-57}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 15000:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.99999999999999999e-73 or 1.25e-57 < y < 15000

    1. Initial program 55.4%

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

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

    if 1.99999999999999999e-73 < y < 1.25e-57 or 15000 < y

    1. Initial program 44.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 2 \cdot 10^{-73}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-57}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 15000:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternative 7: 50.1% accurate, 19.0× speedup?

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

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

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

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

    \[\leadsto -1 \]

Developer target: 51.1% 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 2023322 
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (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))))