Average Error: 31.7 → 12.4
Time: 12.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}\;\left(y \cdot 4\right) \cdot y \le 1.883987095627688634773256576903935146579 \cdot 10^{-179}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 25951328951665387827625984:\\ \;\;\;\;\frac{1}{\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 56309717854388472133950898176:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.251271519567312889559392701775878259286 \cdot 10^{285}:\\ \;\;\;\;\frac{1}{\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 1.883987095627688634773256576903935146579 \cdot 10^{-179}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 25951328951665387827625984:\\
\;\;\;\;\frac{1}{\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 56309717854388472133950898176:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.251271519567312889559392701775878259286 \cdot 10^{285}:\\
\;\;\;\;\frac{1}{\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 r543270 = x;
        double r543271 = r543270 * r543270;
        double r543272 = y;
        double r543273 = 4.0;
        double r543274 = r543272 * r543273;
        double r543275 = r543274 * r543272;
        double r543276 = r543271 - r543275;
        double r543277 = r543271 + r543275;
        double r543278 = r543276 / r543277;
        return r543278;
}

double f(double x, double y) {
        double r543279 = y;
        double r543280 = 4.0;
        double r543281 = r543279 * r543280;
        double r543282 = r543281 * r543279;
        double r543283 = 1.8839870956276886e-179;
        bool r543284 = r543282 <= r543283;
        double r543285 = 1.0;
        double r543286 = 2.5951328951665388e+25;
        bool r543287 = r543282 <= r543286;
        double r543288 = x;
        double r543289 = r543288 * r543288;
        double r543290 = r543289 + r543282;
        double r543291 = r543289 - r543282;
        double r543292 = r543290 / r543291;
        double r543293 = r543285 / r543292;
        double r543294 = 5.630971785438847e+28;
        bool r543295 = r543282 <= r543294;
        double r543296 = 7.251271519567313e+285;
        bool r543297 = r543282 <= r543296;
        double r543298 = -1.0;
        double r543299 = r543297 ? r543293 : r543298;
        double r543300 = r543295 ? r543285 : r543299;
        double r543301 = r543287 ? r543293 : r543300;
        double r543302 = r543284 ? r543285 : r543301;
        return r543302;
}

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.7
Target31.4
Herbie12.4
\[\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 (* (* y 4.0) y) < 1.8839870956276886e-179 or 2.5951328951665388e+25 < (* (* y 4.0) y) < 5.630971785438847e+28

    1. Initial program 26.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 clear-num26.3

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    4. Taylor expanded around inf 11.7

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

    if 1.8839870956276886e-179 < (* (* y 4.0) y) < 2.5951328951665388e+25 or 5.630971785438847e+28 < (* (* y 4.0) y) < 7.251271519567313e+285

    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}\]
    2. Using strategy rm
    3. Applied clear-num15.7

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

    if 7.251271519567313e+285 < (* (* y 4.0) y)

    1. Initial program 61.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 8.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 1.883987095627688634773256576903935146579 \cdot 10^{-179}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 25951328951665387827625984:\\ \;\;\;\;\frac{1}{\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 56309717854388472133950898176:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.251271519567312889559392701775878259286 \cdot 10^{285}:\\ \;\;\;\;\frac{1}{\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 2019323 
(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))))