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

Percentage Accurate: 50.9% → 94.1%
Time: 9.9s
Alternatives: 6
Speedup: 3.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 6 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.9% 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: 94.1% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 0:\\ \;\;\;\;\mathsf{fma}\left(-0.125, {\left(\frac{x}{y}\right)}^{4}, {\left(\frac{x}{y}\right)}^{2} \cdot 0.5\right) + -1\\ \mathbf{elif}\;x \cdot x \leq 1.6 \cdot 10^{+297}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{x}{\mathsf{fma}\left({y}^{2}, 4, {x}^{2}\right)}, \frac{-4}{4 + \frac{{x}^{2}}{{y}^{2}}}\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= (* x x) 0.0)
   (+ (fma -0.125 (pow (/ x y) 4.0) (* (pow (/ x y) 2.0) 0.5)) -1.0)
   (if (<= (* x x) 1.6e+297)
     (fma
      x
      (/ x (fma (pow y 2.0) 4.0 (pow x 2.0)))
      (/ -4.0 (+ 4.0 (/ (pow x 2.0) (pow y 2.0)))))
     (+ 1.0 (/ -8.0 (/ (/ x y) (/ y x)))))))
double code(double x, double y) {
	double tmp;
	if ((x * x) <= 0.0) {
		tmp = fma(-0.125, pow((x / y), 4.0), (pow((x / y), 2.0) * 0.5)) + -1.0;
	} else if ((x * x) <= 1.6e+297) {
		tmp = fma(x, (x / fma(pow(y, 2.0), 4.0, pow(x, 2.0))), (-4.0 / (4.0 + (pow(x, 2.0) / pow(y, 2.0)))));
	} else {
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (Float64(x * x) <= 0.0)
		tmp = Float64(fma(-0.125, (Float64(x / y) ^ 4.0), Float64((Float64(x / y) ^ 2.0) * 0.5)) + -1.0);
	elseif (Float64(x * x) <= 1.6e+297)
		tmp = fma(x, Float64(x / fma((y ^ 2.0), 4.0, (x ^ 2.0))), Float64(-4.0 / Float64(4.0 + Float64((x ^ 2.0) / (y ^ 2.0)))));
	else
		tmp = Float64(1.0 + Float64(-8.0 / Float64(Float64(x / y) / Float64(y / x))));
	end
	return tmp
end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 0.0], N[(N[(-0.125 * N[Power[N[(x / y), $MachinePrecision], 4.0], $MachinePrecision] + N[(N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1.6e+297], N[(x * N[(x / N[(N[Power[y, 2.0], $MachinePrecision] * 4.0 + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-4.0 / N[(4.0 + N[(N[Power[x, 2.0], $MachinePrecision] / N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 \cdot x \leq 0:\\
\;\;\;\;\mathsf{fma}\left(-0.125, {\left(\frac{x}{y}\right)}^{4}, {\left(\frac{x}{y}\right)}^{2} \cdot 0.5\right) + -1\\

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

\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 (*.f64 x x) < 0.0

    1. Initial program 60.0%

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

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

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

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

      \[\leadsto \color{blue}{\frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u33.9%

        \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    6. Applied egg-rr33.9%

      \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    7. Taylor expanded in x around 0 65.5%

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

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

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

        \[\leadsto \mathsf{fma}\left(-0.125, \frac{{x}^{\color{blue}{\left(2 \cdot 2\right)}}}{{y}^{4}}, 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1\right) \]
      4. pow-sqr65.5%

        \[\leadsto \mathsf{fma}\left(-0.125, \frac{\color{blue}{{x}^{2} \cdot {x}^{2}}}{{y}^{4}}, 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1\right) \]
      5. metadata-eval65.5%

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

        \[\leadsto \mathsf{fma}\left(-0.125, \frac{{x}^{2} \cdot {x}^{2}}{\color{blue}{{y}^{2} \cdot {y}^{2}}}, 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1\right) \]
      7. times-frac83.6%

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

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

        \[\leadsto \mathsf{fma}\left(-0.125, \frac{x \cdot x}{\color{blue}{y \cdot y}} \cdot \frac{{x}^{2}}{{y}^{2}}, 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1\right) \]
      10. times-frac83.6%

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

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

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

        \[\leadsto \mathsf{fma}\left(-0.125, {\left(\frac{x}{y}\right)}^{2} \cdot \frac{x \cdot x}{\color{blue}{y \cdot y}}, 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1\right) \]
      14. times-frac83.6%

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

        \[\leadsto \mathsf{fma}\left(-0.125, {\left(\frac{x}{y}\right)}^{2} \cdot \color{blue}{{\left(\frac{x}{y}\right)}^{2}}, 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1\right) \]
      16. pow-sqr83.6%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-0.125, {\left(\frac{x}{y}\right)}^{4}, \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)\right) \]
      21. times-frac96.0%

        \[\leadsto \mathsf{fma}\left(-0.125, {\left(\frac{x}{y}\right)}^{4}, \mathsf{fma}\left(0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)\right) \]
      22. unpow296.0%

        \[\leadsto \mathsf{fma}\left(-0.125, {\left(\frac{x}{y}\right)}^{4}, \mathsf{fma}\left(0.5, \color{blue}{{\left(\frac{x}{y}\right)}^{2}}, -1\right)\right) \]
      23. metadata-eval96.0%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.125, {\left(\frac{x}{y}\right)}^{4}, \mathsf{fma}\left(0.5, {\left(\frac{x}{y}\right)}^{2}, -1\right)\right)} \]
    10. Step-by-step derivation
      1. fma-udef96.0%

        \[\leadsto \color{blue}{-0.125 \cdot {\left(\frac{x}{y}\right)}^{4} + \mathsf{fma}\left(0.5, {\left(\frac{x}{y}\right)}^{2}, -1\right)} \]
      2. fma-udef96.0%

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(-0.125, {\left(\frac{x}{y}\right)}^{4}, 0.5 \cdot {\left(\frac{x}{y}\right)}^{2}\right)} + -1 \]
      5. *-commutative96.0%

        \[\leadsto \mathsf{fma}\left(-0.125, {\left(\frac{x}{y}\right)}^{4}, \color{blue}{{\left(\frac{x}{y}\right)}^{2} \cdot 0.5}\right) + -1 \]
    11. Applied egg-rr96.0%

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

    if 0.0 < (*.f64 x x) < 1.59999999999999997e297

    1. Initial program 75.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. div-sub75.7%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{{x}^{2}}{\mathsf{fma}\left(4, {y}^{2}, \color{blue}{{x}^{2}}\right)} + \left(-\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right) \]
      10. *-un-lft-identity75.7%

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

        \[\leadsto \frac{{x}^{2}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)} + \left(-\frac{\color{blue}{\left(4 \cdot y\right)} \cdot y}{1 \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}\right) \]
      12. associate-*l*75.7%

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

        \[\leadsto \frac{{x}^{2}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)} + \left(-\frac{4 \cdot \color{blue}{{y}^{2}}}{1 \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}\right) \]
      14. *-un-lft-identity75.7%

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

        \[\leadsto \frac{{x}^{2}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)} + \left(-\frac{4 \cdot {y}^{2}}{\color{blue}{\left(y \cdot 4\right) \cdot y + x \cdot x}}\right) \]
      16. *-commutative75.7%

        \[\leadsto \frac{{x}^{2}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)} + \left(-\frac{4 \cdot {y}^{2}}{\color{blue}{\left(4 \cdot y\right)} \cdot y + x \cdot x}\right) \]
      17. associate-*l*75.7%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(x, \frac{x}{\color{blue}{\mathsf{fma}\left({y}^{2}, 4, {x}^{2}\right)}}, -\frac{4 \cdot {y}^{2}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right) \]
      7. associate-/l*75.4%

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

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

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

        \[\leadsto \mathsf{fma}\left(x, \frac{x}{\mathsf{fma}\left({y}^{2}, 4, {x}^{2}\right)}, \frac{-4}{\frac{\color{blue}{4 \cdot {y}^{2} + {x}^{2}}}{{y}^{2}}}\right) \]
      11. *-commutative75.4%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{x}{\mathsf{fma}\left({y}^{2}, 4, {x}^{2}\right)}, \frac{-4}{\frac{\mathsf{fma}\left({y}^{2}, 4, {x}^{2}\right)}{{y}^{2}}}\right)} \]
    7. Taylor expanded in y around 0 99.5%

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

    if 1.59999999999999997e297 < (*.f64 x x)

    1. Initial program 4.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-cube-cbrt4.5%

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

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

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

      \[\leadsto \color{blue}{\frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u4.5%

        \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    6. Applied egg-rr4.5%

      \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    7. Taylor expanded in y around 0 78.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 81.8% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{\frac{x}{y}}{\frac{y}{x}}\\ \mathbf{if}\;x \cdot x \leq 10^{-209}:\\ \;\;\;\;\mathsf{fma}\left(0.5, t_1, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 10^{+284}:\\ \;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-8}{t_1}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* y (* y 4.0))) (t_1 (/ (/ x y) (/ y x))))
   (if (<= (* x x) 1e-209)
     (fma 0.5 t_1 -1.0)
     (if (<= (* x x) 1e+284)
       (/ (- (* x x) t_0) (+ (* x x) t_0))
       (+ 1.0 (/ -8.0 t_1))))))
