Average Error: 31.5 → 13.3
Time: 2.6s
Precision: 64
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.22011096454309528 \cdot 10^{205}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -3.4425921643712863 \cdot 10^{190}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -2.63068118997058504 \cdot 10^{141}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -3.3639004184692263 \cdot 10^{-161}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, \sqrt{4}, \left|x\right|\right) \cdot \mathsf{fma}\left(-\sqrt{4}, y, \left|x\right|\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 1.1393370701449459 \cdot 10^{-92}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.4947948969068313 \cdot 10^{60}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, \sqrt{4}, \left|x\right|\right) \cdot \mathsf{fma}\left(-\sqrt{4}, y, \left|x\right|\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 3.73657933459427146 \cdot 10^{84}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.58724200356930738 \cdot 10^{101}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, \sqrt{4}, \left|x\right|\right) \cdot \mathsf{fma}\left(-\sqrt{4}, y, \left|x\right|\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;x \le -3.22011096454309528 \cdot 10^{205}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -3.4425921643712863 \cdot 10^{190}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -2.63068118997058504 \cdot 10^{141}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -3.3639004184692263 \cdot 10^{-161}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, \sqrt{4}, \left|x\right|\right) \cdot \mathsf{fma}\left(-\sqrt{4}, y, \left|x\right|\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;x \le 1.1393370701449459 \cdot 10^{-92}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 2.4947948969068313 \cdot 10^{60}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, \sqrt{4}, \left|x\right|\right) \cdot \mathsf{fma}\left(-\sqrt{4}, y, \left|x\right|\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;x \le 3.73657933459427146 \cdot 10^{84}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 4.58724200356930738 \cdot 10^{101}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, \sqrt{4}, \left|x\right|\right) \cdot \mathsf{fma}\left(-\sqrt{4}, y, \left|x\right|\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

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

\end{array}
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 temp;
	if ((x <= -3.2201109645430953e+205)) {
		temp = 1.0;
	} else {
		double temp_1;
		if ((x <= -3.4425921643712863e+190)) {
			temp_1 = -1.0;
		} else {
			double temp_2;
			if ((x <= -2.630681189970585e+141)) {
				temp_2 = 1.0;
			} else {
				double temp_3;
				if ((x <= -3.3639004184692263e-161)) {
					temp_3 = ((fma(y, sqrt(4.0), fabs(x)) * fma(-sqrt(4.0), y, fabs(x))) / ((x * x) + ((y * 4.0) * y)));
				} else {
					double temp_4;
					if ((x <= 1.1393370701449459e-92)) {
						temp_4 = -1.0;
					} else {
						double temp_5;
						if ((x <= 2.4947948969068313e+60)) {
							temp_5 = ((fma(y, sqrt(4.0), fabs(x)) * fma(-sqrt(4.0), y, fabs(x))) / ((x * x) + ((y * 4.0) * y)));
						} else {
							double temp_6;
							if ((x <= 3.7365793345942715e+84)) {
								temp_6 = -1.0;
							} else {
								double temp_7;
								if ((x <= 4.5872420035693074e+101)) {
									temp_7 = ((fma(y, sqrt(4.0), fabs(x)) * fma(-sqrt(4.0), y, fabs(x))) / ((x * x) + ((y * 4.0) * y)));
								} else {
									temp_7 = 1.0;
								}
								temp_6 = temp_7;
							}
							temp_5 = temp_6;
						}
						temp_4 = temp_5;
					}
					temp_3 = temp_4;
				}
				temp_2 = temp_3;
			}
			temp_1 = temp_2;
		}
		temp = temp_1;
	}
	return temp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.5
Target31.2
Herbie13.3
\[\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} \lt 0.974323384962678118:\\ \;\;\;\;\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.2201109645430953e+205 or -3.4425921643712863e+190 < x < -2.630681189970585e+141 or 4.5872420035693074e+101 < x

    1. Initial program 55.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 around inf 9.1

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

    if -3.2201109645430953e+205 < x < -3.4425921643712863e+190 or -3.3639004184692263e-161 < x < 1.1393370701449459e-92 or 2.4947948969068313e+60 < x < 3.7365793345942715e+84

    1. Initial program 28.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 around 0 14.0

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

    if -2.630681189970585e+141 < x < -3.3639004184692263e-161 or 1.1393370701449459e-92 < x < 2.4947948969068313e+60 or 3.7365793345942715e+84 < x < 4.5872420035693074e+101

    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. Using strategy rm
    3. Applied add-sqr-sqrt40.0

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    4. Applied add-sqr-sqrt40.0

      \[\leadsto \frac{x \cdot x - \left(y \cdot \color{blue}{\left(\sqrt{4} \cdot \sqrt{4}\right)}\right) \cdot \left(\sqrt{y} \cdot \sqrt{y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    5. Applied add-sqr-sqrt40.1

      \[\leadsto \frac{x \cdot x - \left(\color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \left(\sqrt{4} \cdot \sqrt{4}\right)\right) \cdot \left(\sqrt{y} \cdot \sqrt{y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    6. Applied unswap-sqr40.1

      \[\leadsto \frac{x \cdot x - \color{blue}{\left(\left(\sqrt{y} \cdot \sqrt{4}\right) \cdot \left(\sqrt{y} \cdot \sqrt{4}\right)\right)} \cdot \left(\sqrt{y} \cdot \sqrt{y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    7. Applied unswap-sqr40.1

      \[\leadsto \frac{x \cdot x - \color{blue}{\left(\left(\sqrt{y} \cdot \sqrt{4}\right) \cdot \sqrt{y}\right) \cdot \left(\left(\sqrt{y} \cdot \sqrt{4}\right) \cdot \sqrt{y}\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    8. Applied add-sqr-sqrt40.1

      \[\leadsto \frac{\color{blue}{\sqrt{x \cdot x} \cdot \sqrt{x \cdot x}} - \left(\left(\sqrt{y} \cdot \sqrt{4}\right) \cdot \sqrt{y}\right) \cdot \left(\left(\sqrt{y} \cdot \sqrt{4}\right) \cdot \sqrt{y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    9. Applied difference-of-squares40.1

      \[\leadsto \frac{\color{blue}{\left(\sqrt{x \cdot x} + \left(\sqrt{y} \cdot \sqrt{4}\right) \cdot \sqrt{y}\right) \cdot \left(\sqrt{x \cdot x} - \left(\sqrt{y} \cdot \sqrt{4}\right) \cdot \sqrt{y}\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    10. Simplified40.0

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(y, \sqrt{4}, \left|x\right|\right)} \cdot \left(\sqrt{x \cdot x} - \left(\sqrt{y} \cdot \sqrt{4}\right) \cdot \sqrt{y}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    11. Simplified16.0

      \[\leadsto \frac{\mathsf{fma}\left(y, \sqrt{4}, \left|x\right|\right) \cdot \color{blue}{\mathsf{fma}\left(-\sqrt{4}, y, \left|x\right|\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.22011096454309528 \cdot 10^{205}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -3.4425921643712863 \cdot 10^{190}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -2.63068118997058504 \cdot 10^{141}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -3.3639004184692263 \cdot 10^{-161}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, \sqrt{4}, \left|x\right|\right) \cdot \mathsf{fma}\left(-\sqrt{4}, y, \left|x\right|\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 1.1393370701449459 \cdot 10^{-92}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.4947948969068313 \cdot 10^{60}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, \sqrt{4}, \left|x\right|\right) \cdot \mathsf{fma}\left(-\sqrt{4}, y, \left|x\right|\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 3.73657933459427146 \cdot 10^{84}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.58724200356930738 \cdot 10^{101}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, \sqrt{4}, \left|x\right|\right) \cdot \mathsf{fma}\left(-\sqrt{4}, y, \left|x\right|\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2020066 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4))) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4)))) 2) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))))

  (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))))