Average Error: 31.8 → 12.7
Time: 6.2s
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.376122509742530877543344174301183479676 \cdot 10^{-251}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.285582852365793226651820472382056127268 \cdot 10^{-180}:\\ \;\;\;\;\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}\\ \mathbf{elif}\;x \cdot x \le 1.220088560819746934993661344775764994096 \cdot 10^{-131}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 6.180077099071456665238677691645979687927 \cdot 10^{191}:\\ \;\;\;\;\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}\\ \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.376122509742530877543344174301183479676 \cdot 10^{-251}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 2.285582852365793226651820472382056127268 \cdot 10^{-180}:\\
\;\;\;\;\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}\\

\mathbf{elif}\;x \cdot x \le 1.220088560819746934993661344775764994096 \cdot 10^{-131}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 6.180077099071456665238677691645979687927 \cdot 10^{191}:\\
\;\;\;\;\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}\\

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

\end{array}
double f(double x, double y) {
        double r440325 = x;
        double r440326 = r440325 * r440325;
        double r440327 = y;
        double r440328 = 4.0;
        double r440329 = r440327 * r440328;
        double r440330 = r440329 * r440327;
        double r440331 = r440326 - r440330;
        double r440332 = r440326 + r440330;
        double r440333 = r440331 / r440332;
        return r440333;
}

double f(double x, double y) {
        double r440334 = x;
        double r440335 = r440334 * r440334;
        double r440336 = 1.3761225097425309e-251;
        bool r440337 = r440335 <= r440336;
        double r440338 = -1.0;
        double r440339 = 2.2855828523657932e-180;
        bool r440340 = r440335 <= r440339;
        double r440341 = y;
        double r440342 = 4.0;
        double r440343 = r440341 * r440342;
        double r440344 = r440343 * r440341;
        double r440345 = r440335 + r440344;
        double r440346 = r440335 / r440345;
        double r440347 = r440344 / r440345;
        double r440348 = r440346 - r440347;
        double r440349 = 1.220088560819747e-131;
        bool r440350 = r440335 <= r440349;
        double r440351 = 6.180077099071457e+191;
        bool r440352 = r440335 <= r440351;
        double r440353 = 1.0;
        double r440354 = r440352 ? r440348 : r440353;
        double r440355 = r440350 ? r440338 : r440354;
        double r440356 = r440340 ? r440348 : r440355;
        double r440357 = r440337 ? r440338 : r440356;
        return r440357;
}

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.8
Target31.5
Herbie12.7
\[\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.9743233849626781184483093056769575923681:\\ \;\;\;\;\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) < 1.3761225097425309e-251 or 2.2855828523657932e-180 < (* x x) < 1.220088560819747e-131

    1. Initial program 27.4

      \[\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 10.5

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

    if 1.3761225097425309e-251 < (* x x) < 2.2855828523657932e-180 or 1.220088560819747e-131 < (* x x) < 6.180077099071457e+191

    1. Initial program 16.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-sub16.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}}\]

    if 6.180077099071457e+191 < (* x x)

    1. Initial program 50.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 11.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 1.376122509742530877543344174301183479676 \cdot 10^{-251}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.285582852365793226651820472382056127268 \cdot 10^{-180}:\\ \;\;\;\;\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}\\ \mathbf{elif}\;x \cdot x \le 1.220088560819746934993661344775764994096 \cdot 10^{-131}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 6.180077099071456665238677691645979687927 \cdot 10^{191}:\\ \;\;\;\;\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}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019298 
(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.974323384962678118) (- (/ (* 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))))