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

Percentage Accurate: 50.2% → 78.9%
Time: 8.1s
Alternatives: 9
Speedup: 19.0×

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 9 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.2% 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: 78.9% accurate, 0.0× 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}\\ \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\ \;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(3 \cdot \log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right), -8, 1\right)\\ \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))))
   (if (<= (* x x) 5e-245)
     (fma 0.5 (* (/ x y) (/ x y)) -1.0)
     (if (<= (* x x) 2e-88)
       t_1
       (if (<= (* x x) 2e+90)
         (+ -1.0 (/ (/ (* x (/ x y)) y) 4.0))
         (if (<= (* x x) 4e+277)
           t_1
           (fma (* 3.0 (log (cbrt (+ 1.0 (pow (/ y x) 2.0))))) -8.0 1.0)))))))
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 tmp;
	if ((x * x) <= 5e-245) {
		tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
	} else if ((x * x) <= 2e-88) {
		tmp = t_1;
	} else if ((x * x) <= 2e+90) {
		tmp = -1.0 + (((x * (x / y)) / y) / 4.0);
	} else if ((x * x) <= 4e+277) {
		tmp = t_1;
	} else {
		tmp = fma((3.0 * log(cbrt((1.0 + pow((y / x), 2.0))))), -8.0, 1.0);
	}
	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))
	tmp = 0.0
	if (Float64(x * x) <= 5e-245)
		tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0);
	elseif (Float64(x * x) <= 2e-88)
		tmp = t_1;
	elseif (Float64(x * x) <= 2e+90)
		tmp = Float64(-1.0 + Float64(Float64(Float64(x * Float64(x / y)) / y) / 4.0));
	elseif (Float64(x * x) <= 4e+277)
		tmp = t_1;
	else
		tmp = fma(Float64(3.0 * log(cbrt(Float64(1.0 + (Float64(y / x) ^ 2.0))))), -8.0, 1.0);
	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[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-245], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e-88], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e+90], N[(-1.0 + N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+277], t$95$1, N[(N[(3.0 * N[Log[N[Power[N[(1.0 + N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $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}\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\

\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\
\;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\

\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3 \cdot \log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right), -8, 1\right)\\


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

    1. Initial program 48.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 75.5%

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

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

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

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

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

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

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

    if 4.9999999999999997e-245 < (*.f64 x x) < 1.99999999999999987e-88 or 1.99999999999999993e90 < (*.f64 x x) < 4.00000000000000001e277

    1. Initial program 83.0%

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

    if 1.99999999999999987e-88 < (*.f64 x x) < 1.99999999999999993e90

    1. Initial program 60.6%

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

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

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

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

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

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{y \cdot \left(y \cdot 4\right)}} \]
    5. Step-by-step derivation
      1. div-sub33.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}}{4} - 1 \]
      2. associate-*r/73.9%

        \[\leadsto \frac{\color{blue}{\frac{\frac{x}{y} \cdot x}{y}}}{4} - 1 \]
    8. Applied egg-rr73.9%

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

    if 4.00000000000000001e277 < (*.f64 x x)

    1. Initial program 8.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 82.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)} \]
    5. Step-by-step derivation
      1. add-log-exp88.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\log \left(e^{\frac{y}{x} \cdot \frac{y}{x}}\right)}, -8, 1\right) \]
      2. pow288.8%

        \[\leadsto \mathsf{fma}\left(\log \left(e^{\color{blue}{{\left(\frac{y}{x}\right)}^{2}}}\right), -8, 1\right) \]
    6. Applied egg-rr88.8%

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

      \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left(1 + \frac{{y}^{2}}{{x}^{2}}\right)}, -8, 1\right) \]
    8. Step-by-step derivation
      1. unpow282.0%

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left(1 + {\left(\frac{y}{x}\right)}^{2}\right)}, -8, 1\right) \]
    10. Step-by-step derivation
      1. add-cube-cbrt89.8%

        \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left(\left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}} \cdot \sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right) \cdot \sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right)}, -8, 1\right) \]
      2. log-prod89.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}} \cdot \sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right) + \log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right)}, -8, 1\right) \]
      3. pow289.8%

        \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left({\left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right)}^{2}\right)} + \log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right), -8, 1\right) \]
    11. Applied egg-rr89.8%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\log \left({\left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right)}^{2}\right) + \log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right)}, -8, 1\right) \]
    12. Step-by-step derivation
      1. log-pow89.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{2 \cdot \log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right)} + \log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right), -8, 1\right) \]
      2. distribute-lft1-in89.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right)}, -8, 1\right) \]
      3. metadata-eval89.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{3} \cdot \log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right), -8, 1\right) \]
    13. Simplified89.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\ \;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(3 \cdot \log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right), -8, 1\right)\\ \end{array} \]

