Average Error: 31.6 → 12.7
Time: 6.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}\;y \cdot \left(y \cdot 4\right) \leq 9.8813129168249 \cdot 10^{-324}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 2.0305632361013187 \cdot 10^{-198}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x + \left(y \cdot y\right) \cdot -4}{x \cdot x + 4 \cdot \left(y \cdot y\right)}\right)}^{3}}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 6.818969806715923 \cdot 10^{-140}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 2.7140562314388115 \cdot 10^{-101}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x + \left(y \cdot y\right) \cdot -4}{x \cdot x + 4 \cdot \left(y \cdot y\right)}\right)}^{3}}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 5.385412758967982 \cdot 10^{-27}:\\ \;\;\;\;1 - 8 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 1.3525302745620225 \cdot 10^{+180}:\\ \;\;\;\;\frac{x \cdot x}{y \cdot \left(y \cdot 4\right) + x \cdot x} - \frac{y \cdot \left(y \cdot 4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1 + \sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5} \cdot \left(\sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5} \cdot \sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5}\right)\\ \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 \cdot \left(y \cdot 4\right) \leq 9.8813129168249 \cdot 10^{-324}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 6.818969806715923 \cdot 10^{-140}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 5.385412758967982 \cdot 10^{-27}:\\
\;\;\;\;1 - 8 \cdot \frac{y \cdot y}{x \cdot x}\\

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

\mathbf{else}:\\
\;\;\;\;-1 + \sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5} \cdot \left(\sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5} \cdot \sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5}\right)\\

\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 (* y 4.0)) 9.8813129168249e-324)
   1.0
   (if (<= (* y (* y 4.0)) 2.0305632361013187e-198)
     (cbrt
      (pow (/ (+ (* x x) (* (* y y) -4.0)) (+ (* x x) (* 4.0 (* y y)))) 3.0))
     (if (<= (* y (* y 4.0)) 6.818969806715923e-140)
       1.0
       (if (<= (* y (* y 4.0)) 2.7140562314388115e-101)
         (cbrt
          (pow
           (/ (+ (* x x) (* (* y y) -4.0)) (+ (* x x) (* 4.0 (* y y))))
           3.0))
         (if (<= (* y (* y 4.0)) 5.385412758967982e-27)
           (- 1.0 (* 8.0 (/ (* y y) (* x x))))
           (if (<= (* y (* y 4.0)) 1.3525302745620225e+180)
             (-
              (/ (* x x) (+ (* y (* y 4.0)) (* x x)))
              (/ (* y (* y 4.0)) (+ (* y (* y 4.0)) (* x x))))
             (+
              -1.0
              (*
               (cbrt (* (pow (fabs (/ x y)) 2.0) 0.5))
               (*
                (cbrt (* (pow (fabs (/ x y)) 2.0) 0.5))
                (cbrt (* (pow (fabs (/ x y)) 2.0) 0.5))))))))))))
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 * (y * 4.0)) <= 9.8813129168249e-324) {
		tmp = 1.0;
	} else if ((y * (y * 4.0)) <= 2.0305632361013187e-198) {
		tmp = cbrt(pow((((x * x) + ((y * y) * -4.0)) / ((x * x) + (4.0 * (y * y)))), 3.0));
	} else if ((y * (y * 4.0)) <= 6.818969806715923e-140) {
		tmp = 1.0;
	} else if ((y * (y * 4.0)) <= 2.7140562314388115e-101) {
		tmp = cbrt(pow((((x * x) + ((y * y) * -4.0)) / ((x * x) + (4.0 * (y * y)))), 3.0));
	} else if ((y * (y * 4.0)) <= 5.385412758967982e-27) {
		tmp = 1.0 - (8.0 * ((y * y) / (x * x)));
	} else if ((y * (y * 4.0)) <= 1.3525302745620225e+180) {
		tmp = ((x * x) / ((y * (y * 4.0)) + (x * x))) - ((y * (y * 4.0)) / ((y * (y * 4.0)) + (x * x)));
	} else {
		tmp = -1.0 + (cbrt(pow(fabs(x / y), 2.0) * 0.5) * (cbrt(pow(fabs(x / y), 2.0) * 0.5) * cbrt(pow(fabs(x / y), 2.0) * 0.5)));
	}
	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.6