double code(double x, double y) {
	double t_0 = y * (y * 4.0);
	double t_1 = (x / y) / (y / x);
	double tmp;
	if ((x * x) <= 1e-209) {
		tmp = fma(0.5, t_1, -1.0);
	} else if ((x * x) <= 1e+284) {
		tmp = ((x * x) - t_0) / ((x * x) + t_0);
	} else {
		tmp = 1.0 + (-8.0 / t_1);
	}
	return tmp;
}
function code(x, y)
	t_0 = Float64(y * Float64(y * 4.0))
	t_1 = Float64(Float64(x / y) / Float64(y / x))
	tmp = 0.0
	if (Float64(x * x) <= 1e-209)
		tmp = fma(0.5, t_1, -1.0);
	elseif (Float64(x * x) <= 1e+284)
		tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0));
	else
		tmp = Float64(1.0 + Float64(-8.0 / t_1));
	end
	return tmp
end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 1e-209], N[(0.5 * t$95$1 + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1e+284], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-8.0 / t$95$1), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := \frac{\frac{x}{y}}{\frac{y}{x}}\\
\mathbf{if}\;x \cdot x \leq 10^{-209}:\\
\;\;\;\;\mathsf{fma}\left(0.5, t_1, -1\right)\\

\mathbf{elif}\;x \cdot x \leq 10^{+284}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\

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


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

    1. Initial program 62.2%

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

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

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

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

      \[\leadsto \color{blue}{\frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u37.3%

        \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    6. Applied egg-rr37.3%

      \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    7. Taylor expanded in x around 0 84.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-209 < (*.f64 x x) < 1.00000000000000008e284

    1. Initial program 77.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 1.00000000000000008e284 < (*.f64 x x)

    1. Initial program 8.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-cube-cbrt8.4%

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

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

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

      \[\leadsto \color{blue}{\frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u8.4%

        \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    6. Applied egg-rr8.4%

      \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    7. Taylor expanded in y around 0 76.9%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 10^{-209}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{\frac{x}{y}}{\frac{y}{x}}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 10^{+284}:\\ \;\;\;\;\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} \]
  5. Add Preprocessing

Alternative 3: 66.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;x \leq 7.2 \cdot 10^{-105}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{+142}:\\ \;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\ \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))))
   (if (<= x 7.2e-105)
     -1.0
     (if (<= x 1.1e+142)
       (/ (- (* x x) t_0) (+ (* x x) t_0))
       (+ 1.0 (/ -8.0 (/ (/ x y) (/ y x))))))))
