Average Error: 31.6 → 14.8
Time: 3.4s
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}\;\left(y \cdot 4\right) \cdot y \le 6.5681746261658627 \cdot 10^{-214}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 6.51230295658223255 \cdot 10^{-77}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.16324510776386085 \cdot 10^{31}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.7671028773181022 \cdot 10^{187}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.36943602155751907 \cdot 10^{227}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 9.4017814857528666 \cdot 10^{260}:\\ \;\;\;\;\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}\;\left(y \cdot 4\right) \cdot y \le 6.5681746261658627 \cdot 10^{-214}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.16324510776386085 \cdot 10^{31}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.36943602155751907 \cdot 10^{227}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 9.4017814857528666 \cdot 10^{260}:\\
\;\;\;\;\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 f(double x, double y) {
        double r674232 = x;
        double r674233 = r674232 * r674232;
        double r674234 = y;
        double r674235 = 4.0;
        double r674236 = r674234 * r674235;
        double r674237 = r674236 * r674234;
        double r674238 = r674233 - r674237;
        double r674239 = r674233 + r674237;
        double r674240 = r674238 / r674239;
        return r674240;
}

double f(double x, double y) {
        double r674241 = y;
        double r674242 = 4.0;
        double r674243 = r674241 * r674242;
        double r674244 = r674243 * r674241;
        double r674245 = 6.568174626165863e-214;
        bool r674246 = r674244 <= r674245;
        double r674247 = 1.0;
        double r674248 = 6.5123029565822326e-77;
        bool r674249 = r674244 <= r674248;
        double r674250 = x;
        double r674251 = r674250 * r674250;
        double r674252 = r674251 - r674244;
        double r674253 = r674251 + r674244;
        double r674254 = r674252 / r674253;
        double r674255 = 7.163245107763861e+31;
        bool r674256 = r674244 <= r674255;
        double r674257 = 1.7671028773181022e+187;
        bool r674258 = r674244 <= r674257;
        double r674259 = 2.369436021557519e+227;
        bool r674260 = r674244 <= r674259;
        double r674261 = 9.401781485752867e+260;
        bool r674262 = r674244 <= r674261;
        double r674263 = -1.0;
        double r674264 = r674262 ? r674254 : r674263;
        double r674265 = r674260 ? r674247 : r674264;
        double r674266 = r674258 ? r674254 : r674265;
        double r674267 = r674256 ? r674247 : r674266;
        double r674268 = r674249 ? r674254 : r674267;
        double r674269 = r674246 ? r674247 : r674268;
        return r674269;
}

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.6
Target31.3
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 3 regimes
  2. if (* (* y 4.0) y) < 6.568174626165863e-214 or 6.5123029565822326e-77 < (* (* y 4.0) y) < 7.163245107763861e+31 or 1.7671028773181022e+187 < (* (* y 4.0) y) < 2.369436021557519e+227

    1. Initial program 24.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 17.6

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

    if 6.568174626165863e-214 < (* (* y 4.0) y) < 6.5123029565822326e-77 or 7.163245107763861e+31 < (* (* y 4.0) y) < 1.7671028773181022e+187 or 2.369436021557519e+227 < (* (* y 4.0) y) < 9.401781485752867e+260

    1. Initial program 15.7

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

    if 9.401781485752867e+260 < (* (* y 4.0) y)

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 6.5681746261658627 \cdot 10^{-214}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 6.51230295658223255 \cdot 10^{-77}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.16324510776386085 \cdot 10^{31}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.7671028773181022 \cdot 10^{187}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.36943602155751907 \cdot 10^{227}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 9.4017814857528666 \cdot 10^{260}:\\ \;\;\;\;\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 2020024 +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))))