Target31.3
Herbie12.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 5 regimes
  2. if (*.f64 (*.f64 y 4) y) < 9.88131e-324 or 2.0305632361013187e-198 < (*.f64 (*.f64 y 4) y) < 6.81896980671592274e-140

    1. Initial program 29.1

      \[\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.2

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

    if 9.88131e-324 < (*.f64 (*.f64 y 4) y) < 2.0305632361013187e-198 or 6.81896980671592274e-140 < (*.f64 (*.f64 y 4) y) < 2.7140562314388115e-101

    1. Initial program 16.5

      \[\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_binary64_1989216.5

      \[\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}}}\]
    4. Simplified16.5

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

    if 2.7140562314388115e-101 < (*.f64 (*.f64 y 4) y) < 5.38541275896798215e-27

    1. Initial program 17.4

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

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

      \[\leadsto \color{blue}{1 - 8 \cdot \frac{y \cdot y}{x \cdot x}}\]

    if 5.38541275896798215e-27 < (*.f64 (*.f64 y 4) y) < 1.3525302745620225e180

    1. Initial program 15.6

      \[\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 div-sub_binary64_1986115.6

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

    if 1.3525302745620225e180 < (*.f64 (*.f64 y 4) y)

    1. Initial program 49.4

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1}\]
    3. Simplified16.0

      \[\leadsto \color{blue}{-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt_binary64_1987816.0

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

      \[\leadsto -1 + 0.5 \cdot \left(\color{blue}{\left|\frac{x}{y}\right|} \cdot \sqrt{\frac{x \cdot x}{y \cdot y}}\right)\]
    7. Simplified10.5

      \[\leadsto -1 + 0.5 \cdot \left(\left|\frac{x}{y}\right| \cdot \color{blue}{\left|\frac{x}{y}\right|}\right)\]
    8. Using strategy rm
    9. Applied add-cube-cbrt_binary64_1989110.5

      \[\leadsto -1 + \color{blue}{\left(\sqrt[3]{0.5 \cdot \left(\left|\frac{x}{y}\right| \cdot \left|\frac{x}{y}\right|\right)} \cdot \sqrt[3]{0.5 \cdot \left(\left|\frac{x}{y}\right| \cdot \left|\frac{x}{y}\right|\right)}\right) \cdot \sqrt[3]{0.5 \cdot \left(\left|\frac{x}{y}\right| \cdot \left|\frac{x}{y}\right|\right)}}\]
    10. Simplified10.5

      \[\leadsto -1 + \color{blue}{\left(\sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5} \cdot \sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5}\right)} \cdot \sqrt[3]{0.5 \cdot \left(\left|\frac{x}{y}\right| \cdot \left|\frac{x}{y}\right|\right)}\]
    11. Simplified10.5

      \[\leadsto -1 + \left(\sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5} \cdot \sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5}\right) \cdot \color{blue}{\sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5}}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification12.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 9.8813129168249 \cdot 10^{-324}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 2.0305632361013187 \cdot 10^{-198}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x + \left(y \cdot y\right) \cdot -4}{x \cdot x + 4 \cdot \left(y \cdot y\right)}\right)}^{3}}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 6.818969806715923 \cdot 10^{-140}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 2.7140562314388115 \cdot 10^{-101}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x + \left(y \cdot y\right) \cdot -4}{x \cdot x + 4 \cdot \left(y \cdot y\right)}\right)}^{3}}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 5.385412758967982 \cdot 10^{-27}:\\ \;\;\;\;1 - 8 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 1.3525302745620225 \cdot 10^{+180}:\\ \;\;\;\;\frac{x \cdot x}{y \cdot \left(y \cdot 4\right) + x \cdot x} - \frac{y \cdot \left(y \cdot 4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1 + \sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5} \cdot \left(\sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5} \cdot \sqrt[3]{{\left(\left|\frac{x}{y}\right|\right)}^{2} \cdot 0.5}\right)\\ \end{array}\]

Reproduce

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