Alternative 2: 78.9% accurate, 0.1× 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}\\ \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\ \;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log \left(1 + \frac{\frac{y}{x}}{\frac{x}{y}}\right), -8, 1\right)\\ \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))))
   (if (<= (* x x) 5e-245)
     (fma 0.5 (* (/ x y) (/ x y)) -1.0)
     (if (<= (* x x) 2e-88)
       t_1
       (if (<= (* x x) 2e+90)
         (+ -1.0 (/ (/ (* x (/ x y)) y) 4.0))
         (if (<= (* x x) 4e+277)
           t_1
           (fma (log (+ 1.0 (/ (/ y x) (/ x y)))) -8.0 1.0)))))))
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 tmp;
	if ((x * x) <= 5e-245) {
		tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
	} else if ((x * x) <= 2e-88) {
		tmp = t_1;
	} else if ((x * x) <= 2e+90) {
		tmp = -1.0 + (((x * (x / y)) / y) / 4.0);
	} else if ((x * x) <= 4e+277) {
		tmp = t_1;
	} else {
		tmp = fma(log((1.0 + ((y / x) / (x / y)))), -8.0, 1.0);
	}
	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))
	tmp = 0.0
	if (Float64(x * x) <= 5e-245)
		tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0);
	elseif (Float64(x * x) <= 2e-88)
		tmp = t_1;
	elseif (Float64(x * x) <= 2e+90)
		tmp = Float64(-1.0 + Float64(Float64(Float64(x * Float64(x / y)) / y) / 4.0));
	elseif (Float64(x * x) <= 4e+277)
		tmp = t_1;
	else
		tmp = fma(log(Float64(1.0 + Float64(Float64(y / x) / Float64(x / y)))), -8.0, 1.0);
	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[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-245], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e-88], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e+90], N[(-1.0 + N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+277], t$95$1, N[(N[Log[N[(1.0 + N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * -8.0 + 1.0), $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}\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\

\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\
\;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\

\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\
\;\;\;\;t_1\\

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


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

    1. Initial program 48.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 75.5%

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

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

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

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

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

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

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

    if 4.9999999999999997e-245 < (*.f64 x x) < 1.99999999999999987e-88 or 1.99999999999999993e90 < (*.f64 x x) < 4.00000000000000001e277

    1. Initial program 83.0%

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

    if 1.99999999999999987e-88 < (*.f64 x x) < 1.99999999999999993e90

    1. Initial program 60.6%

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

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

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

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

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

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{y \cdot \left(y \cdot 4\right)}} \]
    5. Step-by-step derivation
      1. div-sub33.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}}{4} - 1 \]
      2. associate-*r/73.9%

        \[\leadsto \frac{\color{blue}{\frac{\frac{x}{y} \cdot x}{y}}}{4} - 1 \]
    8. Applied egg-rr73.9%

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

    if 4.00000000000000001e277 < (*.f64 x x)

    1. Initial program 8.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 82.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)} \]
    5. Step-by-step derivation
      1. add-log-exp88.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\log \left(e^{\frac{y}{x} \cdot \frac{y}{x}}\right)}, -8, 1\right) \]
      2. pow288.8%

        \[\leadsto \mathsf{fma}\left(\log \left(e^{\color{blue}{{\left(\frac{y}{x}\right)}^{2}}}\right), -8, 1\right) \]
    6. Applied egg-rr88.8%

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

      \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left(1 + \frac{{y}^{2}}{{x}^{2}}\right)}, -8, 1\right) \]
    8. Step-by-step derivation
      1. unpow282.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\ \;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log \left(1 + \frac{\frac{y}{x}}{\frac{x}{y}}\right), -8, 1\right)\\ \end{array} \]

