Average Error: 31.5 → 13.8
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(x, x, -4 \cdot \left(y \cdot y\right)\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\\ t_1 := {\left(\frac{y}{x}\right)}^{2}\\ \mathbf{if}\;y \leq -2.7 \cdot 10^{+180}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -6 \cdot 10^{+110}:\\ \;\;\;\;{\left(\sqrt[3]{1 + t_1 \cdot -8}\right)}^{3}\\ \mathbf{elif}\;y \leq -1 \cdot 10^{-22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.5 \cdot 10^{-23}:\\ \;\;\;\;\sqrt[3]{{\left(1 + -8 \cdot \log \left(e^{t_1}\right)\right)}^{3}}\\ \mathbf{elif}\;y \leq -1.45 \cdot 10^{-85}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-159}:\\ \;\;\;\;\mathsf{fma}\left(t_1, -8, 1\right)\\ \mathbf{elif}\;y \leq 1.12 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-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 x x (* -4.0 (* y y))) (fma x x (* y (* y 4.0)))))
        (t_1 (pow (/ y x) 2.0)))
   (if (<= y -2.7e+180)
     -1.0
     (if (<= y -6e+110)
       (pow (cbrt (+ 1.0 (* t_1 -8.0))) 3.0)
       (if (<= y -1e-22)
         t_0
         (if (<= y -1.5e-23)
           (cbrt (pow (+ 1.0 (* -8.0 (log (exp t_1)))) 3.0))
           (if (<= y -1.45e-85)
             t_0
             (if (<= y 2.05e-159)
               (fma t_1 -8.0 1.0)
               (if (<= y 1.12e+123) t_0 -1.0)))))))))
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(x, x, (-4.0 * (y * y))) / fma(x, x, (y * (y * 4.0)));
	double t_1 = pow((y / x), 2.0);
	double tmp;
	if (y <= -2.7e+180) {
		tmp = -1.0;
	} else if (y <= -6e+110) {
		tmp = pow(cbrt((1.0 + (t_1 * -8.0))), 3.0);
	} else if (y <= -1e-22) {
		tmp = t_0;
	} else if (y <= -1.5e-23) {
		tmp = cbrt(pow((1.0 + (-8.0 * log(exp(t_1)))), 3.0));
	} else if (y <= -1.45e-85) {
		tmp = t_0;
	} else if (y <= 2.05e-159) {
		tmp = fma(t_1, -8.0, 1.0);
	} else if (y <= 1.12e+123) {
		tmp = t_0;
	} else {
		tmp = -1.0;
	}
	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(x, x, Float64(-4.0 * Float64(y * y))) / fma(x, x, Float64(y * Float64(y * 4.0))))
	t_1 = Float64(y / x) ^ 2.0
	tmp = 0.0
	if (y <= -2.7e+180)
		tmp = -1.0;
	elseif (y <= -6e+110)
		tmp = cbrt(Float64(1.0 + Float64(t_1 * -8.0))) ^ 3.0;
	elseif (y <= -1e-22)
		tmp = t_0;
	elseif (y <= -1.5e-23)
		tmp = cbrt((Float64(1.0 + Float64(-8.0 * log(exp(t_1)))) ^ 3.0));
	elseif (y <= -1.45e-85)
		tmp = t_0;
	elseif (y <= 2.05e-159)
		tmp = fma(t_1, -8.0, 1.0);
	elseif (y <= 1.12e+123)
		tmp = t_0;
	else
		tmp = -1.0;
	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[(x * x + N[(-4.0 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * x + N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[y, -2.7e+180], -1.0, If[LessEqual[y, -6e+110], N[Power[N[Power[N[(1.0 + N[(t$95$1 * -8.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision], If[LessEqual[y, -1e-22], t$95$0, If[LessEqual[y, -1.5e-23], N[Power[N[Power[N[(1.0 + N[(-8.0 * N[Log[N[Exp[t$95$1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision], If[LessEqual[y, -1.45e-85], t$95$0, If[LessEqual[y, 2.05e-159], N[(t$95$1 * -8.0 + 1.0), $MachinePrecision], If[LessEqual[y, 1.12e+123], t$95$0, -1.0]]]]]]]]]
\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(x, x, -4 \cdot \left(y \cdot y\right)\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\\
t_1 := {\left(\frac{y}{x}\right)}^{2}\\
\mathbf{if}\;y \leq -2.7 \cdot 10^{+180}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -6 \cdot 10^{+110}:\\
\;\;\;\;{\left(\sqrt[3]{1 + t_1 \cdot -8}\right)}^{3}\\

\mathbf{elif}\;y \leq -1 \cdot 10^{-22}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -1.5 \cdot 10^{-23}:\\
\;\;\;\;\sqrt[3]{{\left(1 + -8 \cdot \log \left(e^{t_1}\right)\right)}^{3}}\\

\mathbf{elif}\;y \leq -1.45 \cdot 10^{-85}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 2.05 \cdot 10^{-159}:\\
\;\;\;\;\mathsf{fma}\left(t_1, -8, 1\right)\\

\mathbf{elif}\;y \leq 1.12 \cdot 10^{+123}:\\
\;\;\;\;t_0\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Target

Original31.5
Target31.2
Herbie13.8
\[\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 5 regimes
  2. if y < -2.70000000000000016e180 or 1.12e123 < y

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

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

    if -2.70000000000000016e180 < y < -6.00000000000000014e110

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

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

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2} \cdot -8}\right)}^{3}} \]

    if -6.00000000000000014e110 < y < -1e-22 or -1.50000000000000001e-23 < y < -1.4500000000000001e-85 or 2.05000000000000007e-159 < y < 1.12e123

    1. Initial program 15.0

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

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

    if -1e-22 < y < -1.50000000000000001e-23

    1. Initial program 11.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 inf 16.7

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

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

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

      \[\leadsto \sqrt[3]{{\left(1 + \color{blue}{\log \left(e^{{\left(\frac{y}{x}\right)}^{2}}\right)} \cdot -8\right)}^{3}} \]

    if -1.4500000000000001e-85 < y < 2.05000000000000007e-159

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.7 \cdot 10^{+180}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -6 \cdot 10^{+110}:\\ \;\;\;\;{\left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2} \cdot -8}\right)}^{3}\\ \mathbf{elif}\;y \leq -1 \cdot 10^{-22}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -4 \cdot \left(y \cdot y\right)\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\\ \mathbf{elif}\;y \leq -1.5 \cdot 10^{-23}:\\ \;\;\;\;\sqrt[3]{{\left(1 + -8 \cdot \log \left(e^{{\left(\frac{y}{x}\right)}^{2}}\right)\right)}^{3}}\\ \mathbf{elif}\;y \leq -1.45 \cdot 10^{-85}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -4 \cdot \left(y \cdot y\right)\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-159}:\\ \;\;\;\;\mathsf{fma}\left({\left(\frac{y}{x}\right)}^{2}, -8, 1\right)\\ \mathbf{elif}\;y \leq 1.12 \cdot 10^{+123}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -4 \cdot \left(y \cdot y\right)\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Reproduce

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