Average Error: 31.7 → 12.8
Time: 2.4s
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 \leq 2.6519277267935953 \cdot 10^{-297}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 2.5604160700203113 \cdot 10^{-149}:\\ \;\;\;\;\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \frac{1}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 2.773273929418784 \cdot 10^{-69}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 2.5090772621844595 \cdot 10^{+260}:\\ \;\;\;\;\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \frac{1}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \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 \leq 2.6519277267935953 \cdot 10^{-297}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \leq 2.5604160700203113 \cdot 10^{-149}:\\
\;\;\;\;\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \frac{1}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\

\mathbf{elif}\;x \cdot x \leq 2.773273929418784 \cdot 10^{-69}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \leq 2.5090772621844595 \cdot 10^{+260}:\\
\;\;\;\;\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \frac{1}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\

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

\end{array}
double code(double x, double y) {
	return (((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)) <= 2.6519277267935953e-297)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if ((((double) (x * x)) <= 2.5604160700203113e-149)) {
			VAR_1 = ((double) (((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) * (1.0 / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0)))))))));
		} else {
			double VAR_2;
			if ((((double) (x * x)) <= 2.773273929418784e-69)) {
				VAR_2 = -1.0;
			} else {
				double VAR_3;
				if ((((double) (x * x)) <= 2.5090772621844595e+260)) {
					VAR_3 = ((double) (((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) * (1.0 / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0)))))))));
				} 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.7
Target31.3
Herbie12.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} < 0.9743233849626781:\\ \;\;\;\;\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) < 2.6519277267935953e-297 or 2.5604160700203113e-149 < (* x x) < 2.7732739294187841e-69

    1. Initial program 27.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 0 12.1

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

    if 2.6519277267935953e-297 < (* x x) < 2.5604160700203113e-149 or 2.7732739294187841e-69 < (* x x) < 2.5090772621844595e260

    1. Initial program 16.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 div-inv16.2

      \[\leadsto \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}}\]
    4. Simplified16.2

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

    if 2.5090772621844595e260 < (* x x)

    1. Initial program 57.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 inf 9.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2.6519277267935953 \cdot 10^{-297}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 2.5604160700203113 \cdot 10^{-149}:\\ \;\;\;\;\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \frac{1}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 2.773273929418784 \cdot 10^{-69}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 2.5090772621844595 \cdot 10^{+260}:\\ \;\;\;\;\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \frac{1}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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