double code(double x, double y) {
	double t_0 = y * (y * 4.0);
	double tmp;
	if (x <= 7.2e-105) {
		tmp = -1.0;
	} else if (x <= 1.1e+142) {
		tmp = ((x * x) - t_0) / ((x * x) + t_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) :: t_0
    real(8) :: tmp
    t_0 = y * (y * 4.0d0)
    if (x <= 7.2d-105) then
        tmp = -1.0d0
    else if (x <= 1.1d+142) then
        tmp = ((x * x) - t_0) / ((x * x) + t_0)
    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 tmp;
	if (x <= 7.2e-105) {
		tmp = -1.0;
	} else if (x <= 1.1e+142) {
		tmp = ((x * x) - t_0) / ((x * x) + t_0);
	} else {
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
	}
	return tmp;
}
def code(x, y):
	t_0 = y * (y * 4.0)
	tmp = 0
	if x <= 7.2e-105:
		tmp = -1.0
	elif x <= 1.1e+142:
		tmp = ((x * x) - t_0) / ((x * x) + t_0)
	else:
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)))
	return tmp
function code(x, y)
	t_0 = Float64(y * Float64(y * 4.0))
	tmp = 0.0
	if (x <= 7.2e-105)
		tmp = -1.0;
	elseif (x <= 1.1e+142)
		tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_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)
	t_0 = y * (y * 4.0);
	tmp = 0.0;
	if (x <= 7.2e-105)
		tmp = -1.0;
	elseif (x <= 1.1e+142)
		tmp = ((x * x) - t_0) / ((x * x) + t_0);
	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]}, If[LessEqual[x, 7.2e-105], -1.0, If[LessEqual[x, 1.1e+142], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $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)\\
\mathbf{if}\;x \leq 7.2 \cdot 10^{-105}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \leq 1.1 \cdot 10^{+142}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\

\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 < 7.19999999999999929e-105

    1. Initial program 60.2%

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

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

    if 7.19999999999999929e-105 < x < 1.09999999999999993e142

    1. Initial program 70.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

    if 1.09999999999999993e142 < x

    1. Initial program 5.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-cube-cbrt5.4%

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

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

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

      \[\leadsto \color{blue}{\frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u5.4%

        \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    6. Applied egg-rr5.4%

      \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    7. Taylor expanded in y around 0 75.1%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 7.2 \cdot 10^{-105}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{+142}:\\ \;\;\;\;\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} \]
  5. Add Preprocessing

Alternative 4: 64.1% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 2.8 \cdot 10^{+19}:\\ \;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y 2.8e+19) (+ 1.0 (/ -8.0 (/ (/ x y) (/ y x)))) -1.0))
double code(double x, double y) {
	double tmp;
	if (y <= 2.8e+19) {
		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 <= 2.8d+19) 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 <= 2.8e+19) {
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
	} else {
		tmp = -1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 2.8e+19:
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)))
	else:
		tmp = -1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 2.8e+19)
		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 <= 2.8e+19)
		tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 2.8e+19], 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 2.8 \cdot 10^{+19}:\\