Alternative 3: 78.6% accurate, 0.2× 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}\\ \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\ \;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\ \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))))
   (if (<= (* x x) 5e-245)
     (fma 0.5 (* (/ x y) (/ x y)) -1.0)
     (if (<= (* x x) 2e-88)
       t_1
       (if (<= (* x x) 2e+90)
         (+ -1.0 (/ (/ (* x (/ x y)) y) 4.0))
         (if (<= (* x x) 4e+277) t_1 (fma (* (/ y x) (/ y x)) -8.0 1.0)))))))
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 tmp;
	if ((x * x) <= 5e-245) {
		tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
	} else if ((x * x) <= 2e-88) {
		tmp = t_1;
	} else if ((x * x) <= 2e+90) {
		tmp = -1.0 + (((x * (x / y)) / y) / 4.0);
	} else if ((x * x) <= 4e+277) {
		tmp = t_1;
	} else {
		tmp = fma(((y / x) * (y / x)), -8.0, 1.0);
	}
	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))
	tmp = 0.0
	if (Float64(x * x) <= 5e-245)
		tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0);
	elseif (Float64(x * x) <= 2e-88)
		tmp = t_1;
	elseif (Float64(x * x) <= 2e+90)
		tmp = Float64(-1.0 + Float64(Float64(Float64(x * Float64(x / y)) / y) / 4.0));
	elseif (Float64(x * x) <= 4e+277)
		tmp = t_1;
	else
		tmp = fma(Float64(Float64(y / x) * Float64(y / x)), -8.0, 1.0);
	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[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-245], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e-88], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e+90], N[(-1.0 + N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+277], t$95$1, N[(N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $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}\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\

\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\
\;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\

\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\
\;\;\;\;t_1\\

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


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

    1. Initial program 48.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 75.5%

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

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

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

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

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

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

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

    if 4.9999999999999997e-245 < (*.f64 x x) < 1.99999999999999987e-88 or 1.99999999999999993e90 < (*.f64 x x) < 4.00000000000000001e277

    1. Initial program 83.0%

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

    if 1.99999999999999987e-88 < (*.f64 x x) < 1.99999999999999993e90

    1. Initial program 60.6%

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

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

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

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

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

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{y \cdot \left(y \cdot 4\right)}} \]
    5. Step-by-step derivation
      1. div-sub33.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}}{4} - 1 \]
      2. associate-*r/73.9%

        \[\leadsto \frac{\color{blue}{\frac{\frac{x}{y} \cdot x}{y}}}{4} - 1 \]
    8. Applied egg-rr73.9%

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

    if 4.00000000000000001e277 < (*.f64 x x)

    1. Initial program 8.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 82.0%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\ \;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\ \end{array} \]

Alternative 4: 78.5% accurate, 0.2× 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}\\ \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\ \;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{\frac{y}{x}}{\frac{x}{y}} \cdot -4\\ \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))))
   (if (<= (* x x) 5e-245)
     (fma 0.5 (* (/ x y) (/ x y)) -1.0)
     (if (<= (* x x) 2e-88)
       t_1
       (if (<= (* x x) 2e+90)
         (+ -1.0 (/ (/ (* x (/ x y)) y) 4.0))
         (if (<= (* x x) 4e+277) t_1 (+ 1.0 (* (/ (/ y x) (/ x y)) -4.0))))))))
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 tmp;
	if ((x * x) <= 5e-245) {
		tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
	} else if ((x * x) <= 2e-88) {
		tmp = t_1;
	} else if ((x * x) <= 2e+90) {
		tmp = -1.0 + (((x * (x / y)) / y) / 4.0);
	} else if ((x * x) <= 4e+277) {
		tmp = t_1;
	} else {
		tmp = 1.0 + (((y / x) / (x / y)) * -4.0);
	}
	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))
	tmp = 0.0
	if (Float64(x * x) <= 5e-245)
		tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0);
	elseif (Float64(x * x) <= 2e-88)
		tmp = t_1;
	elseif (Float64(x * x) <= 2e+90)
		tmp = Float64(-1.0 + Float64(Float64(Float64(x * Float64(x / y)) / y) / 4.0));
	elseif (Float64(x * x) <= 4e+277)
		tmp = t_1;
	else
		tmp = Float64(1.0 + Float64(Float64(Float64(y / x) / Float64(x / y)) * -4.0));
	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[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-245], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e-88], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e+90], N[(-1.0 + N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+277], t$95$1, N[(1.0 + N[(N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision] * -4.0), $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}\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\

\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\
\;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\

\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\
\;\;\;\;t_1\\

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


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

    1. Initial program 48.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 75.5%

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

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

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

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

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

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

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

    if 4.9999999999999997e-245 < (*.f64 x x) < 1.99999999999999987e-88 or 1.99999999999999993e90 < (*.f64 x x) < 4.00000000000000001e277

    1. Initial program 83.0%

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

    if 1.99999999999999987e-88 < (*.f64 x x) < 1.99999999999999993e90

    1. Initial program 60.6%

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

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

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

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

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

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{y \cdot \left(y \cdot 4\right)}} \]
    5. Step-by-step derivation
      1. div-sub33.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}}{4} - 1 \]
      2. associate-*r/73.9%

        \[\leadsto \frac{\color{blue}{\frac{\frac{x}{y} \cdot x}{y}}}{4} - 1 \]
    8. Applied egg-rr73.9%

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

    if 4.00000000000000001e277 < (*.f64 x x)

    1. Initial program 8.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 8.5%

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

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

      \[\leadsto \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    5. Taylor expanded in x around inf 82.0%

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

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

        \[\leadsto 1 + -4 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}} \]
      3. times-frac89.0%

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

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

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

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

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

        \[\leadsto 1 + -4 \cdot \color{blue}{\frac{\frac{y}{x}}{\frac{x}{y}}} \]
    9. Applied egg-rr89.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\ \;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\ \;\;\;\;\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{\frac{y}{x}}{\frac{x}{y}} \cdot -4\\ \end{array} \]

