Average Error: 31.4 → 14.2
Time: 1.8s
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} \mathbf{if}\;x \le -4.2246922815829505 \cdot 10^{161}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -2.74341333021284792 \cdot 10^{112}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -2.59300640596294464 \cdot 10^{-148}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 1.796093000965077 \cdot 10^{-121}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.3302640771995154 \cdot 10^{38}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{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 -4.2246922815829505 \cdot 10^{161}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -2.74341333021284792 \cdot 10^{112}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -2.59300640596294464 \cdot 10^{-148}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;x \le 1.796093000965077 \cdot 10^{-121}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 4.3302640771995154 \cdot 10^{38}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

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

\end{array}
double code(double x, double y) {
	return ((double) (((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))));
}
double code(double x, double y) {
	double VAR;
	if ((x <= -4.2246922815829505e+161)) {
		VAR = 1.0;
	} else {
		double VAR_1;
		if ((x <= -2.743413330212848e+112)) {
			VAR_1 = -1.0;
		} else {
			double VAR_2;
			if ((x <= -2.5930064059629446e-148)) {
				VAR_2 = ((double) (((double) (((double) (x * x)) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y)))))) - ((double) (((double) (((double) (y * 4.0)) * y)) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))))));
			} else {
				double VAR_3;
				if ((x <= 1.7960930009650773e-121)) {
					VAR_3 = -1.0;
				} else {
					double VAR_4;
					if ((x <= 4.330264077199515e+38)) {
						VAR_4 = ((double) (((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))));
					} else {
						VAR_4 = 1.0;
					}
					VAR_3 = VAR_4;
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

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.4
Target31.2
Herbie14.2
\[\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 4 regimes
  2. if x < -4.2246922815829505e161 or 4.3302640771995154e38 < x

    1. Initial program 50.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 around inf 12.4

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

    if -4.2246922815829505e161 < x < -2.74341333021284792e112 or -2.59300640596294464e-148 < x < 1.796093000965077e-121

    1. Initial program 27.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 around 0 14.7

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

    if -2.74341333021284792e112 < x < -2.59300640596294464e-148

    1. Initial program 16.2

      \[\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 div-sub16.2

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

    if 1.796093000965077e-121 < x < 4.3302640771995154e38

    1. Initial program 14.1

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification14.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.2246922815829505 \cdot 10^{161}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -2.74341333021284792 \cdot 10^{112}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -2.59300640596294464 \cdot 10^{-148}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 1.796093000965077 \cdot 10^{-121}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.3302640771995154 \cdot 10^{38}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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