Average Error: 31.9 → 15.3
Time: 1.9s
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}\;y \leq -3.127310730564356 \cdot 10^{+43}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 8.016764780682956 \cdot 10^{-128}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.797814197344609 \cdot 10^{-83}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - \frac{y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 15450054544.413227:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.8816810645316985 \cdot 10^{+90}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\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}\;y \leq -3.127310730564356 \cdot 10^{+43}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq 8.016764780682956 \cdot 10^{-128}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \leq 15450054544.413227:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 1.8816810645316985 \cdot 10^{+90}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\

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

\end{array}
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (if (<= y -3.127310730564356e+43)
   -1.0
   (if (<= y 8.016764780682956e-128)
     1.0
     (if (<= y 2.797814197344609e-83)
       (-
        (/ (* x x) (+ (* x x) (* y (* y 4.0))))
        (/ (* y (* y 4.0)) (+ (* x x) (* y (* y 4.0)))))
       (if (<= y 15450054544.413227)
         1.0
         (if (<= y 1.8816810645316985e+90)
           (log
            (exp (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))))
           -1.0))))))
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 tmp;
	if (y <= -3.127310730564356e+43) {
		tmp = -1.0;
	} else if (y <= 8.016764780682956e-128) {
		tmp = 1.0;
	} else if (y <= 2.797814197344609e-83) {
		tmp = ((x * x) / ((x * x) + (y * (y * 4.0)))) - ((y * (y * 4.0)) / ((x * x) + (y * (y * 4.0))));
	} else if (y <= 15450054544.413227) {
		tmp = 1.0;
	} else if (y <= 1.8816810645316985e+90) {
		tmp = log(exp(((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)))));
	} else {
		tmp = -1.0;
	}
	return tmp;
}

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
Herbie15.3
\[\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 4 regimes
  2. if y < -3.12731073056435602e43 or 1.88168106453169849e90 < y

    1. Initial program 46.9

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

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

    if -3.12731073056435602e43 < y < 8.0167647806829561e-128 or 2.797814197344609e-83 < y < 15450054544.413227

    1. Initial program 23.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 17.0

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

    if 8.0167647806829561e-128 < y < 2.797814197344609e-83

    1. Initial program 18.3

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

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

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot \left(y \cdot 4\right)}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    5. Simplified18.3

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

    if 15450054544.413227 < y < 1.88168106453169849e90

    1. Initial program 15.2

      \[\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-log-exp_binary64_1972615.3

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]
    4. Simplified15.3

      \[\leadsto \log \color{blue}{\left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification15.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.127310730564356 \cdot 10^{+43}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 8.016764780682956 \cdot 10^{-128}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.797814197344609 \cdot 10^{-83}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - \frac{y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 15450054544.413227:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.8816810645316985 \cdot 10^{+90}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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