Alternative 5: 78.5% accurate, 0.5× 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 := -1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\ \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{\frac{y}{x}}{\frac{x}{y}} \cdot -4\\ \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 (+ -1.0 (/ (/ (* x (/ x y)) y) 4.0))))
   (if (<= (* x x) 5e-245)
     t_2
     (if (<= (* x x) 2e-88)
       t_1
       (if (<= (* x x) 2e+90)
         t_2
         (if (<= (* x x) 4e+277) t_1 (+ 1.0 (* (/ (/ y x) (/ x y)) -4.0))))))))
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 = -1.0 + (((x * (x / y)) / y) / 4.0);
	double tmp;
	if ((x * x) <= 5e-245) {
		tmp = t_2;
	} else if ((x * x) <= 2e-88) {
		tmp = t_1;
	} else if ((x * x) <= 2e+90) {
		tmp = t_2;
	} else if ((x * x) <= 4e+277) {
		tmp = t_1;
	} else {
		tmp = 1.0 + (((y / x) / (x / y)) * -4.0);
	}
	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 = (-1.0d0) + (((x * (x / y)) / y) / 4.0d0)
    if ((x * x) <= 5d-245) then
        tmp = t_2
    else if ((x * x) <= 2d-88) then
        tmp = t_1
    else if ((x * x) <= 2d+90) then
        tmp = t_2
    else if ((x * x) <= 4d+277) then
        tmp = t_1
    else
        tmp = 1.0d0 + (((y / x) / (x / y)) * (-4.0d0))
    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 = -1.0 + (((x * (x / y)) / y) / 4.0);
	double tmp;
	if ((x * x) <= 5e-245) {
		tmp = t_2;
	} else if ((x * x) <= 2e-88) {
		tmp = t_1;
	} else if ((x * x) <= 2e+90) {
		tmp = t_2;
	} else if ((x * x) <= 4e+277) {
		tmp = t_1;
	} else {
		tmp = 1.0 + (((y / x) / (x / y)) * -4.0);
	}
	return tmp;
}
def code(x, y):
	t_0 = y * (y * 4.0)
	t_1 = ((x * x) - t_0) / ((x * x) + t_0)
	t_2 = -1.0 + (((x * (x / y)) / y) / 4.0)
	tmp = 0
	if (x * x) <= 5e-245:
		tmp = t_2
	elif (x * x) <= 2e-88:
		tmp = t_1
	elif (x * x) <= 2e+90:
		tmp = t_2
	elif (x * x) <= 4e+277:
		tmp = t_1
	else:
		tmp = 1.0 + (((y / x) / (x / y)) * -4.0)
	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(-1.0 + Float64(Float64(Float64(x * Float64(x / y)) / y) / 4.0))
	tmp = 0.0
	if (Float64(x * x) <= 5e-245)
		tmp = t_2;
	elseif (Float64(x * x) <= 2e-88)
		tmp = t_1;
	elseif (Float64(x * x) <= 2e+90)
		tmp = t_2;
	elseif (Float64(x * x) <= 4e+277)
		tmp = t_1;
	else
		tmp = Float64(1.0 + Float64(Float64(Float64(y / x) / Float64(x / y)) * -4.0));
	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 = -1.0 + (((x * (x / y)) / y) / 4.0);
	tmp = 0.0;
	if ((x * x) <= 5e-245)
		tmp = t_2;
	elseif ((x * x) <= 2e-88)
		tmp = t_1;
	elseif ((x * x) <= 2e+90)
		tmp = t_2;
	elseif ((x * x) <= 4e+277)
		tmp = t_1;
	else
		tmp = 1.0 + (((y / x) / (x / y)) * -4.0);
	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[(-1.0 + N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-245], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 2e-88], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e+90], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 4e+277], t$95$1, N[(1.0 + N[(N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision] * -4.0), $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 := -1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x x) < 4.9999999999999997e-245 or 1.99999999999999987e-88 < (*.f64 x x) < 1.99999999999999993e90

    1. Initial program 51.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 40.6%

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

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

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

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

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{y \cdot \left(y \cdot 4\right)}} \]
    5. Step-by-step derivation
      1. div-sub40.4%

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

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

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

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

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

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

        \[\leadsto \frac{{\left(\frac{x}{y}\right)}^{2}}{4} - \color{blue}{1} \]
    6. Applied egg-rr80.8%

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

        \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}}{4} - 1 \]
      2. associate-*r/80.8%

        \[\leadsto \frac{\color{blue}{\frac{\frac{x}{y} \cdot x}{y}}}{4} - 1 \]
    8. Applied egg-rr80.8%

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

    if 4.9999999999999997e-245 < (*.f64 x x) < 1.99999999999999987e-88 or 1.99999999999999993e90 < (*.f64 x x) < 4.00000000000000001e277

    1. Initial program 83.0%

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

    if 4.00000000000000001e277 < (*.f64 x x)

    1. Initial program 8.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 8.5%

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

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

      \[\leadsto \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    5. Taylor expanded in x around inf 82.0%

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

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

        \[\leadsto 1 + -4 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}} \]
      3. times-frac89.0%

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

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

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

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

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

        \[\leadsto 1 + -4 \cdot \color{blue}{\frac{\frac{y}{x}}{\frac{x}{y}}} \]
    9. Applied egg-rr89.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\ \;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\ \;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\ \;\;\;\;\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{\frac{y}{x}}{\frac{x}{y}} \cdot -4\\ \end{array} \]

