Average Error: 32.0 → 13.7
Time: 3.7s
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 -2.1778217648239176 \cdot 10^{+77}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.3265302524848746 \cdot 10^{-94}:\\ \;\;\;\;\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 4.26375791351412 \cdot 10^{-167}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 0.00715413837609351:\\ \;\;\;\;\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 5.368248308510426 \cdot 10^{+49}:\\ \;\;\;\;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.1778217648239176 \cdot 10^{+77}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -1.3265302524848746 \cdot 10^{-94}:\\
\;\;\;\;\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 4.26375791351412 \cdot 10^{-167}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 0.00715413837609351:\\
\;\;\;\;\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 5.368248308510426 \cdot 10^{+49}:\\
\;\;\;\;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.1778217648239176e+77)
   -1.0
   (if (<= y -1.3265302524848746e-94)
     (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
     (if (<= y 4.26375791351412e-167)
       1.0
       (if (<= y 0.00715413837609351)
         (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
         (if (<= y 5.368248308510426e+49) 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.1778217648239176e+77) {
		tmp = -1.0;
	} else if (y <= -1.3265302524848746e-94) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)));
	} else if (y <= 4.26375791351412e-167) {
		tmp = 1.0;
	} else if (y <= 0.00715413837609351) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)));
	} else if (y <= 5.368248308510426e+49) {
		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

Original32.0
Target31.7
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} < 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 y < -2.1778217648239176e77 or 5.36824830851042616e49 < y

    1. Initial program 46.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 0 12.9

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

    if -2.1778217648239176e77 < y < -1.3265302524848746e-94 or 4.26375791351411973e-167 < y < 0.0071541383760935096

    1. Initial program 16.4

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

    if -1.3265302524848746e-94 < y < 4.26375791351411973e-167 or 0.0071541383760935096 < y < 5.36824830851042616e49

    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 12.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.1778217648239176 \cdot 10^{+77}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.3265302524848746 \cdot 10^{-94}:\\ \;\;\;\;\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 4.26375791351412 \cdot 10^{-167}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 0.00715413837609351:\\ \;\;\;\;\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 5.368248308510426 \cdot 10^{+49}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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