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

Percentage Accurate: 50.6% → 74.9%
Time: 7.1s
Alternatives: 5
Speedup: 2.6×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 50.6% accurate, 1.0× speedup?

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

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

Alternative 1: 74.9% accurate, 1.1× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;y_m \leq 62000000000:\\ \;\;\;\;1\\ \mathbf{elif}\;y_m \leq 3.3 \cdot 10^{+62} \lor \neg \left(y_m \leq 4.6 \cdot 10^{+86}\right):\\ \;\;\;\;0.5 \cdot \frac{x \cdot \frac{x}{y_m}}{y_m} + -1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m)
 :precision binary64
 (if (<= y_m 62000000000.0)
   1.0
   (if (or (<= y_m 3.3e+62) (not (<= y_m 4.6e+86)))
     (+ (* 0.5 (/ (* x (/ x y_m)) y_m)) -1.0)
     1.0)))
y_m = fabs(y);
double code(double x, double y_m) {
	double tmp;
	if (y_m <= 62000000000.0) {
		tmp = 1.0;
	} else if ((y_m <= 3.3e+62) || !(y_m <= 4.6e+86)) {
		tmp = (0.5 * ((x * (x / y_m)) / y_m)) + -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8) :: tmp
    if (y_m <= 62000000000.0d0) then
        tmp = 1.0d0
    else if ((y_m <= 3.3d+62) .or. (.not. (y_m <= 4.6d+86))) then
        tmp = (0.5d0 * ((x * (x / y_m)) / y_m)) + (-1.0d0)
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m) {
	double tmp;
	if (y_m <= 62000000000.0) {
		tmp = 1.0;
	} else if ((y_m <= 3.3e+62) || !(y_m <= 4.6e+86)) {
		tmp = (0.5 * ((x * (x / y_m)) / y_m)) + -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m):
	tmp = 0
	if y_m <= 62000000000.0:
		tmp = 1.0
	elif (y_m <= 3.3e+62) or not (y_m <= 4.6e+86):
		tmp = (0.5 * ((x * (x / y_m)) / y_m)) + -1.0
	else:
		tmp = 1.0
	return tmp
y_m = abs(y)
function code(x, y_m)
	tmp = 0.0
	if (y_m <= 62000000000.0)
		tmp = 1.0;
	elseif ((y_m <= 3.3e+62) || !(y_m <= 4.6e+86))
		tmp = Float64(Float64(0.5 * Float64(Float64(x * Float64(x / y_m)) / y_m)) + -1.0);
	else
		tmp = 1.0;
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m)
	tmp = 0.0;
	if (y_m <= 62000000000.0)
		tmp = 1.0;
	elseif ((y_m <= 3.3e+62) || ~((y_m <= 4.6e+86)))
		tmp = (0.5 * ((x * (x / y_m)) / y_m)) + -1.0;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_] := If[LessEqual[y$95$m, 62000000000.0], 1.0, If[Or[LessEqual[y$95$m, 3.3e+62], N[Not[LessEqual[y$95$m, 4.6e+86]], $MachinePrecision]], N[(N[(0.5 * N[(N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], 1.0]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;y_m \leq 62000000000:\\
\;\;\;\;1\\

\mathbf{elif}\;y_m \leq 3.3 \cdot 10^{+62} \lor \neg \left(y_m \leq 4.6 \cdot 10^{+86}\right):\\
\;\;\;\;0.5 \cdot \frac{x \cdot \frac{x}{y_m}}{y_m} + -1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 6.2e10 or 3.3e62 < y < 4.59999999999999979e86

    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. Taylor expanded in x around inf 59.1%

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

    if 6.2e10 < y < 3.3e62 or 4.59999999999999979e86 < y

    1. Initial program 33.3%

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

      \[\leadsto \color{blue}{\left(-0.125 \cdot \frac{{x}^{4}}{{y}^{4}} + 0.5 \cdot \frac{{x}^{2}}{{y}^{2}}\right) - 1} \]
    3. Taylor expanded in x around 0 79.7%

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{\frac{x}{y} \cdot x}{y}} - 1 \]
    7. Applied egg-rr91.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 62000000000:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{+62} \lor \neg \left(y \leq 4.6 \cdot 10^{+86}\right):\\ \;\;\;\;0.5 \cdot \frac{x \cdot \frac{x}{y}}{y} + -1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 2: 76.9% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := y_m \cdot \left(y_m \cdot 4\right)\\
t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{if}\;t_1 \leq 2:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot {\left(\frac{x}{y_m}\right)}^{2} + -1\\


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

    1. Initial program 100.0%

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

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

    1. Initial program 0.0%

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

      \[\leadsto \color{blue}{\left(-0.125 \cdot \frac{{x}^{4}}{{y}^{4}} + 0.5 \cdot \frac{{x}^{2}}{{y}^{2}}\right) - 1} \]
    3. Taylor expanded in x around 0 40.8%

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

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

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

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

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

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

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

Alternative 3: 76.8% accurate, 0.5× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} t_0 := y_m \cdot \left(y_m \cdot 4\right)\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ \mathbf{if}\;t_1 \leq 2:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x \cdot \frac{x}{y_m}}{y_m} + -1\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m)
 :precision binary64
 (let* ((t_0 (* y_m (* y_m 4.0))) (t_1 (/ (- (* x x) t_0) (+ (* x x) t_0))))
   (if (<= t_1 2.0) t_1 (+ (* 0.5 (/ (* x (/ x y_m)) y_m)) -1.0))))
