Average Error: 32.4 → 12.8
Time: 4.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 \leq -4.833721844680349 \cdot 10^{+87}:\\ \;\;\;\;1 - 8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\ \mathbf{elif}\;x \leq -1.6932163406705725 \cdot 10^{-159}:\\ \;\;\;\;\sqrt[3]{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}\\ \mathbf{elif}\;x \leq 7.088159935425954 \cdot 10^{-155}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 1.4090580343274923 \cdot 10^{+70}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + 4 \cdot \left(y \cdot y\right)}{x \cdot x + \left(y \cdot y\right) \cdot -4}}\\ \mathbf{elif}\;x \leq 2.8060004685656228 \cdot 10^{+85}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{{x}^{2}}{{y}^{2}}\\ \mathbf{elif}\;x \leq 5.71734574737866 \cdot 10^{+172} \lor \neg \left(x \leq 5.841742874771862 \cdot 10^{+172}\right):\\ \;\;\;\;1 - 8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\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 -4.833721844680349 \cdot 10^{+87}:\\
\;\;\;\;1 - 8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\

\mathbf{elif}\;x \leq -1.6932163406705725 \cdot 10^{-159}:\\
\;\;\;\;\sqrt[3]{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}\\

\mathbf{elif}\;x \leq 7.088159935425954 \cdot 10^{-155}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \leq 2.8060004685656228 \cdot 10^{+85}:\\
\;\;\;\;-1 + 0.5 \cdot \frac{{x}^{2}}{{y}^{2}}\\

\mathbf{elif}\;x \leq 5.71734574737866 \cdot 10^{+172} \lor \neg \left(x \leq 5.841742874771862 \cdot 10^{+172}\right):\\
\;\;\;\;1 - 8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\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 -4.833721844680349e+87)
   (- 1.0 (* 8.0 (* (/ y x) (/ y x))))
   (if (<= x -1.6932163406705725e-159)
     (cbrt
      (*
       (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
       (*
        (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
        (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0)))))))
     (if (<= x 7.088159935425954e-155)
       -1.0
       (if (<= x 1.4090580343274923e+70)
         (/ 1.0 (/ (+ (* x x) (* 4.0 (* y y))) (+ (* x x) (* (* y y) -4.0))))
         (if (<= x 2.8060004685656228e+85)
           (+ -1.0 (* 0.5 (/ (pow x 2.0) (pow y 2.0))))
           (if (or (<= x 5.71734574737866e+172)
                   (not (<= x 5.841742874771862e+172)))
             (- 1.0 (* 8.0 (* (/ y x) (/ y x))))
             -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 <= -4.833721844680349e+87) {
		tmp = 1.0 - (8.0 * ((y / x) * (y / x)));
	} else if (x <= -1.6932163406705725e-159) {
		tmp = cbrt((((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)))) * ((((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)))) * (((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0))))));
	} else if (x <= 7.088159935425954e-155) {
		tmp = -1.0;
	} else if (x <= 1.4090580343274923e+70) {
		tmp = 1.0 / (((x * x) + (4.0 * (y * y))) / ((x * x) + ((y * y) * -4.0)));
	} else if (x <= 2.8060004685656228e+85) {
		tmp = -1.0 + (0.5 * (pow(x, 2.0) / pow(y, 2.0)));
	} else if ((x <= 5.71734574737866e+172) || !(x <= 5.841742874771862e+172)) {
		tmp = 1.0 - (8.0 * ((y / x) * (y / x)));
	} 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.4
Target32.1
Herbie12.8
\[\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 5 regimes
  2. if x < -4.8337218446803486e87 or 2.8060004685656228e85 < x < 5.71734574737866021e172 or 5.8417428747718621e172 < x

    1. Initial program 49.8

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

      \[\leadsto \color{blue}{1 - 8 \cdot \frac{{y}^{2}}{{x}^{2}}}\]
    3. Simplified17.4

      \[\leadsto \color{blue}{1 - 8 \cdot \frac{y \cdot y}{x \cdot x}}\]
    4. Using strategy rm
    5. Applied times-frac_binary6410.9

      \[\leadsto 1 - 8 \cdot \color{blue}{\left(\frac{y}{x} \cdot \frac{y}{x}\right)}\]

    if -4.8337218446803486e87 < x < -1.6932163406705725e-159

    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}\]
    2. Using strategy rm
    3. Applied add-cbrt-cube_binary6416.4

      \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \cdot \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right) \cdot \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\]

    if -1.6932163406705725e-159 < x < 7.08815993542595428e-155 or 5.71734574737866021e172 < x < 5.8417428747718621e172

    1. Initial program 31.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 8.4

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

    if 7.08815993542595428e-155 < x < 1.4090580343274923e70

    1. Initial program 17.0

      \[\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_binary6417.0

      \[\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. Simplified17.0

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

    if 1.4090580343274923e70 < x < 2.8060004685656228e85

    1. Initial program 17.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 37.5

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification12.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.833721844680349 \cdot 10^{+87}:\\ \;\;\;\;1 - 8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\ \mathbf{elif}\;x \leq -1.6932163406705725 \cdot 10^{-159}:\\ \;\;\;\;\sqrt[3]{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}\\ \mathbf{elif}\;x \leq 7.088159935425954 \cdot 10^{-155}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 1.4090580343274923 \cdot 10^{+70}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + 4 \cdot \left(y \cdot y\right)}{x \cdot x + \left(y \cdot y\right) \cdot -4}}\\ \mathbf{elif}\;x \leq 2.8060004685656228 \cdot 10^{+85}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{{x}^{2}}{{y}^{2}}\\ \mathbf{elif}\;x \leq 5.71734574737866 \cdot 10^{+172} \lor \neg \left(x \leq 5.841742874771862 \cdot 10^{+172}\right):\\ \;\;\;\;1 - 8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Alternatives

Reproduce

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