Average Error: 31.9 → 13.2
Time: 4.3s
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 -3.995380480633996 \cdot 10^{+123}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.2067715500681638 \cdot 10^{+88}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq -5.05065600910573 \cdot 10^{+15}:\\ \;\;\;\;\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 -13723700.876419608:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq -9.32126470587108 \cdot 10^{-56}:\\ \;\;\;\;\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 6.981857572502039 \cdot 10^{-117}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 2.9610168666493824 \cdot 10^{+147}:\\ \;\;\;\;\frac{1}{\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 \leq -3.995380480633996 \cdot 10^{+123}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq -1.2067715500681638 \cdot 10^{+88}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \leq -5.05065600910573 \cdot 10^{+15}:\\
\;\;\;\;\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 -13723700.876419608:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \leq -9.32126470587108 \cdot 10^{-56}:\\
\;\;\;\;\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 6.981857572502039 \cdot 10^{-117}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \leq 2.9610168666493824 \cdot 10^{+147}:\\
\;\;\;\;\frac{1}{\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 -3.995380480633996e+123)
   1.0
   (if (<= x -1.2067715500681638e+88)
     -1.0
     (if (<= x -5.05065600910573e+15)
       (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
       (if (<= x -13723700.876419608)
         -1.0
         (if (<= x -9.32126470587108e-56)
           (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
           (if (<= x 6.981857572502039e-117)
             -1.0
             (if (<= x 2.9610168666493824e+147)
               (/
                1.0
                (/ (+ (* 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 <= -3.995380480633996e+123) {
		tmp = 1.0;
	} else if (x <= -1.2067715500681638e+88) {
		tmp = -1.0;
	} else if (x <= -5.05065600910573e+15) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)));
	} else if (x <= -13723700.876419608) {
		tmp = -1.0;
	} else if (x <= -9.32126470587108e-56) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)));
	} else if (x <= 6.981857572502039e-117) {
		tmp = -1.0;
	} else if (x <= 2.9610168666493824e+147) {
		tmp = 1.0 / (((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.9
Target31.6
Herbie13.2
\[\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 x < -3.9953804806339959e123 or 2.96101686664938239e147 < x

    1. Initial program 58.9

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

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

    if -3.9953804806339959e123 < x < -1.20677155006816383e88 or -5050656009105730 < x < -13723700.876419608 or -9.3212647058710807e-56 < x < 6.98185757250203928e-117

    1. Initial program 25.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 14.1

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

    if -1.20677155006816383e88 < x < -5050656009105730 or -13723700.876419608 < x < -9.3212647058710807e-56

    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 6.98185757250203928e-117 < x < 2.96101686664938239e147

    1. Initial program 16.1

      \[\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 clear-num_binary64_1098916.1

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

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification13.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.995380480633996 \cdot 10^{+123}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.2067715500681638 \cdot 10^{+88}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq -5.05065600910573 \cdot 10^{+15}:\\ \;\;\;\;\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 -13723700.876419608:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq -9.32126470587108 \cdot 10^{-56}:\\ \;\;\;\;\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 6.981857572502039 \cdot 10^{-117}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 2.9610168666493824 \cdot 10^{+147}:\\ \;\;\;\;\frac{1}{\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 2020354 
(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))))