Average Error: 31.6 → 13.0
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} \mathbf{if}\;x \le -7.842117568339821 \cdot 10^{153}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -2.54668275477538128 \cdot 10^{-159}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)}^{3}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 6.54837042535965277 \cdot 10^{-139}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.17632483470995734 \cdot 10^{-100}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)}^{3}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 3.69226628661608336 \cdot 10^{-13}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.60192956137923708 \cdot 10^{126}:\\ \;\;\;\;\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{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 -7.842117568339821 \cdot 10^{153}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \le 6.54837042535965277 \cdot 10^{-139}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \le 3.69226628661608336 \cdot 10^{-13}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 4.60192956137923708 \cdot 10^{126}:\\
\;\;\;\;\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{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 <= -7.842117568339821e+153)) {
		VAR = 1.0;
	} else {
		double VAR_1;
		if ((x <= -2.5466827547753813e-159)) {
			VAR_1 = ((double) (((double) cbrt(((double) pow(((double) (((double) (x * x)) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y)))))), 3.0)))) - ((double) (((double) (((double) (y * 4.0)) * y)) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))))));
		} else {
			double VAR_2;
			if ((x <= 6.548370425359653e-139)) {
				VAR_2 = -1.0;
			} else {
				double VAR_3;
				if ((x <= 2.1763248347099573e-100)) {
					VAR_3 = ((double) (((double) cbrt(((double) pow(((double) (((double) (x * x)) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y)))))), 3.0)))) - ((double) (((double) (((double) (y * 4.0)) * y)) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))))));
				} else {
					double VAR_4;
					if ((x <= 3.6922662866160834e-13)) {
						VAR_4 = -1.0;
					} else {
						double VAR_5;
						if ((x <= 4.601929561379237e+126)) {
							VAR_5 = ((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 {
							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.6
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 < -7.842117568339821e153 or 4.60192956137923708e126 < x

    1. Initial program 59.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 around inf 9.8

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

    if -7.842117568339821e153 < x < -2.54668275477538128e-159 or 6.54837042535965277e-139 < x < 2.17632483470995734e-100

    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}}\]
    4. Using strategy rm
    5. Applied add-cbrt-cube39.1

      \[\leadsto \frac{x \cdot x}{\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)}}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    6. Applied add-cbrt-cube39.7

      \[\leadsto \frac{x \cdot \color{blue}{\sqrt[3]{\left(x \cdot x\right) \cdot x}}}{\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)}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    7. Applied add-cbrt-cube39.8

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(x \cdot x\right) \cdot x}} \cdot \sqrt[3]{\left(x \cdot x\right) \cdot x}}{\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)}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    8. Applied cbrt-unprod41.0

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\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)}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    9. Applied cbrt-undiv40.9

      \[\leadsto \color{blue}{\sqrt[3]{\frac{\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\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)}}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    10. Simplified16.2

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

    if -2.54668275477538128e-159 < x < 6.54837042535965277e-139 or 2.17632483470995734e-100 < x < 3.69226628661608336e-13

    1. Initial program 27.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 12.3

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

    if 3.69226628661608336e-13 < x < 4.60192956137923708e126

    1. Initial program 14.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 div-sub14.8

      \[\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}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification13.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.842117568339821 \cdot 10^{153}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -2.54668275477538128 \cdot 10^{-159}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)}^{3}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 6.54837042535965277 \cdot 10^{-139}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.17632483470995734 \cdot 10^{-100}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)}^{3}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 3.69226628661608336 \cdot 10^{-13}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.60192956137923708 \cdot 10^{126}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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