Average Error: 31.7 → 13.0
Time: 1.2s
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 \cdot x \leq 2.9058704324939004 \cdot 10^{-107}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 2.810919228514906 \cdot 10^{-40}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 6.117254844660804 \cdot 10^{-16}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 1.2586926368521745 \cdot 10^{+237}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \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 \cdot x \leq 2.9058704324939004 \cdot 10^{-107}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \cdot x \leq 6.117254844660804 \cdot 10^{-16}:\\
\;\;\;\;-1\\

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

\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 x) 2.9058704324939004e-107)
   -1.0
   (if (<= (* x x) 2.810919228514906e-40)
     (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
     (if (<= (* x x) 6.117254844660804e-16)
       -1.0
       (if (<= (* x x) 1.2586926368521745e+237)
         (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.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 * x) <= 2.9058704324939004e-107) {
		tmp = -1.0;
	} else if ((x * x) <= 2.810919228514906e-40) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)));
	} else if ((x * x) <= 6.117254844660804e-16) {
		tmp = -1.0;
	} else if ((x * x) <= 1.2586926368521745e+237) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.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.7
Target31.4
Herbie13.0
\[\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 (*.f64 x x) < 2.90587043249390037e-107 or 2.81091922851490614e-40 < (*.f64 x x) < 6.1172548446608041e-16

    1. Initial program 24.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 0 13.7

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

    if 2.90587043249390037e-107 < (*.f64 x x) < 2.81091922851490614e-40 or 6.1172548446608041e-16 < (*.f64 x x) < 1.2586926368521745e237

    1. Initial program 16.2

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

    if 1.2586926368521745e237 < (*.f64 x x)

    1. Initial program 54.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 9.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2.9058704324939004 \cdot 10^{-107}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 2.810919228514906 \cdot 10^{-40}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 6.117254844660804 \cdot 10^{-16}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 1.2586926368521745 \cdot 10^{+237}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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