Average Error: 32.0 → 13.4
Time: 2.3s
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 -8.293431200400436 \cdot 10^{99}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.8251996632071771 \cdot 10^{89}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -9.7380857919525121 \cdot 10^{-6}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;x \le -4.36418612802454612 \cdot 10^{-48}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -5.53298183894072479 \cdot 10^{-116}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;x \le 8.625951048299595 \cdot 10^{-94}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.59699097472444289 \cdot 10^{55}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;x \le 6.7287380773174298 \cdot 10^{75}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.2759440033047258 \cdot 10^{144}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \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 -8.293431200400436 \cdot 10^{99}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -1.8251996632071771 \cdot 10^{89}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -9.7380857919525121 \cdot 10^{-6}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\

\mathbf{elif}\;x \le -4.36418612802454612 \cdot 10^{-48}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -5.53298183894072479 \cdot 10^{-116}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\

\mathbf{elif}\;x \le 8.625951048299595 \cdot 10^{-94}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 4.59699097472444289 \cdot 10^{55}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\

\mathbf{elif}\;x \le 6.7287380773174298 \cdot 10^{75}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 2.2759440033047258 \cdot 10^{144}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\

\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 <= -8.293431200400436e+99)) {
		VAR = 1.0;
	} else {
		double VAR_1;
		if ((x <= -1.825199663207177e+89)) {
			VAR_1 = -1.0;
		} else {
			double VAR_2;
			if ((x <= -9.738085791952512e-06)) {
				VAR_2 = ((double) log(((double) exp(((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 ((x <= -4.364186128024546e-48)) {
					VAR_3 = -1.0;
				} else {
					double VAR_4;
					if ((x <= -5.532981838940725e-116)) {
						VAR_4 = ((double) log(((double) exp(((double) (((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))))))));
					} else {
						double VAR_5;
						if ((x <= 8.625951048299595e-94)) {
							VAR_5 = -1.0;
						} else {
							double VAR_6;
							if ((x <= 4.596990974724443e+55)) {
								VAR_6 = ((double) log(((double) exp(((double) (((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))))))));
							} else {
								double VAR_7;
								if ((x <= 6.72873807731743e+75)) {
									VAR_7 = -1.0;
								} else {
									double VAR_8;
									if ((x <= 2.275944003304726e+144)) {
										VAR_8 = ((double) log(((double) exp(((double) (((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))))))));
									} else {
										VAR_8 = 1.0;
									}
									VAR_7 = VAR_8;
								}
								VAR_6 = VAR_7;
							}
							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

Original32.0
Target31.7
Herbie13.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 x < -8.293431200400436e99 or 2.2759440033047258e144 < x

    1. Initial program 55.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 inf 9.7

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

    if -8.293431200400436e99 < x < -1.8251996632071771e89 or -9.7380857919525121e-6 < x < -4.36418612802454612e-48 or -5.53298183894072479e-116 < x < 8.625951048299595e-94 or 4.59699097472444289e55 < x < 6.7287380773174298e75

    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 14.1

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

    if -1.8251996632071771e89 < x < -9.7380857919525121e-6 or -4.36418612802454612e-48 < x < -5.53298183894072479e-116 or 8.625951048299595e-94 < x < 4.59699097472444289e55 or 6.7287380773174298e75 < x < 2.2759440033047258e144

    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}\]
    2. Using strategy rm
    3. Applied add-log-exp16.3

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.293431200400436 \cdot 10^{99}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.8251996632071771 \cdot 10^{89}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -9.7380857919525121 \cdot 10^{-6}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;x \le -4.36418612802454612 \cdot 10^{-48}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -5.53298183894072479 \cdot 10^{-116}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;x \le 8.625951048299595 \cdot 10^{-94}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.59699097472444289 \cdot 10^{55}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;x \le 6.7287380773174298 \cdot 10^{75}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.2759440033047258 \cdot 10^{144}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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