Average Error: 31.6 → 13.1
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 -2.34082694014606577 \cdot 10^{118}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -9.20346477231118837 \cdot 10^{91}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -2.331107751590961 \cdot 10^{-11}:\\ \;\;\;\;\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 -4.69614509835442959 \cdot 10^{-35}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -1.05096368820633768 \cdot 10^{-153}:\\ \;\;\;\;\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 4.66038681197601 \cdot 10^{-135}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.66837021863772414 \cdot 10^{108}:\\ \;\;\;\;\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 -2.34082694014606577 \cdot 10^{118}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -9.20346477231118837 \cdot 10^{91}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -2.331107751590961 \cdot 10^{-11}:\\
\;\;\;\;\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 -4.69614509835442959 \cdot 10^{-35}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -1.05096368820633768 \cdot 10^{-153}:\\
\;\;\;\;\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 4.66038681197601 \cdot 10^{-135}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 6.66837021863772414 \cdot 10^{108}:\\
\;\;\;\;\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 <= -2.3408269401460658e+118)) {
		VAR = 1.0;
	} else {
		double VAR_1;
		if ((x <= -9.203464772311188e+91)) {
			VAR_1 = -1.0;
		} else {
			double VAR_2;
			if ((x <= -2.331107751590961e-11)) {
				VAR_2 = (((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)));
			} else {
				double VAR_3;
				if ((x <= -4.6961450983544296e-35)) {
					VAR_3 = -1.0;
				} else {
					double VAR_4;
					if ((x <= -1.0509636882063377e-153)) {
						VAR_4 = (((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)));
					} else {
						double VAR_5;
						if ((x <= 4.66038681197601e-135)) {
							VAR_5 = -1.0;
						} else {
							double VAR_6;
							if ((x <= 6.668370218637724e+108)) {
								VAR_6 = (((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)));
							} 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.6
Target31.2
Herbie13.1
\[\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 < -2.3408269401460658e+118 or 6.668370218637724e+108 < x

    1. Initial program 54.6

      \[\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.2

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

    if -2.3408269401460658e+118 < x < -9.203464772311188e+91 or -2.331107751590961e-11 < x < -4.6961450983544296e-35 or -1.0509636882063377e-153 < x < 4.66038681197601e-135

    1. Initial program 27.6

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

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

    if -9.203464772311188e+91 < x < -2.331107751590961e-11 or -4.6961450983544296e-35 < x < -1.0509636882063377e-153 or 4.66038681197601e-135 < x < 6.668370218637724e+108

    1. Initial program 16.3

      \[\frac{x \cdot x - \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 simplification13.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.34082694014606577 \cdot 10^{118}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -9.20346477231118837 \cdot 10^{91}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -2.331107751590961 \cdot 10^{-11}:\\ \;\;\;\;\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 -4.69614509835442959 \cdot 10^{-35}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -1.05096368820633768 \cdot 10^{-153}:\\ \;\;\;\;\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 4.66038681197601 \cdot 10^{-135}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.66837021863772414 \cdot 10^{108}:\\ \;\;\;\;\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 2020105 +o rules:numerics
(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))))