Average Error: 31.7 → 12.9
Time: 2.1s
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 \leq -1.4754112619831426 \cdot 10^{+145}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.989093596962881 \cdot 10^{-107}:\\ \;\;\;\;\frac{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\sqrt{x \cdot x + y \cdot \left(y \cdot 4\right)}}}{\sqrt{x \cdot x + y \cdot \left(y \cdot 4\right)}}\\ \mathbf{elif}\;y \leq 9.962240782868924 \cdot 10^{-68}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.704440708939182 \cdot 10^{+44}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 3.6825850148726655 \cdot 10^{+65}:\\ \;\;\;\;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 \leq -1.4754112619831426 \cdot 10^{+145}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \leq 9.962240782868924 \cdot 10^{-68}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \leq 3.6825850148726655 \cdot 10^{+65}:\\
\;\;\;\;1\\

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

\end{array}
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (if (<= y -1.4754112619831426e+145)
   -1.0
   (if (<= y -1.989093596962881e-107)
     (/
      (/ (- (* x x) (* y (* y 4.0))) (sqrt (+ (* x x) (* y (* y 4.0)))))
      (sqrt (+ (* x x) (* y (* y 4.0)))))
     (if (<= y 9.962240782868924e-68)
       1.0
       (if (<= y 1.704440708939182e+44)
         (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
         (if (<= y 3.6825850148726655e+65) 1.0 -1.0))))))
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 ((y <= -1.4754112619831426e+145)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((y <= -1.989093596962881e-107)) {
			VAR_1 = ((((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) sqrt(((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))))) / ((double) sqrt(((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0)))))))));
		} else {
			double VAR_2;
			if ((y <= 9.962240782868924e-68)) {
				VAR_2 = 1.0;
			} else {
				double VAR_3;
				if ((y <= 1.704440708939182e+44)) {
					VAR_3 = (((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 <= 3.6825850148726655e+65)) {
						VAR_4 = 1.0;
					} 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.7
Target31.4
Herbie12.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} < 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 4 regimes
  2. if y < -1.4754112619831426e145 or 3.68258501487266548e65 < y

    1. Initial program 53.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 10.3

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

    if -1.4754112619831426e145 < y < -1.989093596962881e-107

    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-sqr-sqrt15.7

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\]
    4. Applied associate-/r*15.7

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

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

    if -1.989093596962881e-107 < y < 9.9622407828689237e-68 or 1.704440708939182e44 < y < 3.68258501487266548e65

    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 inf 13.3

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

    if 9.9622407828689237e-68 < y < 1.704440708939182e44

    1. Initial program 15.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.4754112619831426 \cdot 10^{+145}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.989093596962881 \cdot 10^{-107}:\\ \;\;\;\;\frac{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\sqrt{x \cdot x + y \cdot \left(y \cdot 4\right)}}}{\sqrt{x \cdot x + y \cdot \left(y \cdot 4\right)}}\\ \mathbf{elif}\;y \leq 9.962240782868924 \cdot 10^{-68}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.704440708939182 \cdot 10^{+44}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 3.6825850148726655 \cdot 10^{+65}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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