Average Error: 31.7 → 13.0
Time: 2.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 \le -4.69108546213632265 \cdot 10^{113}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -3.4109173717513567 \cdot 10^{-161}:\\ \;\;\;\;\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(\sqrt[3]{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}} \cdot \sqrt[3]{\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 \le 4030199.65490493784:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.4095657239434897 \cdot 10^{116}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\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 \le -4.69108546213632265 \cdot 10^{113}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -3.4109173717513567 \cdot 10^{-161}:\\
\;\;\;\;\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(\sqrt[3]{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}} \cdot \sqrt[3]{\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 \le 4030199.65490493784:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 4.4095657239434897 \cdot 10^{116}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}}\\

\mathbf{else}:\\
\;\;\;\;1\\

\end{array}
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 VAR;
	if ((x <= -4.6910854621363227e+113)) {
		VAR = 1.0;
	} else {
		double VAR_1;
		if ((x <= -3.4109173717513567e-161)) {
			VAR_1 = ((double) (((double) cbrt((((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))))) * ((double) (((double) cbrt((((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0))))))))) * ((double) cbrt((((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0)))))))))))));
		} else {
			double VAR_2;
			if ((x <= 4030199.654904938)) {
				VAR_2 = -1.0;
			} else {
				double VAR_3;
				if ((x <= 4.40956572394349e+116)) {
					VAR_3 = (1.0 / (((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0))))))));
				} else {
					VAR_3 = 1.0;
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

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.7
Target31.5
Herbie13.0
\[\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} \lt 0.974323384962678118:\\ \;\;\;\;\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 4 regimes
  2. if x < -4.69108546213632265e113 or 4.4095657239434897e116 < x

    1. Initial program 54.9

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

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

    if -4.69108546213632265e113 < x < -3.4109173717513567e-161

    1. Initial program 15.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-cube-cbrt15.5

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

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

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

    if -3.4109173717513567e-161 < x < 4030199.65490493784

    1. Initial program 25.5

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

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

    if 4030199.65490493784 < x < 4.4095657239434897e116

    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-num17.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 + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification13.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.69108546213632265 \cdot 10^{113}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -3.4109173717513567 \cdot 10^{-161}:\\ \;\;\;\;\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(\sqrt[3]{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}} \cdot \sqrt[3]{\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 \le 4030199.65490493784:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.4095657239434897 \cdot 10^{116}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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