y_m = fabs(y);
double code(double x, double y_m) {
	double t_0 = y_m * (y_m * 4.0);
	double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
	double tmp;
	if (t_1 <= 2.0) {
		tmp = t_1;
	} else {
		tmp = (0.5 * ((x * (x / y_m)) / y_m)) + -1.0;
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = y_m * (y_m * 4.0d0)
    t_1 = ((x * x) - t_0) / ((x * x) + t_0)
    if (t_1 <= 2.0d0) then
        tmp = t_1
    else
        tmp = (0.5d0 * ((x * (x / y_m)) / y_m)) + (-1.0d0)
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m) {
	double t_0 = y_m * (y_m * 4.0);
	double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
	double tmp;
	if (t_1 <= 2.0) {
		tmp = t_1;
	} else {
		tmp = (0.5 * ((x * (x / y_m)) / y_m)) + -1.0;
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m):
	t_0 = y_m * (y_m * 4.0)
	t_1 = ((x * x) - t_0) / ((x * x) + t_0)
	tmp = 0
	if t_1 <= 2.0:
		tmp = t_1
	else:
		tmp = (0.5 * ((x * (x / y_m)) / y_m)) + -1.0
	return tmp
y_m = abs(y)
function code(x, y_m)
	t_0 = Float64(y_m * Float64(y_m * 4.0))
	t_1 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0))
	tmp = 0.0
	if (t_1 <= 2.0)
		tmp = t_1;
	else
		tmp = Float64(Float64(0.5 * Float64(Float64(x * Float64(x / y_m)) / y_m)) + -1.0);
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m)
	t_0 = y_m * (y_m * 4.0);
	t_1 = ((x * x) - t_0) / ((x * x) + t_0);
	tmp = 0.0;
	if (t_1 <= 2.0)
		tmp = t_1;
	else
		tmp = (0.5 * ((x * (x / y_m)) / y_m)) + -1.0;
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_] := Block[{t$95$0 = N[(y$95$m * N[(y$95$m * 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[t$95$1, 2.0], t$95$1, N[(N[(0.5 * N[(N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
t_0 := y_m \cdot \left(y_m \cdot 4\right)\\
t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{if}\;t_1 \leq 2:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{x \cdot \frac{x}{y_m}}{y_m} + -1\\


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

    1. Initial program 100.0%

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

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

    1. Initial program 0.0%

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

      \[\leadsto \color{blue}{\left(-0.125 \cdot \frac{{x}^{4}}{{y}^{4}} + 0.5 \cdot \frac{{x}^{2}}{{y}^{2}}\right) - 1} \]
    3. Taylor expanded in x around 0 40.8%

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{\frac{x}{y} \cdot x}{y}} - 1 \]
    7. Applied egg-rr60.0%

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

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

Alternative 4: 74.4% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y_m \leq 44000000000:\\
\;\;\;\;1\\

\mathbf{elif}\;y_m \leq 2 \cdot 10^{+62}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y_m \leq 4.4 \cdot 10^{+86}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 4.4e10 or 2.00000000000000007e62 < y < 4.40000000000000006e86

    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. Taylor expanded in x around inf 59.1%

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

    if 4.4e10 < y < 2.00000000000000007e62 or 4.40000000000000006e86 < y

    1. Initial program 33.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 44000000000:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+62}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{+86}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternative 5: 50.4% accurate, 19.0× speedup?

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

\\
-1
\end{array}
Derivation
  1. Initial program 51.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 51.7%

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

    \[\leadsto -1 \]

Developer target: 51.0% 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 2023320 
(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))))