Average Error: 31.9 → 14.0
Time: 2.0s
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 -3.00186750331876538 \cdot 10^{143}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -6.5918067244508319 \cdot 10^{-138}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 1.9631464787281808 \cdot 10^{68}:\\ \;\;\;\;-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}\;x \le -3.00186750331876538 \cdot 10^{143}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -6.5918067244508319 \cdot 10^{-138}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\

\mathbf{elif}\;x \le 1.9631464787281808 \cdot 10^{68}:\\
\;\;\;\;-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 temp;
	if ((x <= -3.0018675033187654e+143)) {
		temp = 1.0;
	} else {
		double temp_1;
		if ((x <= -6.591806724450832e-138)) {
			temp_1 = expm1(log1p((((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)))));
		} else {
			double temp_2;
			if ((x <= 1.9631464787281808e+68)) {
				temp_2 = -1.0;
			} else {
				temp_2 = 1.0;
			}
			temp_1 = temp_2;
		}
		temp = temp_1;
	}
	return temp;
}

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.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 3 regimes
  2. if x < -3.0018675033187654e+143 or 1.9631464787281808e+68 < x

    1. Initial program 53.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 11.5

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

    if -3.0018675033187654e+143 < x < -6.591806724450832e-138

    1. Initial program 14.1

      \[\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 expm1-log1p-u14.1

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

    if -6.591806724450832e-138 < x < 1.9631464787281808e+68

    1. Initial program 24.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.00186750331876538 \cdot 10^{143}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -6.5918067244508319 \cdot 10^{-138}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 1.9631464787281808 \cdot 10^{68}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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