\;\;\;\;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 < 2.8e19

    1. Initial program 56.8%

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

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

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

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

      \[\leadsto \color{blue}{\frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u43.3%

        \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    6. Applied egg-rr43.3%

      \[\leadsto \frac{{\left(\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{2}}{1} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt[3]{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}}{\mathsf{fma}\left(4, {y}^{2}, {x}^{2}\right)}\right)\right)} \]
    7. Taylor expanded in y around 0 53.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.8e19 < y

    1. Initial program 44.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. Taylor expanded in x around 0 89.5%

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

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

Alternative 5: 63.0% accurate, 3.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 500000:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
(FPCore (x y) :precision binary64 (if (<= y 500000.0) 1.0 -1.0))
double code(double x, double y) {
	double tmp;
	if (y <= 500000.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 <= 500000.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 <= 500000.0) {
		tmp = 1.0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 500000.0:
		tmp = 1.0
	else:
		tmp = -1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 500000.0)
		tmp = 1.0;
	else
		tmp = -1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 500000.0)
		tmp = 1.0;
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 500000.0], 1.0, -1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 500000:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 5e5

    1. Initial program 56.9%

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

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

    if 5e5 < y

    1. Initial program 45.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 500000:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 50.5% 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 54.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. Taylor expanded in x around 0 52.0%

    \[\leadsto \color{blue}{-1} \]
  4. Final simplification52.0%

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

Developer target: 51.4% 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 2024020 
(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))))