Alternative 6: 75.7% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+101}:\\
\;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\

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


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

    1. Initial program 58.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 41.2%

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

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

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

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

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{y \cdot \left(y \cdot 4\right)}} \]
    5. Step-by-step derivation
      1. div-sub40.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot \frac{x}{y}}}{4} - 1 \]
      2. associate-*r/76.0%

        \[\leadsto \frac{\color{blue}{\frac{\frac{x}{y} \cdot x}{y}}}{4} - 1 \]
    8. Applied egg-rr76.0%

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

    if 2e101 < (*.f64 x x)

    1. Initial program 27.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 25.1%

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

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

      \[\leadsto \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    5. Taylor expanded in x around inf 79.3%

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

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

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

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

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

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

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

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

        \[\leadsto 1 + -4 \cdot \color{blue}{\frac{\frac{y}{x}}{\frac{x}{y}}} \]
    9. Applied egg-rr84.4%

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

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

Alternative 7: 63.4% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.6 \cdot 10^{+50}:\\
\;\;\;\;-1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.59999999999999986e50

    1. Initial program 50.2%

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

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

    if 3.59999999999999986e50 < x

    1. Initial program 25.5%

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

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

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

      \[\leadsto \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    5. Taylor expanded in x around inf 80.3%

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

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

        \[\leadsto 1 + -4 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}} \]
      3. times-frac88.0%

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

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

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

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

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

        \[\leadsto 1 + -4 \cdot \color{blue}{\frac{\frac{y}{x}}{\frac{x}{y}}} \]
    9. Applied egg-rr88.0%

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

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

Alternative 8: 63.1% accurate, 6.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+51}:\\
\;\;\;\;-1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1e51

    1. Initial program 50.2%

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

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

    if 1e51 < x

    1. Initial program 25.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 10^{+51}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 9: 50.9% 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 44.9%

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

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

    \[\leadsto -1 \]

Developer target: 50.6% 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 2023215 
(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))))