Average Error: 31.8 → 15.7
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 \le 5.39154 \cdot 10^{-319}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.85294554972595409 \cdot 10^{-174}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 1.07978344102429074 \cdot 10^{-118}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.28194680881355087 \cdot 10^{-30}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 4.91803343113116234 \cdot 10^{43}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.17507261124868762 \cdot 10^{130}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 1.9413557217607002 \cdot 10^{220}:\\ \;\;\;\;-1\\ \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 \le 5.39154 \cdot 10^{-319}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \cdot x \le 1.07978344102429074 \cdot 10^{-118}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \cdot x \le 4.91803343113116234 \cdot 10^{43}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \cdot x \le 1.9413557217607002 \cdot 10^{220}:\\
\;\;\;\;-1\\

\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 ((((double) (x * x)) <= 5.3915407668072e-319)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((((double) (x * x)) <= 2.852945549725954e-174)) {
			VAR_1 = ((double) (((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))));
		} else {
			double VAR_2;
			if ((((double) (x * x)) <= 1.0797834410242907e-118)) {
				VAR_2 = -1.0;
			} else {
				double VAR_3;
				if ((((double) (x * x)) <= 1.2819468088135509e-30)) {
					VAR_3 = ((double) (((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))));
				} else {
					double VAR_4;
					if ((((double) (x * x)) <= 4.918033431131162e+43)) {
						VAR_4 = -1.0;
					} else {
						double VAR_5;
						if ((((double) (x * x)) <= 1.1750726112486876e+130)) {
							VAR_5 = ((double) (((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))));
						} else {
							double VAR_6;
							if ((((double) (x * x)) <= 1.9413557217607002e+220)) {
								VAR_6 = -1.0;
							} else {
								VAR_6 = 1.0;
							}
							VAR_5 = VAR_6;
						}
						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.8
Target31.5
Herbie15.7
\[\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 x) < 5.39154e-319 or 2.85294554972595409e-174 < (* x x) < 1.07978344102429074e-118 or 1.28194680881355087e-30 < (* x x) < 4.91803343113116234e43 or 1.17507261124868762e130 < (* x x) < 1.9413557217607002e220

    1. Initial program 25.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 18.7

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

    if 5.39154e-319 < (* x x) < 2.85294554972595409e-174 or 1.07978344102429074e-118 < (* x x) < 1.28194680881355087e-30 or 4.91803343113116234e43 < (* x x) < 1.17507261124868762e130

    1. Initial program 15.9

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

    if 1.9413557217607002e220 < (* x x)

    1. Initial program 53.0

      \[\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 11.7

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification15.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 5.39154 \cdot 10^{-319}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.85294554972595409 \cdot 10^{-174}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 1.07978344102429074 \cdot 10^{-118}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.28194680881355087 \cdot 10^{-30}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 4.91803343113116234 \cdot 10^{43}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.17507261124868762 \cdot 10^{130}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 1.9413557217607002 \cdot 10^{220}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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