Average Error: 31.5 → 17.4
Time: 2.0s
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 -5.228661566863015 \cdot 10^{+31}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 7.964892245268501 \cdot 10^{-88}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 4.713220725682607 \cdot 10^{-78}:\\ \;\;\;\;\sqrt[3]{{\left({\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right)}\right)}^{\left(\sqrt[3]{3}\right)}}\\ \mathbf{elif}\;x \leq 4.8131270733924935 \cdot 10^{+94}:\\ \;\;\;\;-1\\ \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 -5.228661566863015 \cdot 10^{+31}:\\
\;\;\;\;1\\

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

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

\mathbf{elif}\;x \leq 4.8131270733924935 \cdot 10^{+94}:\\
\;\;\;\;-1\\

\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 -5.228661566863015e+31)
   1.0
   (if (<= x 7.964892245268501e-88)
     -1.0
     (if (<= x 4.713220725682607e-78)
       (cbrt
        (pow
         (pow
          (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
          (* (cbrt 3.0) (cbrt 3.0)))
         (cbrt 3.0)))
       (if (<= x 4.8131270733924935e+94) -1.0 1.0)))))
double code(double x, double y) {
	return (((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y)))));
}
double code(double x, double y) {
	double tmp;
	if ((x <= -5.228661566863015e+31)) {
		tmp = 1.0;
	} else {
		double tmp_1;
		if ((x <= 7.964892245268501e-88)) {
			tmp_1 = -1.0;
		} else {
			double tmp_2;
			if ((x <= 4.713220725682607e-78)) {
				tmp_2 = ((double) cbrt(((double) pow(((double) pow((((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))), ((double) (((double) cbrt(3.0)) * ((double) cbrt(3.0)))))), ((double) cbrt(3.0))))));
			} else {
				double tmp_3;
				if ((x <= 4.8131270733924935e+94)) {
					tmp_3 = -1.0;
				} else {
					tmp_3 = 1.0;
				}
				tmp_2 = tmp_3;
			}
			tmp_1 = tmp_2;
		}
		tmp = tmp_1;
	}
	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.5
Target31.2
Herbie17.4
\[\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 x < -5.22866156686301529e31 or 4.81312707339249346e94 < x

    1. Initial program Error: 46.5 bits

      \[\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 Error: 13.0 bits

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

    if -5.22866156686301529e31 < x < 7.9648922452685006e-88 or 4.7132207256826072e-78 < x < 4.81312707339249346e94

    1. Initial program Error: 21.9 bits

      \[\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 Error: 20.0 bits

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

    if 7.9648922452685006e-88 < x < 4.7132207256826072e-78

    1. Initial program Error: 7.2 bits

      \[\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-cubeError: 53.1 bits

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\sqrt[3]{\left(\left(x \cdot x + \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}}}\]
    4. Applied add-cbrt-cubeError: 53.3 bits

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(x \cdot x - \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)}}}{\sqrt[3]{\left(\left(x \cdot x + \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}}\]
    5. Applied cbrt-undivError: 53.3 bits

      \[\leadsto \color{blue}{\sqrt[3]{\frac{\left(\left(x \cdot x - \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)}{\left(\left(x \cdot x + \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}}}\]
    6. SimplifiedError: 7.2 bits

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{3}}}\]
    7. Using strategy rm
    8. Applied add-cube-cbrtError: 7.2 bits

      \[\leadsto \sqrt[3]{{\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{\color{blue}{\left(\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}\right)}}}\]
    9. Applied pow-unpowError: 40.3 bits

      \[\leadsto \sqrt[3]{\color{blue}{{\left({\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right)}\right)}^{\left(\sqrt[3]{3}\right)}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplificationError: 17.4 bits

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.228661566863015 \cdot 10^{+31}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 7.964892245268501 \cdot 10^{-88}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 4.713220725682607 \cdot 10^{-78}:\\ \;\;\;\;\sqrt[3]{{\left({\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right)}\right)}^{\left(\sqrt[3]{3}\right)}}\\ \mathbf{elif}\;x \leq 4.8131270733924935 \cdot 10^{+94}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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