Average Error: 47.9 → 31.4
Time: 2.7s
Precision: binary64
\[[x, y] = \mathsf{sort}([x, y]) \\]
\[\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 -2.652976160851104 \cdot 10^{-175}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 3.2823881671957526 \cdot 10^{-151}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.756993983734216 \cdot 10^{-26}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 8.46966307063159 \cdot 10^{-14}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2.541450281263339 \cdot 10^{+107}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 8.524407389953581 \cdot 10^{+198}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 6.341550649972557 \cdot 10^{+261}:\\ \;\;\;\;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 -2.652976160851104 \cdot 10^{-175}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 3.2823881671957526 \cdot 10^{-151}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 4.756993983734216 \cdot 10^{-26}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 8.46966307063159 \cdot 10^{-14}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 2.541450281263339 \cdot 10^{+107}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 8.524407389953581 \cdot 10^{+198}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 6.341550649972557 \cdot 10^{+261}:\\
\;\;\;\;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 -2.652976160851104e-175)
   1.0
   (if (<= y 3.2823881671957526e-151)
     -1.0
     (if (<= y 4.756993983734216e-26)
       1.0
       (if (<= y 8.46966307063159e-14)
         -1.0
         (if (<= y 2.541450281263339e+107)
           1.0
           (if (<= y 8.524407389953581e+198)
             -1.0
             (if (<= y 6.341550649972557e+261) 1.0 -1.0))))))))
double code(double x, double y) {
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
double code(double x, double y) {
	double tmp;
	if (y <= -2.652976160851104e-175) {
		tmp = 1.0;
	} else if (y <= 3.2823881671957526e-151) {
		tmp = -1.0;
	} else if (y <= 4.756993983734216e-26) {
		tmp = 1.0;
	} else if (y <= 8.46966307063159e-14) {
		tmp = -1.0;
	} else if (y <= 2.541450281263339e+107) {
		tmp = 1.0;
	} else if (y <= 8.524407389953581e+198) {
		tmp = -1.0;
	} else if (y <= 6.341550649972557e+261) {
		tmp = 1.0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original47.9
Target47.5
Herbie31.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} < 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 2 regimes
  2. if y < -2.6529761608511038e-175 or 3.28238816719575257e-151 < y < 4.7569939837342163e-26 or 8.4696630706315897e-14 < y < 2.54145028126333895e107 or 8.52440738995358133e198 < y < 6.3415506499725572e261

    1. Initial program 45.9

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Simplified45.9

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y \cdot y, -4, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}} \]
    3. Taylor expanded in y around 0 31.4

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

    if -2.6529761608511038e-175 < y < 3.28238816719575257e-151 or 4.7569939837342163e-26 < y < 8.4696630706315897e-14 or 2.54145028126333895e107 < y < 8.52440738995358133e198 or 6.3415506499725572e261 < y

    1. Initial program 50.2

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Simplified50.2

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y \cdot y, -4, x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}} \]
    3. Taylor expanded in y around inf 31.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.652976160851104 \cdot 10^{-175}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 3.2823881671957526 \cdot 10^{-151}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.756993983734216 \cdot 10^{-26}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 8.46966307063159 \cdot 10^{-14}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2.541450281263339 \cdot 10^{+107}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 8.524407389953581 \cdot 10^{+198}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 6.341550649972557 \cdot 10^{+261}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Reproduce

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