Average Error: 31.8 → 13.7
Time: 1.8s
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 -8.5879199558929298 \cdot 10^{142}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2798534198627767 \cdot 10^{-51}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\ \mathbf{elif}\;y \le -6.28303770149519229 \cdot 10^{-94}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -5.5508566775455689 \cdot 10^{-153}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\ \mathbf{elif}\;y \le 7.23290146831023033 \cdot 10^{-147}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.58118176477928574 \cdot 10^{-34}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\ \mathbf{elif}\;y \le 1.1941518770762368 \cdot 10^{22}:\\ \;\;\;\;1\\ \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 -8.5879199558929298 \cdot 10^{142}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le -6.28303770149519229 \cdot 10^{-94}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \le 7.23290146831023033 \cdot 10^{-147}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \le 1.1941518770762368 \cdot 10^{22}:\\
\;\;\;\;1\\

\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 <= -8.58791995589293e+142)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((y <= -1.2798534198627767e-51)) {
			VAR_1 = ((double) log(((double) exp(((double) (((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))))))));
		} else {
			double VAR_2;
			if ((y <= -6.283037701495192e-94)) {
				VAR_2 = 1.0;
			} else {
				double VAR_3;
				if ((y <= -5.550856677545569e-153)) {
					VAR_3 = ((double) log(((double) exp(((double) (((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))))))));
				} else {
					double VAR_4;
					if ((y <= 7.23290146831023e-147)) {
						VAR_4 = 1.0;
					} else {
						double VAR_5;
						if ((y <= 2.5811817647792857e-34)) {
							VAR_5 = ((double) log(((double) exp(((double) (((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))))))));
						} else {
							double VAR_6;
							if ((y <= 1.1941518770762368e+22)) {
								VAR_6 = 1.0;
							} 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.8
Target31.5
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 y < -8.5879199558929298e142 or 1.1941518770762368e22 < y

    1. Initial program 49.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 0 12.3

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

    if -8.5879199558929298e142 < y < -1.2798534198627767e-51 or -6.28303770149519229e-94 < y < -5.5508566775455689e-153 or 7.23290146831023033e-147 < y < 2.58118176477928574e-34

    1. Initial program 15.7

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

      \[\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)}\]
    4. Simplified15.7

      \[\leadsto \log \color{blue}{\left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)}\]

    if -1.2798534198627767e-51 < y < -6.28303770149519229e-94 or -5.5508566775455689e-153 < y < 7.23290146831023033e-147 or 2.58118176477928574e-34 < y < 1.1941518770762368e22

    1. Initial program 26.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 13.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -8.5879199558929298 \cdot 10^{142}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2798534198627767 \cdot 10^{-51}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\ \mathbf{elif}\;y \le -6.28303770149519229 \cdot 10^{-94}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -5.5508566775455689 \cdot 10^{-153}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\ \mathbf{elif}\;y \le 7.23290146831023033 \cdot 10^{-147}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.58118176477928574 \cdot 10^{-34}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\ \mathbf{elif}\;y \le 1.1941518770762368 \cdot 10^{22}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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