Average Error: 31.5 → 13.0
Time: 1.8s
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 -2.88499570758548 \cdot 10^{124}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.48182733090046945 \cdot 10^{-95}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)}^{3}}\\ \mathbf{elif}\;x \le 8.2778672837026512 \cdot 10^{-137}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.42914357264318537:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 2.4875935555596149 \cdot 10^{44}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.30263506617115279 \cdot 10^{154}:\\ \;\;\;\;\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 -2.88499570758548 \cdot 10^{124}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -1.48182733090046945 \cdot 10^{-95}:\\
\;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)}^{3}}\\

\mathbf{elif}\;x \le 8.2778672837026512 \cdot 10^{-137}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 1.42914357264318537:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;x \le 2.4875935555596149 \cdot 10^{44}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 1.30263506617115279 \cdot 10^{154}:\\
\;\;\;\;\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 (((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)));
}
double code(double x, double y) {
	double VAR;
	if ((x <= -2.88499570758548e+124)) {
		VAR = 1.0;
	} else {
		double VAR_1;
		if ((x <= -1.4818273309004695e-95)) {
			VAR_1 = cbrt(pow((((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y))), 3.0));
		} else {
			double VAR_2;
			if ((x <= 8.277867283702651e-137)) {
				VAR_2 = -1.0;
			} else {
				double VAR_3;
				if ((x <= 1.4291435726431854)) {
					VAR_3 = (((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)));
				} else {
					double VAR_4;
					if ((x <= 2.487593555559615e+44)) {
						VAR_4 = -1.0;
					} else {
						double VAR_5;
						if ((x <= 1.3026350661711528e+154)) {
							VAR_5 = (((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)));
						} else {
							VAR_5 = 1.0;
						}
						VAR_4 = VAR_5;
					}
					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.5
Target31.3
Herbie13.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} \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 < -2.88499570758548e+124 or 1.3026350661711528e+154 < x

    1. Initial program 60.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 around inf 9.7

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

    if -2.88499570758548e+124 < x < -1.4818273309004695e-95

    1. Initial program 15.8

      \[\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-cbrt-cube44.3

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

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(x \cdot x - \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)}}}{\sqrt[3]{\left(\left(x \cdot x + \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}}\]
    5. Applied cbrt-undiv44.8

      \[\leadsto \color{blue}{\sqrt[3]{\frac{\left(\left(x \cdot x - \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)}{\left(\left(x \cdot x + \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}}}\]
    6. Simplified15.8

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

    if -1.4818273309004695e-95 < x < 8.277867283702651e-137 or 1.4291435726431854 < x < 2.487593555559615e+44

    1. Initial program 26.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 around 0 12.4

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

    if 8.277867283702651e-137 < x < 1.4291435726431854 or 2.487593555559615e+44 < x < 1.3026350661711528e+154

    1. Initial program 15.8

      \[\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 simplification13.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.88499570758548 \cdot 10^{124}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.48182733090046945 \cdot 10^{-95}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)}^{3}}\\ \mathbf{elif}\;x \le 8.2778672837026512 \cdot 10^{-137}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.42914357264318537:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 2.4875935555596149 \cdot 10^{44}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.30263506617115279 \cdot 10^{154}:\\ \;\;\;\;\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 2020079 
(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))))