Average Error: 32.1 → 13.7
Time: 1.1s
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 -3.08310863609937876 \cdot 10^{138}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.4247950034871411 \cdot 10^{-65}:\\ \;\;\;\;\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 5.15744740423650361 \cdot 10^{-136}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 5.8877866093643367 \cdot 10^{-36}:\\ \;\;\;\;\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 1914785280668363300:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.02681147685658205 \cdot 10^{120}:\\ \;\;\;\;\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 -3.08310863609937876 \cdot 10^{138}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -1.4247950034871411 \cdot 10^{-65}:\\
\;\;\;\;\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 5.15744740423650361 \cdot 10^{-136}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 5.8877866093643367 \cdot 10^{-36}:\\
\;\;\;\;\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 1914785280668363300:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 2.02681147685658205 \cdot 10^{120}:\\
\;\;\;\;\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 <= -3.083108636099379e+138)) {
		VAR = 1.0;
	} else {
		double VAR_1;
		if ((x <= -1.4247950034871411e-65)) {
			VAR_1 = (((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)));
		} else {
			double VAR_2;
			if ((x <= 5.1574474042365036e-136)) {
				VAR_2 = -1.0;
			} else {
				double VAR_3;
				if ((x <= 5.887786609364337e-36)) {
					VAR_3 = (((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)));
				} else {
					double VAR_4;
					if ((x <= 1.9147852806683633e+18)) {
						VAR_4 = -1.0;
					} else {
						double VAR_5;
						if ((x <= 2.026811476856582e+120)) {
							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

Original32.1
Target31.7
Herbie13.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 < -3.083108636099379e+138 or 2.026811476856582e+120 < x

    1. Initial program 58.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 10.3

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

    if -3.083108636099379e+138 < x < -1.4247950034871411e-65 or 5.1574474042365036e-136 < x < 5.887786609364337e-36 or 1.9147852806683633e+18 < x < 2.026811476856582e+120

    1. Initial program 16.8

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

    if -1.4247950034871411e-65 < x < 5.1574474042365036e-136 or 5.887786609364337e-36 < x < 1.9147852806683633e+18

    1. Initial program 25.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.08310863609937876 \cdot 10^{138}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.4247950034871411 \cdot 10^{-65}:\\ \;\;\;\;\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 5.15744740423650361 \cdot 10^{-136}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 5.8877866093643367 \cdot 10^{-36}:\\ \;\;\;\;\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 1914785280668363300:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.02681147685658205 \cdot 10^{120}:\\ \;\;\;\;\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 2020078 
(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))))