Average Error: 31.5 → 12.9
Time: 4.9s
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 4.94066 \cdot 10^{-324}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.6510033806694153 \cdot 10^{-246}:\\ \;\;\;\;\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)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.00910593225652596 \cdot 10^{-105}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.23283737728315802 \cdot 10^{293}:\\ \;\;\;\;\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)\\ \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 4.94066 \cdot 10^{-324}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.6510033806694153 \cdot 10^{-246}:\\
\;\;\;\;\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)\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.00910593225652596 \cdot 10^{-105}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.23283737728315802 \cdot 10^{293}:\\
\;\;\;\;\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)\\

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

\end{array}
double f(double x, double y) {
        double r360252 = x;
        double r360253 = r360252 * r360252;
        double r360254 = y;
        double r360255 = 4.0;
        double r360256 = r360254 * r360255;
        double r360257 = r360256 * r360254;
        double r360258 = r360253 - r360257;
        double r360259 = r360253 + r360257;
        double r360260 = r360258 / r360259;
        return r360260;
}

double f(double x, double y) {
        double r360261 = y;
        double r360262 = 4.0;
        double r360263 = r360261 * r360262;
        double r360264 = r360263 * r360261;
        double r360265 = 4.9406564584125e-324;
        bool r360266 = r360264 <= r360265;
        double r360267 = 1.0;
        double r360268 = 2.6510033806694153e-246;
        bool r360269 = r360264 <= r360268;
        double r360270 = x;
        double r360271 = r360270 * r360270;
        double r360272 = r360271 - r360264;
        double r360273 = r360271 + r360264;
        double r360274 = r360272 / r360273;
        double r360275 = exp(r360274);
        double r360276 = log(r360275);
        double r360277 = 2.009105932256526e-105;
        bool r360278 = r360264 <= r360277;
        double r360279 = 2.232837377283158e+293;
        bool r360280 = r360264 <= r360279;
        double r360281 = -1.0;
        double r360282 = r360280 ? r360276 : r360281;
        double r360283 = r360278 ? r360267 : r360282;
        double r360284 = r360269 ? r360276 : r360283;
        double r360285 = r360266 ? r360267 : r360284;
        return r360285;
}

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.5
Target31.2
Herbie12.9
\[\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) < 4.9406564584125e-324 or 2.6510033806694153e-246 < (* (* y 4.0) y) < 2.009105932256526e-105

    1. Initial program 25.7

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

      \[\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. Taylor expanded around inf 12.7

      \[\leadsto \log \color{blue}{e}\]

    if 4.9406564584125e-324 < (* (* y 4.0) y) < 2.6510033806694153e-246 or 2.009105932256526e-105 < (* (* y 4.0) y) < 2.232837377283158e+293

    1. Initial program 15.5

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

      \[\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)}\]

    if 2.232837377283158e+293 < (* (* y 4.0) y)

    1. Initial program 61.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 4.94066 \cdot 10^{-324}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.6510033806694153 \cdot 10^{-246}:\\ \;\;\;\;\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)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.00910593225652596 \cdot 10^{-105}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.23283737728315802 \cdot 10^{293}:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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