Average Error: 31.8 → 12.4
Time: 1.6s
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}\;y \le -2.70873612826175788 \cdot 10^{89}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.1206412856111805 \cdot 10^{64}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -8.20523521345841934 \cdot 10^{-99}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 2.4422272024826744 \cdot 10^{-116}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.05417644285835125 \cdot 10^{105}:\\ \;\;\;\;\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}\;y \le -2.70873612826175788 \cdot 10^{89}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -2.1206412856111805 \cdot 10^{64}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \le 2.4422272024826744 \cdot 10^{-116}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 1.05417644285835125 \cdot 10^{105}:\\
\;\;\;\;\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 ((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 ((y <= -2.708736128261758e+89)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((y <= -2.1206412856111805e+64)) {
			VAR_1 = 1.0;
		} else {
			double VAR_2;
			if ((y <= -8.20523521345842e-99)) {
				VAR_2 = ((double) (((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))));
			} else {
				double VAR_3;
				if ((y <= 2.4422272024826744e-116)) {
					VAR_3 = 1.0;
				} else {
					double VAR_4;
					if ((y <= 1.0541764428583513e+105)) {
						VAR_4 = ((double) (((double) (((double) (x * x)) - ((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

Original31.8
Target31.5
Herbie12.4
\[\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 y < -2.70873612826175788e89 or 1.05417644285835125e105 < y

    1. Initial program 51.8

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

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

    if -2.70873612826175788e89 < y < -2.1206412856111805e64 or -8.20523521345841934e-99 < y < 2.4422272024826744e-116

    1. Initial program 26.2

      \[\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}\]

    if -2.1206412856111805e64 < y < -8.20523521345841934e-99 or 2.4422272024826744e-116 < y < 1.05417644285835125e105

    1. Initial program 15.2

      \[\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 simplification12.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.70873612826175788 \cdot 10^{89}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.1206412856111805 \cdot 10^{64}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -8.20523521345841934 \cdot 10^{-99}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 2.4422272024826744 \cdot 10^{-116}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.05417644285835125 \cdot 10^{105}:\\ \;\;\;\;\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 2020153 
(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))))