Average Error: 31.9 → 14.2
Time: 1.7s
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}\;y \le -8.2639569030933339 \cdot 10^{142}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.68665577088671205 \cdot 10^{-83}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 1.7369511562531757 \cdot 10^{-112}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 5.75963449839209801 \cdot 10^{-24}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 5.42037427797573429 \cdot 10^{30}:\\ \;\;\;\;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}\;y \le -8.2639569030933339 \cdot 10^{142}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -4.68665577088671205 \cdot 10^{-83}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;y \le 1.7369511562531757 \cdot 10^{-112}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 5.75963449839209801 \cdot 10^{-24}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;y \le 5.42037427797573429 \cdot 10^{30}:\\
\;\;\;\;1\\

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

\end{array}
double code(double x, double y) {
	return (((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)));
}
double code(double x, double y) {
	double VAR;
	if ((y <= -8.263956903093334e+142)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((y <= -4.686655770886712e-83)) {
			VAR_1 = (fma(x, x, -((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)));
		} else {
			double VAR_2;
			if ((y <= 1.7369511562531757e-112)) {
				VAR_2 = 1.0;
			} else {
				double VAR_3;
				if ((y <= 5.759634498392098e-24)) {
					VAR_3 = (fma(x, x, -((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)));
				} else {
					double VAR_4;
					if ((y <= 5.420374277975734e+30)) {
						VAR_4 = 1.0;
					} else {
						VAR_4 = -1.0;
					}
					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.9
Target31.6
Herbie14.2
\[\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 < -8.263956903093334e+142 or 5.420374277975734e+30 < y

    1. Initial program 49.4

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

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

    if -8.263956903093334e+142 < y < -4.686655770886712e-83 or 1.7369511562531757e-112 < y < 5.759634498392098e-24

    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 fma-neg17.0

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

    if -4.686655770886712e-83 < y < 1.7369511562531757e-112 or 5.759634498392098e-24 < y < 5.420374277975734e+30

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -8.2639569030933339 \cdot 10^{142}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.68665577088671205 \cdot 10^{-83}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 1.7369511562531757 \cdot 10^{-112}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 5.75963449839209801 \cdot 10^{-24}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 5.42037427797573429 \cdot 10^{30}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2020102 +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))))