Average Error: 31.9 → 12.6
Time: 4.5s
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 \leq -6.782623048135753 \cdot 10^{+135}:\\ \;\;\;\;-1 + 0.5 \cdot \left(\left(\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}} \cdot \frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}}\right) \cdot \left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}} \cdot \frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right)\right)\\ \mathbf{elif}\;y \leq -2.0471170134376602 \cdot 10^{-106}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x + \left(y \cdot y\right) \cdot -4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\right)}^{3}}\\ \mathbf{elif}\;y \leq 1.5065991278181313 \cdot 10^{-140}:\\ \;\;\;\;\sqrt[3]{1}\\ \mathbf{elif}\;y \leq 7.090214672623547 \cdot 10^{+79}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)} \cdot \left(\sqrt[3]{-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)} \cdot \sqrt[3]{-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)}\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 \leq -6.782623048135753 \cdot 10^{+135}:\\
\;\;\;\;-1 + 0.5 \cdot \left(\left(\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}} \cdot \frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}}\right) \cdot \left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}} \cdot \frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right)\right)\\

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

\mathbf{elif}\;y \leq 1.5065991278181313 \cdot 10^{-140}:\\
\;\;\;\;\sqrt[3]{1}\\

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

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)} \cdot \left(\sqrt[3]{-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)} \cdot \sqrt[3]{-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)}\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 -6.782623048135753e+135)
   (+
    -1.0
    (*
     0.5
     (*
      (*
       (/ (* (cbrt x) (cbrt x)) (* (cbrt y) (cbrt y)))
       (/ (* (cbrt x) (cbrt x)) (* (cbrt y) (cbrt y))))
      (* (/ (cbrt x) (cbrt y)) (/ (cbrt x) (cbrt y))))))
   (if (<= y -2.0471170134376602e-106)
     (cbrt
      (pow (/ (+ (* x x) (* (* y y) -4.0)) (+ (* x x) (* (* y y) 4.0))) 3.0))
     (if (<= y 1.5065991278181313e-140)
       (cbrt 1.0)
       (if (<= y 7.090214672623547e+79)
         (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
         (*
          (cbrt (+ -1.0 (* 0.5 (* (/ x y) (/ x y)))))
          (*
           (cbrt (+ -1.0 (* 0.5 (* (/ x y) (/ x y)))))
           (cbrt (+ -1.0 (* 0.5 (* (/ x y) (/ x y))))))))))))
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 <= -6.782623048135753e+135) {
		tmp = -1.0 + (0.5 * ((((cbrt(x) * cbrt(x)) / (cbrt(y) * cbrt(y))) * ((cbrt(x) * cbrt(x)) / (cbrt(y) * cbrt(y)))) * ((cbrt(x) / cbrt(y)) * (cbrt(x) / cbrt(y)))));
	} else if (y <= -2.0471170134376602e-106) {
		tmp = cbrt(pow((((x * x) + ((y * y) * -4.0)) / ((x * x) + ((y * y) * 4.0))), 3.0));
	} else if (y <= 1.5065991278181313e-140) {
		tmp = cbrt(1.0);
	} else if (y <= 7.090214672623547e+79) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)));
	} else {
		tmp = cbrt(-1.0 + (0.5 * ((x / y) * (x / y)))) * (cbrt(-1.0 + (0.5 * ((x / y) * (x / y)))) * cbrt(-1.0 + (0.5 * ((x / y) * (x / y)))));
	}
	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
Herbie12.6
\[\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 y < -6.78262304813575286e135

    1. Initial program 59.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 16.9

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

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

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

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

      \[\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_binary648.9

      \[\leadsto -1 + 0.5 \cdot \left(\left|\frac{x}{y}\right| \cdot \left|\frac{x}{\color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{y}}}\right|\right)\]
    10. Applied add-cube-cbrt_binary648.9

      \[\leadsto -1 + 0.5 \cdot \left(\left|\frac{x}{y}\right| \cdot \left|\frac{\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}}}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{y}}\right|\right)\]
    11. Applied times-frac_binary648.9

      \[\leadsto -1 + 0.5 \cdot \left(\left|\frac{x}{y}\right| \cdot \left|\color{blue}{\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}} \cdot \frac{\sqrt[3]{x}}{\sqrt[3]{y}}}\right|\right)\]
    12. Applied fabs-mul_binary648.9

      \[\leadsto -1 + 0.5 \cdot \left(\left|\frac{x}{y}\right| \cdot \color{blue}{\left(\left|\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}}\right| \cdot \left|\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right|\right)}\right)\]
    13. Applied add-cube-cbrt_binary648.9

      \[\leadsto -1 + 0.5 \cdot \left(\left|\frac{x}{\color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{y}}}\right| \cdot \left(\left|\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}}\right| \cdot \left|\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right|\right)\right)\]
    14. Applied add-cube-cbrt_binary648.9

      \[\leadsto -1 + 0.5 \cdot \left(\left|\frac{\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}}}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{y}}\right| \cdot \left(\left|\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}}\right| \cdot \left|\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right|\right)\right)\]
    15. Applied times-frac_binary648.9

      \[\leadsto -1 + 0.5 \cdot \left(\left|\color{blue}{\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}} \cdot \frac{\sqrt[3]{x}}{\sqrt[3]{y}}}\right| \cdot \left(\left|\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}}\right| \cdot \left|\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right|\right)\right)\]
    16. Applied fabs-mul_binary648.9

      \[\leadsto -1 + 0.5 \cdot \left(\color{blue}{\left(\left|\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}}\right| \cdot \left|\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right|\right)} \cdot \left(\left|\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}}\right| \cdot \left|\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right|\right)\right)\]
    17. Applied swap-sqr_binary648.9

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

    if -6.78262304813575286e135 < y < -2.04711701343766017e-106

    1. Initial program 16.7

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

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

      \[\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.04711701343766017e-106 < y < 1.50659912781813125e-140

    1. Initial program 27.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_binary6427.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. Simplified27.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}}}\]
    5. Taylor expanded around inf 9.5

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

    if 1.50659912781813125e-140 < y < 7.0902146726235471e79

    1. Initial program 16.7

      \[\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 +-commutative_binary6416.7

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

    if 7.0902146726235471e79 < 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 17.5

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

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

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

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

      \[\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_binary6411.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -6.782623048135753 \cdot 10^{+135}:\\ \;\;\;\;-1 + 0.5 \cdot \left(\left(\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}} \cdot \frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\sqrt[3]{y} \cdot \sqrt[3]{y}}\right) \cdot \left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}} \cdot \frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right)\right)\\ \mathbf{elif}\;y \leq -2.0471170134376602 \cdot 10^{-106}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x + \left(y \cdot y\right) \cdot -4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\right)}^{3}}\\ \mathbf{elif}\;y \leq 1.5065991278181313 \cdot 10^{-140}:\\ \;\;\;\;\sqrt[3]{1}\\ \mathbf{elif}\;y \leq 7.090214672623547 \cdot 10^{+79}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)} \cdot \left(\sqrt[3]{-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)} \cdot \sqrt[3]{-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)}\right)\\ \end{array}\]

Reproduce

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