Average Error: 31.6 → 12.5
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} \mathbf{if}\;x \cdot x \leq 9.0166980366027 \cdot 10^{-321}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 1.913632195396027 \cdot 10^{-189}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{3}}\\ \mathbf{elif}\;x \cdot x \leq 3.544760866850198 \cdot 10^{-134}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 4.76257875583899 \cdot 10^{+191}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{3}}\\ \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 \cdot x \leq 9.0166980366027 \cdot 10^{-321}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \cdot x \leq 3.544760866850198 \cdot 10^{-134}:\\
\;\;\;\;-1\\

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

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

\end{array}
double code(double x, double y) {
	return (((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 ((((double) (x * x)) <= 9.0166980366027e-321)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((((double) (x * x)) <= 1.913632195396027e-189)) {
			VAR_1 = ((double) cbrt(((double) pow((((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))), 3.0))));
		} else {
			double VAR_2;
			if ((((double) (x * x)) <= 3.544760866850198e-134)) {
				VAR_2 = -1.0;
			} else {
				double VAR_3;
				if ((((double) (x * x)) <= 4.76257875583899e+191)) {
					VAR_3 = ((double) cbrt(((double) pow((((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))), 3.0))));
				} else {
					VAR_3 = 1.0;
				}
				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
Herbie12.5
\[\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 x) < 9.0167e-321 or 1.9136321953960272e-189 < (* x x) < 3.54476086685019787e-134

    1. Initial program Error: 29.3 bits

      \[\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 Error: 10.3 bits

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

    if 9.0167e-321 < (* x x) < 1.9136321953960272e-189 or 3.54476086685019787e-134 < (* x x) < 4.7625787558389901e191

    1. Initial program Error: 15.7 bits

      \[\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-cubeError: 42.2 bits

      \[\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-cubeError: 42.5 bits

      \[\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-undivError: 42.5 bits

      \[\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. SimplifiedError: 15.7 bits

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

    if 4.7625787558389901e191 < (* x x)

    1. Initial program Error: 50.3 bits

      \[\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 Error: 10.8 bits

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplificationError: 12.5 bits

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 9.0166980366027 \cdot 10^{-321}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 1.913632195396027 \cdot 10^{-189}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{3}}\\ \mathbf{elif}\;x \cdot x \leq 3.544760866850198 \cdot 10^{-134}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 4.76257875583899 \cdot 10^{+191}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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