Average Error: 31.0 → 13.7
Time: 1.9s
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 -2.554553604554076 \cdot 10^{+100}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -2.0055094058071508 \cdot 10^{-162}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 4.738501923569654 \cdot 10^{-141}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 4.6413923854819006 \cdot 10^{-60}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 8.442517610183642 \cdot 10^{-14}:\\ \;\;\;\;-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}\;x \leq -2.554553604554076 \cdot 10^{+100}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \leq 4.738501923569654 \cdot 10^{-141}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \leq 8.442517610183642 \cdot 10^{-14}:\\
\;\;\;\;-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 (<= x -2.554553604554076e+100)
   1.0
   (if (<= x -2.0055094058071508e-162)
     (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
     (if (<= x 4.738501923569654e-141)
       -1.0
       (if (<= x 4.6413923854819006e-60)
         (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
         (if (<= x 8.442517610183642e-14) -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 (x <= -2.554553604554076e+100) {
		tmp = 1.0;
	} else if (x <= -2.0055094058071508e-162) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)));
	} else if (x <= 4.738501923569654e-141) {
		tmp = -1.0;
	} else if (x <= 4.6413923854819006e-60) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)));
	} else if (x <= 8.442517610183642e-14) {
		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

Original31.0
Target30.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 x < -2.554553604554076e100 or 8.4425176101836424e-14 < x

    1. Initial program 44.0

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

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

    if -2.554553604554076e100 < x < -2.00550940580715082e-162 or 4.73850192356965429e-141 < x < 4.6413923854819006e-60

    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}\]

    if -2.00550940580715082e-162 < x < 4.73850192356965429e-141 or 4.6413923854819006e-60 < x < 8.4425176101836424e-14

    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 0 10.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.554553604554076 \cdot 10^{+100}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -2.0055094058071508 \cdot 10^{-162}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 4.738501923569654 \cdot 10^{-141}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 4.6413923854819006 \cdot 10^{-60}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 8.442517610183642 \cdot 10^{-14}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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