Average Error: 31.7 → 14.7
Time: 2.1s
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 \cdot x \le 4.9967782475553325 \cdot 10^{-286}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 6.5044111571989142 \cdot 10^{-147}:\\ \;\;\;\;\left(\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y} \cdot \sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}\right) \cdot \frac{\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 4.9446452383030628 \cdot 10^{-59}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 46.7132961700270997:\\ \;\;\;\;\left(\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y} \cdot \sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}\right) \cdot \frac{\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 1.05434436441613764 \cdot 10^{91}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 4.53860330471986415 \cdot 10^{263}:\\ \;\;\;\;\left(\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y} \cdot \sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}\right) \cdot \frac{\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \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 \cdot x \le 4.9967782475553325 \cdot 10^{-286}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \cdot x \le 4.9446452383030628 \cdot 10^{-59}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 46.7132961700270997:\\
\;\;\;\;\left(\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y} \cdot \sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}\right) \cdot \frac{\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;x \cdot x \le 1.05434436441613764 \cdot 10^{91}:\\
\;\;\;\;-1\\

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

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

\end{array}
double code(double x, double y) {
	return ((double) (((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 ((((double) (x * x)) <= 4.9967782475553325e-286)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((((double) (x * x)) <= 6.504411157198914e-147)) {
			VAR_1 = ((double) (((double) (((double) cbrt(((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))))) * ((double) cbrt(((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))))))) * ((double) (((double) cbrt(((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))))));
		} else {
			double VAR_2;
			if ((((double) (x * x)) <= 4.944645238303063e-59)) {
				VAR_2 = -1.0;
			} else {
				double VAR_3;
				if ((((double) (x * x)) <= 46.7132961700271)) {
					VAR_3 = ((double) (((double) (((double) cbrt(((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))))) * ((double) cbrt(((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))))))) * ((double) (((double) cbrt(((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))))));
				} else {
					double VAR_4;
					if ((((double) (x * x)) <= 1.0543443644161376e+91)) {
						VAR_4 = -1.0;
					} else {
						double VAR_5;
						if ((((double) (x * x)) <= 4.538603304719864e+263)) {
							VAR_5 = ((double) (((double) (((double) cbrt(((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))))) * ((double) cbrt(((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))))))) * ((double) (((double) cbrt(((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))))));
						} else {
							VAR_5 = 1.0;
						}
						VAR_4 = VAR_5;
					}
					VAR_3 = VAR_4;
				}
				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.4
Herbie14.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} \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 3 regimes
  2. if (* x x) < 4.9967782475553325e-286 or 6.5044111571989142e-147 < (* x x) < 4.9446452383030628e-59 or 46.7132961700270997 < (* x x) < 1.05434436441613764e91

    1. Initial program 24.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 0 15.9

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

    if 4.9967782475553325e-286 < (* x x) < 6.5044111571989142e-147 or 4.9446452383030628e-59 < (* x x) < 46.7132961700270997 or 1.05434436441613764e91 < (* x x) < 4.53860330471986415e263

    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 *-un-lft-identity16.8

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{1 \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}}\]
    4. Applied add-cube-cbrt17.8

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y} \cdot \sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}\right) \cdot \sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}}}{1 \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}\]
    5. Applied times-frac17.8

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

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

    if 4.53860330471986415e263 < (* x x)

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 4.9967782475553325 \cdot 10^{-286}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 6.5044111571989142 \cdot 10^{-147}:\\ \;\;\;\;\left(\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y} \cdot \sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}\right) \cdot \frac{\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 4.9446452383030628 \cdot 10^{-59}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 46.7132961700270997:\\ \;\;\;\;\left(\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y} \cdot \sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}\right) \cdot \frac{\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 1.05434436441613764 \cdot 10^{91}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 4.53860330471986415 \cdot 10^{263}:\\ \;\;\;\;\left(\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y} \cdot \sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}\right) \cdot \frac{\sqrt[3]{x \cdot x - \left(y \cdot 4\right) \cdot y}}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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