Average Error: 31.5 → 14.8
Time: 1.8s
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}\;x \le -5.20849409813975316 \cdot 10^{71}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.7815539218516901 \cdot 10^{-69}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -2.15173739486952312 \cdot 10^{-132}:\\ \;\;\;\;\frac{\frac{1}{x \cdot x + \left(y \cdot 4\right) \cdot y}}{\frac{1}{x \cdot x - \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 9.91379596263745997 \cdot 10^{-132}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.87803095035586109 \cdot 10^{-18}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 0.362998339815672477:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 5.3293509688902746 \cdot 10^{81}:\\ \;\;\;\;\frac{1}{\frac{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 \le -5.20849409813975316 \cdot 10^{71}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -1.7815539218516901 \cdot 10^{-69}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \le 9.91379596263745997 \cdot 10^{-132}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \le 0.362998339815672477:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 5.3293509688902746 \cdot 10^{81}:\\
\;\;\;\;\frac{1}{\frac{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 ((x <= -5.208494098139753e+71)) {
		VAR = 1.0;
	} else {
		double VAR_1;
		if ((x <= -1.7815539218516901e-69)) {
			VAR_1 = -1.0;
		} else {
			double VAR_2;
			if ((x <= -2.151737394869523e-132)) {
				VAR_2 = ((double) (((double) (1.0 / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y)))))) / ((double) (1.0 / ((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y))))))));
			} else {
				double VAR_3;
				if ((x <= 9.91379596263746e-132)) {
					VAR_3 = -1.0;
				} else {
					double VAR_4;
					if ((x <= 2.878030950355861e-18)) {
						VAR_4 = ((double) (1.0 / ((double) (((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y))))))));
					} else {
						double VAR_5;
						if ((x <= 0.3629983398156725)) {
							VAR_5 = -1.0;
						} else {
							double VAR_6;
							if ((x <= 5.329350968890275e+81)) {
								VAR_6 = ((double) (1.0 / ((double) (((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y))))))));
							} else {
								VAR_6 = 1.0;
							}
							VAR_5 = VAR_6;
						}
						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.5
Target31.2
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} \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 < -5.208494098139753e+71 or 5.329350968890275e+81 < x

    1. Initial program 47.2

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

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

    if -5.208494098139753e+71 < x < -1.7815539218516901e-69 or -2.151737394869523e-132 < x < 9.91379596263746e-132 or 2.878030950355861e-18 < x < 0.3629983398156725

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

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

    if -1.7815539218516901e-69 < x < -2.151737394869523e-132

    1. Initial program 16.7

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

      \[\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. Using strategy rm
    5. Applied div-inv16.8

      \[\leadsto \frac{1}{\color{blue}{\left(x \cdot x + \left(y \cdot 4\right) \cdot y\right) \cdot \frac{1}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    6. Applied associate-/r*16.7

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

    if 9.91379596263746e-132 < x < 2.878030950355861e-18 or 0.3629983398156725 < x < 5.329350968890275e+81

    1. Initial program 15.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 clear-num15.8

      \[\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}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification14.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.20849409813975316 \cdot 10^{71}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.7815539218516901 \cdot 10^{-69}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -2.15173739486952312 \cdot 10^{-132}:\\ \;\;\;\;\frac{\frac{1}{x \cdot x + \left(y \cdot 4\right) \cdot y}}{\frac{1}{x \cdot x - \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 9.91379596263745997 \cdot 10^{-132}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.87803095035586109 \cdot 10^{-18}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 0.362998339815672477:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 5.3293509688902746 \cdot 10^{81}:\\ \;\;\;\;\frac{1}{\frac{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 2020122 
(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))))