Average Error: 31.4 → 11.8
Time: 4.5s
Precision: 64
\[\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}\;\left(y \cdot 4\right) \cdot y \le 5.78219856375817544 \cdot 10^{-301}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.58544396808553 \cdot 10^{-219}:\\ \;\;\;\;\frac{x + \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \frac{x - \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.94728338656335405 \cdot 10^{-137}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.8120705214528157 \cdot 10^{295}:\\ \;\;\;\;\frac{x + \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \frac{x - \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{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}\;\left(y \cdot 4\right) \cdot y \le 5.78219856375817544 \cdot 10^{-301}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.58544396808553 \cdot 10^{-219}:\\
\;\;\;\;\frac{x + \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \frac{x - \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.94728338656335405 \cdot 10^{-137}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.8120705214528157 \cdot 10^{295}:\\
\;\;\;\;\frac{x + \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \frac{x - \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{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) (((double) (y * 4.0)) * y)) <= 5.7821985637581754e-301)) {
		VAR = 1.0;
	} else {
		double VAR_1;
		if ((((double) (((double) (y * 4.0)) * y)) <= 1.5854439680855296e-219)) {
			VAR_1 = ((double) (((double) (((double) (x + ((double) sqrt(((double) (((double) (y * 4.0)) * y)))))) / ((double) sqrt(((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y)))))))) * ((double) (((double) (x - ((double) sqrt(((double) (((double) (y * 4.0)) * y)))))) / ((double) sqrt(((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))))))));
		} else {
			double VAR_2;
			if ((((double) (((double) (y * 4.0)) * y)) <= 2.947283386563354e-137)) {
				VAR_2 = 1.0;
			} else {
				double VAR_3;
				if ((((double) (((double) (y * 4.0)) * y)) <= 1.8120705214528157e+295)) {
					VAR_3 = ((double) (((double) (((double) (x + ((double) sqrt(((double) (((double) (y * 4.0)) * y)))))) / ((double) sqrt(((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y)))))))) * ((double) (((double) (x - ((double) sqrt(((double) (((double) (y * 4.0)) * y)))))) / ((double) sqrt(((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y))))))))));
				} 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.4
Target31.0
Herbie11.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} \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 (* (* y 4.0) y) < 5.7821985637581754e-301 or 1.5854439680855296e-219 < (* (* y 4.0) y) < 2.947283386563354e-137

    1. Initial program 26.8

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

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

    if 5.7821985637581754e-301 < (* (* y 4.0) y) < 1.5854439680855296e-219 or 2.947283386563354e-137 < (* (* y 4.0) y) < 1.8120705214528157e+295

    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-sqr-sqrt15.5

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\]
    4. Applied add-sqr-sqrt15.5

      \[\leadsto \frac{x \cdot x - \color{blue}{\sqrt{\left(y \cdot 4\right) \cdot y} \cdot \sqrt{\left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]
    5. Applied difference-of-squares15.5

      \[\leadsto \frac{\color{blue}{\left(x + \sqrt{\left(y \cdot 4\right) \cdot y}\right) \cdot \left(x - \sqrt{\left(y \cdot 4\right) \cdot y}\right)}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]
    6. Applied times-frac15.0

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

    if 1.8120705214528157e+295 < (* (* y 4.0) y)

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 5.78219856375817544 \cdot 10^{-301}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.58544396808553 \cdot 10^{-219}:\\ \;\;\;\;\frac{x + \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \frac{x - \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.94728338656335405 \cdot 10^{-137}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.8120705214528157 \cdot 10^{295}:\\ \;\;\;\;\frac{x + \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \frac{x - \sqrt{\left(y \cdot 4\right) \cdot y}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2020114 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4))) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4)))) 2) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))))

  (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))))