Average Error: 32.0 → 14.5
Time: 2.2s
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 -453786506312159.188:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.3355785139393343 \cdot 10^{-51}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -1.7546357657244188 \cdot 10^{-118}:\\ \;\;\;\;\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 9.65949313199003763 \cdot 10^{-60}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 3.8241169029132044 \cdot 10^{68}:\\ \;\;\;\;\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 -453786506312159.188:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -1.3355785139393343 \cdot 10^{-51}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -1.7546357657244188 \cdot 10^{-118}:\\
\;\;\;\;\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 9.65949313199003763 \cdot 10^{-60}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 3.8241169029132044 \cdot 10^{68}:\\
\;\;\;\;\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 <= -453786506312159.2)) {
		VAR = 1.0;
	} else {
		double VAR_1;
		if ((x <= -1.3355785139393343e-51)) {
			VAR_1 = -1.0;
		} else {
			double VAR_2;
			if ((x <= -1.7546357657244188e-118)) {
				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 <= 9.659493131990038e-60)) {
					VAR_3 = -1.0;
				} else {
					double VAR_4;
					if ((x <= 3.8241169029132044e+68)) {
						VAR_4 = ((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_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

Original32.0
Target31.7
Herbie14.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} \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 < -453786506312159.188 or 3.8241169029132044e68 < x

    1. Initial program 44.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 inf 14.0

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

    if -453786506312159.188 < x < -1.3355785139393343e-51 or -1.7546357657244188e-118 < x < 9.65949313199003763e-60

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

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

    if -1.3355785139393343e-51 < x < -1.7546357657244188e-118 or 9.65949313199003763e-60 < x < 3.8241169029132044e68

    1. Initial program 15.6

      \[\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-sub15.6

      \[\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 3 regimes into one program.
  4. Final simplification14.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -453786506312159.188:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.3355785139393343 \cdot 10^{-51}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -1.7546357657244188 \cdot 10^{-118}:\\ \;\;\;\;\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 9.65949313199003763 \cdot 10^{-60}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 3.8241169029132044 \cdot 10^{68}:\\ \;\;\;\;\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 2020152 
(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))))