Average Error: 31.5 → 12.0
Time: 2.4s
Precision: binary64
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
\[\begin{array}{l} t_0 := \frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}\\ t_1 := \mathsf{fma}\left(-8, {\left(\frac{y}{x}\right)}^{2}, 1\right)\\ \mathbf{if}\;x \leq -3.940563540672608 \cdot 10^{+146}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.2812740382304326 \cdot 10^{-143}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.885754200942679 \cdot 10^{-107}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \leq 1.2495046734520845 \cdot 10^{+104}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (fma y (* y -4.0) (* x x)) (fma y (* y 4.0) (* x x))))
        (t_1 (fma -8.0 (pow (/ y x) 2.0) 1.0)))
   (if (<= x -3.940563540672608e+146)
     t_1
     (if (<= x -3.2812740382304326e-143)
       t_0
       (if (<= x 5.885754200942679e-107)
         (fma 0.5 (* (/ x y) (/ x y)) -1.0)
         (if (<= x 1.2495046734520845e+104) t_0 t_1))))))
double code(double x, double y) {
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
double code(double x, double y) {
	double t_0 = fma(y, (y * -4.0), (x * x)) / fma(y, (y * 4.0), (x * x));
	double t_1 = fma(-8.0, pow((y / x), 2.0), 1.0);
	double tmp;
	if (x <= -3.940563540672608e+146) {
		tmp = t_1;
	} else if (x <= -3.2812740382304326e-143) {
		tmp = t_0;
	} else if (x <= 5.885754200942679e-107) {
		tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
	} else if (x <= 1.2495046734520845e+104) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y)
	return Float64(Float64(Float64(x * x) - Float64(Float64(y * 4.0) * y)) / Float64(Float64(x * x) + Float64(Float64(y * 4.0) * y)))
end
function code(x, y)
	t_0 = Float64(fma(y, Float64(y * -4.0), Float64(x * x)) / fma(y, Float64(y * 4.0), Float64(x * x)))
	t_1 = fma(-8.0, (Float64(y / x) ^ 2.0), 1.0)
	tmp = 0.0
	if (x <= -3.940563540672608e+146)
		tmp = t_1;
	elseif (x <= -3.2812740382304326e-143)
		tmp = t_0;
	elseif (x <= 5.885754200942679e-107)
		tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0);
	elseif (x <= 1.2495046734520845e+104)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(N[(y * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(y * N[(y * 4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-8.0 * N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x, -3.940563540672608e+146], t$95$1, If[LessEqual[x, -3.2812740382304326e-143], t$95$0, If[LessEqual[x, 5.885754200942679e-107], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[x, 1.2495046734520845e+104], t$95$0, t$95$1]]]]]]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}\\
t_1 := \mathsf{fma}\left(-8, {\left(\frac{y}{x}\right)}^{2}, 1\right)\\
\mathbf{if}\;x \leq -3.940563540672608 \cdot 10^{+146}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -3.2812740382304326 \cdot 10^{-143}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 5.885754200942679 \cdot 10^{-107}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\

\mathbf{elif}\;x \leq 1.2495046734520845 \cdot 10^{+104}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Bits error versus x

Bits error versus y

Target

Original31.5
Target31.2
Herbie12.0
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} < 0.9743233849626781:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if x < -3.94056354067260782e146 or 1.24950467345208449e104 < x

    1. Initial program 56.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 inf 16.0

      \[\leadsto \color{blue}{1 - 8 \cdot \frac{{y}^{2}}{{x}^{2}}} \]
    3. Simplified8.7

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

      \[\leadsto \color{blue}{1 + {\left(\frac{y}{x}\right)}^{2} \cdot -8} \]
    5. Applied egg-rr8.7

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

    if -3.94056354067260782e146 < x < -3.28127403823043262e-143 or 5.8857542009426793e-107 < x < 1.24950467345208449e104

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

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

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}} \]
    4. Taylor expanded in x around 0 16.0

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

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

    if -3.28127403823043262e-143 < x < 5.8857542009426793e-107

    1. Initial program 28.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.940563540672608 \cdot 10^{+146}:\\ \;\;\;\;\mathsf{fma}\left(-8, {\left(\frac{y}{x}\right)}^{2}, 1\right)\\ \mathbf{elif}\;x \leq -3.2812740382304326 \cdot 10^{-143}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}\\ \mathbf{elif}\;x \leq 5.885754200942679 \cdot 10^{-107}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \leq 1.2495046734520845 \cdot 10^{+104}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-8, {\left(\frac{y}{x}\right)}^{2}, 1\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022150 
(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))))