Average Error: 31.2 → 15.4
Time: 2.5s
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 := \log \left(\sqrt{e^{\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{{\left(\mathsf{hypot}\left(x, y \cdot 2\right)\right)}^{2}}}}\right)\\ \mathbf{if}\;x \leq -4.3416912027427956 \cdot 10^{+26}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 5.608377203181558 \cdot 10^{-58}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 5.032080348772434 \cdot 10^{+85}:\\ \;\;\;\;t_0 + t_0\\ \mathbf{elif}\;x \leq 1.1936372032097385 \cdot 10^{+132}:\\ \;\;\;\;-1\\ \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
         (log
          (sqrt
           (exp
            (/ (fma -4.0 (* y y) (* x x)) (pow (hypot x (* y 2.0)) 2.0)))))))
   (if (<= x -4.3416912027427956e+26)
     1.0
     (if (<= x 5.608377203181558e-58)
       -1.0
       (if (<= x 5.032080348772434e+85)
         (+ t_0 t_0)
         (if (<= x 1.1936372032097385e+132) -1.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 = log(sqrt(exp((fma(-4.0, (y * y), (x * x)) / pow(hypot(x, (y * 2.0)), 2.0)))));
	double tmp;
	if (x <= -4.3416912027427956e+26) {
		tmp = 1.0;
	} else if (x <= 5.608377203181558e-58) {
		tmp = -1.0;
	} else if (x <= 5.032080348772434e+85) {
		tmp = t_0 + t_0;
	} else if (x <= 1.1936372032097385e+132) {
		tmp = -1.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 = log(sqrt(exp(Float64(fma(-4.0, Float64(y * y), Float64(x * x)) / (hypot(x, Float64(y * 2.0)) ^ 2.0)))))
	tmp = 0.0
	if (x <= -4.3416912027427956e+26)
		tmp = 1.0;
	elseif (x <= 5.608377203181558e-58)
		tmp = -1.0;
	elseif (x <= 5.032080348772434e+85)
		tmp = Float64(t_0 + t_0);
	elseif (x <= 1.1936372032097385e+132)
		tmp = -1.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[Log[N[Sqrt[N[Exp[N[(N[(-4.0 * N[(y * y), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] / N[Power[N[Sqrt[x ^ 2 + N[(y * 2.0), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -4.3416912027427956e+26], 1.0, If[LessEqual[x, 5.608377203181558e-58], -1.0, If[LessEqual[x, 5.032080348772434e+85], N[(t$95$0 + t$95$0), $MachinePrecision], If[LessEqual[x, 1.1936372032097385e+132], -1.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 := \log \left(\sqrt{e^{\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{{\left(\mathsf{hypot}\left(x, y \cdot 2\right)\right)}^{2}}}}\right)\\
\mathbf{if}\;x \leq -4.3416912027427956 \cdot 10^{+26}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 5.608377203181558 \cdot 10^{-58}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \leq 5.032080348772434 \cdot 10^{+85}:\\
\;\;\;\;t_0 + t_0\\

\mathbf{elif}\;x \leq 1.1936372032097385 \cdot 10^{+132}:\\
\;\;\;\;-1\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Target

Original31.2
Target30.9
Herbie15.4
\[\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 < -4.3416912027427956e26 or 1.1936372032097385e132 < x

    1. Initial program 48.2

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

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

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

    if -4.3416912027427956e26 < x < 5.6083772031815579e-58 or 5.03208034877243396e85 < x < 1.1936372032097385e132

    1. Initial program 22.8

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

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

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

    if 5.6083772031815579e-58 < x < 5.03208034877243396e85

    1. Initial program 15.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.3416912027427956 \cdot 10^{+26}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 5.608377203181558 \cdot 10^{-58}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 5.032080348772434 \cdot 10^{+85}:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{{\left(\mathsf{hypot}\left(x, y \cdot 2\right)\right)}^{2}}}}\right) + \log \left(\sqrt{e^{\frac{\mathsf{fma}\left(-4, y \cdot y, x \cdot x\right)}{{\left(\mathsf{hypot}\left(x, y \cdot 2\right)\right)}^{2}}}}\right)\\ \mathbf{elif}\;x \leq 1.1936372032097385 \cdot 10^{+132}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Reproduce

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