Average Error: 30.9 → 11.7
Time: 2.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}\;x \leq -4.011305840276716 \cdot 10^{+97}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.4200406406138674 \cdot 10^{-159}:\\ \;\;\;\;x \cdot \frac{x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - y \cdot \frac{y}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{4}}\\ \mathbf{elif}\;x \leq 1.5691779440763096 \cdot 10^{-150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 9.916395680502954 \cdot 10^{+80}:\\ \;\;\;\;x \cdot \frac{x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - y \cdot \frac{y}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{4}}\\ \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 \leq -4.011305840276716 \cdot 10^{+97}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq -1.4200406406138674 \cdot 10^{-159}:\\
\;\;\;\;x \cdot \frac{x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - y \cdot \frac{y}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{4}}\\

\mathbf{elif}\;x \leq 1.5691779440763096 \cdot 10^{-150}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \leq 9.916395680502954 \cdot 10^{+80}:\\
\;\;\;\;x \cdot \frac{x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - y \cdot \frac{y}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{4}}\\

\mathbf{else}:\\
\;\;\;\;1\\

\end{array}
double code(double x, double y) {
	return (((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 <= -4.011305840276716e+97)) {
		VAR = 1.0;
	} else {
		double VAR_1;
		if ((x <= -1.4200406406138674e-159)) {
			VAR_1 = ((double) (((double) (x * (x / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))))) - ((double) (y * (y / (((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0)))))) / 4.0))))));
		} else {
			double VAR_2;
			if ((x <= 1.5691779440763096e-150)) {
				VAR_2 = -1.0;
			} else {
				double VAR_3;
				if ((x <= 9.916395680502954e+80)) {
					VAR_3 = ((double) (((double) (x * (x / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))))) - ((double) (y * (y / (((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0)))))) / 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

Original30.9
Target30.6
Herbie11.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} < 0.9743233849626781:\\ \;\;\;\;\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 < -4.01130584027671627e97 or 9.916395680502954e80 < x

    1. Initial program 48.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 10.7

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

    if -4.01130584027671627e97 < x < -1.4200406406138674e-159 or 1.5691779440763096e-150 < x < 9.916395680502954e80

    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 div-sub14.8

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

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

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

    if -1.4200406406138674e-159 < x < 1.5691779440763096e-150

    1. Initial program 30.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 8.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.011305840276716 \cdot 10^{+97}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.4200406406138674 \cdot 10^{-159}:\\ \;\;\;\;x \cdot \frac{x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - y \cdot \frac{y}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{4}}\\ \mathbf{elif}\;x \leq 1.5691779440763096 \cdot 10^{-150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 9.916395680502954 \cdot 10^{+80}:\\ \;\;\;\;x \cdot \frac{x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - y \cdot \frac{y}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{4}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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