Average Error: 31.9 → 12.8
Time: 2.6s
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 \cdot x \le 1.51233920017420984 \cdot 10^{-184}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 259753368901583.88:\\ \;\;\;\;\log \left(e^{\left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} + \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\right)\\ \mathbf{elif}\;x \cdot x \le 4.9513109421031689 \cdot 10^{37}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.4348180576052783 \cdot 10^{267}:\\ \;\;\;\;\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}\;x \cdot x \le 1.51233920017420984 \cdot 10^{-184}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 259753368901583.88:\\
\;\;\;\;\log \left(e^{\left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} + \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\right)\\

\mathbf{elif}\;x \cdot x \le 4.9513109421031689 \cdot 10^{37}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 1.4348180576052783 \cdot 10^{267}:\\
\;\;\;\;\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 r781240 = x;
        double r781241 = r781240 * r781240;
        double r781242 = y;
        double r781243 = 4.0;
        double r781244 = r781242 * r781243;
        double r781245 = r781244 * r781242;
        double r781246 = r781241 - r781245;
        double r781247 = r781241 + r781245;
        double r781248 = r781246 / r781247;
        return r781248;
}

double f(double x, double y) {
        double r781249 = x;
        double r781250 = r781249 * r781249;
        double r781251 = 1.5123392001742098e-184;
        bool r781252 = r781250 <= r781251;
        double r781253 = 1.0;
        double r781254 = -r781253;
        double r781255 = 259753368901583.88;
        bool r781256 = r781250 <= r781255;
        double r781257 = y;
        double r781258 = 4.0;
        double r781259 = r781257 * r781258;
        double r781260 = r781259 * r781257;
        double r781261 = r781250 + r781260;
        double r781262 = r781250 / r781261;
        double r781263 = sqrt(r781262);
        double r781264 = r781260 / r781261;
        double r781265 = sqrt(r781264);
        double r781266 = r781263 + r781265;
        double r781267 = r781263 - r781265;
        double r781268 = r781266 * r781267;
        double r781269 = exp(r781268);
        double r781270 = log(r781269);
        double r781271 = 4.951310942103169e+37;
        bool r781272 = r781250 <= r781271;
        double r781273 = 1.4348180576052783e+267;
        bool r781274 = r781250 <= r781273;
        double r781275 = r781250 - r781260;
        double r781276 = r781275 / r781261;
        double r781277 = exp(r781276);
        double r781278 = log(r781277);
        double r781279 = 1.0;
        double r781280 = r781274 ? r781278 : r781279;
        double r781281 = r781272 ? r781254 : r781280;
        double r781282 = r781256 ? r781270 : r781281;
        double r781283 = r781252 ? r781254 : r781282;
        return r781283;
}

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
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} \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 4 regimes
  2. if (* x x) < 1.5123392001742098e-184 or 259753368901583.88 < (* x x) < 4.951310942103169e+37

    1. Initial program 25.9

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

      \[\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. Using strategy rm
    5. Applied div-sub25.9

      \[\leadsto \log \left(e^{\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}}}\right)\]
    6. Taylor expanded around 0 11.9

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

    if 1.5123392001742098e-184 < (* x x) < 259753368901583.88

    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 add-log-exp16.1

      \[\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. Using strategy rm
    5. Applied div-sub16.1

      \[\leadsto \log \left(e^{\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}}}\right)\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt16.1

      \[\leadsto \log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \color{blue}{\sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}}\right)\]
    8. Applied add-sqr-sqrt16.1

      \[\leadsto \log \left(e^{\color{blue}{\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\]
    9. Applied difference-of-squares16.1

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

    if 4.951310942103169e+37 < (* x x) < 1.4348180576052783e+267

    1. Initial program 16.4

      \[\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-exp16.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 1.4348180576052783e+267 < (* x x)

    1. Initial program 58.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 inf 9.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 1.51233920017420984 \cdot 10^{-184}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 259753368901583.88:\\ \;\;\;\;\log \left(e^{\left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} + \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\right)\\ \mathbf{elif}\;x \cdot x \le 4.9513109421031689 \cdot 10^{37}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.4348180576052783 \cdot 10^{267}:\\ \;\;\;\;\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 2020025 
(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))))