Average Error: 31.1 → 11.9
Time: 2.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 -3.59212080144569144 \cdot 10^{136}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.70222773693093438 \cdot 10^{-104}:\\ \;\;\;\;\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.308403323997654 \cdot 10^{-140}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.03728651240276817 \cdot 10^{145}:\\ \;\;\;\;x \cdot \frac{x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - y \cdot \left(y \cdot \frac{4}{x \cdot x + y \cdot \left(y \cdot 4\right)}\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}\;y \le -3.59212080144569144 \cdot 10^{136}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -3.70222773693093438 \cdot 10^{-104}:\\
\;\;\;\;\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.308403323997654 \cdot 10^{-140}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 1.03728651240276817 \cdot 10^{145}:\\
\;\;\;\;x \cdot \frac{x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - y \cdot \left(y \cdot \frac{4}{x \cdot x + y \cdot \left(y \cdot 4\right)}\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 ((y <= -3.5921208014456914e+136)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((y <= -3.7022277369309344e-104)) {
			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 <= 1.308403323997654e-140)) {
				VAR_2 = 1.0;
			} else {
				double VAR_3;
				if ((y <= 1.0372865124027682e+145)) {
					VAR_3 = ((double) (((double) (x * ((double) (x / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0)))))))))) - ((double) (y * ((double) (y * ((double) (4.0 / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))))))))));
				} else {
					VAR_3 = -1.0;
				}
				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.1
Target30.8
Herbie11.9
\[\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 4 regimes
  2. if y < -3.59212080144569144e136 or 1.03728651240276817e145 < y

    1. Initial program 60.1

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

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

    if -3.59212080144569144e136 < y < -3.70222773693093438e-104

    1. Initial program 14.8

      \[\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-exp14.8

      \[\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. Simplified14.8

      \[\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 -3.70222773693093438e-104 < y < 1.308403323997654e-140

    1. Initial program 27.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 inf 10.0

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

    if 1.308403323997654e-140 < y < 1.03728651240276817e145

    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 div-sub15.7

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]
    4. Simplified15.3

      \[\leadsto \color{blue}{x \cdot \frac{x}{x \cdot x + y \cdot \left(y \cdot 4\right)}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    5. Simplified15.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -3.59212080144569144 \cdot 10^{136}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.70222773693093438 \cdot 10^{-104}:\\ \;\;\;\;\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.308403323997654 \cdot 10^{-140}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.03728651240276817 \cdot 10^{145}:\\ \;\;\;\;x \cdot \frac{x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - y \cdot \left(y \cdot \frac{4}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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