Average Error: 32.0 → 14.8
Time: 1.8s
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 -1.1567941219743209 \cdot 10^{+146}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -2.1900985744224192 \cdot 10^{-33}:\\ \;\;\;\;\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)}^{3}}\\ \mathbf{elif}\;x \leq 7.37508648907558 \cdot 10^{-62}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 2.992724529533424 \cdot 10^{-09}:\\ \;\;\;\;\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)}^{3}}\\ \mathbf{elif}\;x \leq 2.248804362437393 \cdot 10^{+81}:\\ \;\;\;\;-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 -1.1567941219743209 \cdot 10^{+146}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq -2.1900985744224192 \cdot 10^{-33}:\\
\;\;\;\;\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)}^{3}}\\

\mathbf{elif}\;x \leq 7.37508648907558 \cdot 10^{-62}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \leq 2.992724529533424 \cdot 10^{-09}:\\
\;\;\;\;\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)}^{3}}\\

\mathbf{elif}\;x \leq 2.248804362437393 \cdot 10^{+81}:\\
\;\;\;\;-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 -1.1567941219743209e+146)
   1.0
   (if (<= x -2.1900985744224192e-33)
     (cbrt
      (pow (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0)))) 3.0))
     (if (<= x 7.37508648907558e-62)
       -1.0
       (if (<= x 2.992724529533424e-09)
         (cbrt
          (pow
           (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
           3.0))
         (if (<= x 2.248804362437393e+81) -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 <= -1.1567941219743209e+146)) {
		tmp = 1.0;
	} else {
		double tmp_1;
		if ((x <= -2.1900985744224192e-33)) {
			tmp_1 = ((double) cbrt(((double) pow((((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))), 3.0))));
		} else {
			double tmp_2;
			if ((x <= 7.37508648907558e-62)) {
				tmp_2 = -1.0;
			} else {
				double tmp_3;
				if ((x <= 2.992724529533424e-09)) {
					tmp_3 = ((double) cbrt(((double) pow((((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))), 3.0))));
				} else {
					double tmp_4;
					if ((x <= 2.248804362437393e+81)) {
						tmp_4 = -1.0;
					} else {
						tmp_4 = 1.0;
					}
					tmp_3 = tmp_4;
				}
				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

Original32.0
Target31.7
Herbie14.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 3 regimes
  2. if x < -1.1567941219743209e146 or 2.24880436243739286e81 < x

    1. Initial program 54.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 inf 10.7

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

    if -1.1567941219743209e146 < x < -2.1900985744224192e-33 or 7.3750864890755804e-62 < x < 2.9927245295334239e-9

    1. Initial program 16.8

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

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

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

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

      \[\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}}}\]

    if -2.1900985744224192e-33 < x < 7.3750864890755804e-62 or 2.9927245295334239e-9 < x < 2.24880436243739286e81

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

      \[\leadsto \color{blue}{-1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.1567941219743209 \cdot 10^{+146}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -2.1900985744224192 \cdot 10^{-33}:\\ \;\;\;\;\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)}^{3}}\\ \mathbf{elif}\;x \leq 7.37508648907558 \cdot 10^{-62}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 2.992724529533424 \cdot 10^{-09}:\\ \;\;\;\;\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)}^{3}}\\ \mathbf{elif}\;x \leq 2.248804362437393 \cdot 10^{+81}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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