Average Error: 32.0 → 12.6
Time: 4.1s
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 \le -1.15431295039553488213566106957485115951 \cdot 10^{123}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.049461047373995695414776940334688667457 \cdot 10^{-90}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 5.481288829847034474742950694868171684444 \cdot 10^{-119}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 7.251238886375513779793874451315946152856 \cdot 10^{-42}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 2.637073173922210812467059604102814773796 \cdot 10^{-4}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.73515077677864244964006142406283884833 \cdot 10^{127}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{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 \le -1.15431295039553488213566106957485115951 \cdot 10^{123}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \le 5.481288829847034474742950694868171684444 \cdot 10^{-119}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \le 2.637073173922210812467059604102814773796 \cdot 10^{-4}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r440505 = x;
        double r440506 = r440505 * r440505;
        double r440507 = y;
        double r440508 = 4.0;
        double r440509 = r440507 * r440508;
        double r440510 = r440509 * r440507;
        double r440511 = r440506 - r440510;
        double r440512 = r440506 + r440510;
        double r440513 = r440511 / r440512;
        return r440513;
}

double f(double x, double y) {
        double r440514 = x;
        double r440515 = -1.1543129503955349e+123;
        bool r440516 = r440514 <= r440515;
        double r440517 = 1.0;
        double r440518 = -1.0494610473739957e-90;
        bool r440519 = r440514 <= r440518;
        double r440520 = r440514 * r440514;
        double r440521 = y;
        double r440522 = 4.0;
        double r440523 = r440521 * r440522;
        double r440524 = r440523 * r440521;
        double r440525 = r440520 - r440524;
        double r440526 = r440520 + r440524;
        double r440527 = sqrt(r440526);
        double r440528 = r440525 / r440527;
        double r440529 = r440528 / r440527;
        double r440530 = 5.481288829847034e-119;
        bool r440531 = r440514 <= r440530;
        double r440532 = -1.0;
        double r440533 = 7.251238886375514e-42;
        bool r440534 = r440514 <= r440533;
        double r440535 = 0.0002637073173922211;
        bool r440536 = r440514 <= r440535;
        double r440537 = 4.735150776778642e+127;
        bool r440538 = r440514 <= r440537;
        double r440539 = r440538 ? r440529 : r440517;
        double r440540 = r440536 ? r440532 : r440539;
        double r440541 = r440534 ? r440529 : r440540;
        double r440542 = r440531 ? r440532 : r440541;
        double r440543 = r440519 ? r440529 : r440542;
        double r440544 = r440516 ? r440517 : r440543;
        return r440544;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.0
Target31.8
Herbie12.6
\[\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 < -1.1543129503955349e+123 or 4.735150776778642e+127 < x

    1. Initial program 56.5

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

    if -1.1543129503955349e+123 < x < -1.0494610473739957e-90 or 5.481288829847034e-119 < x < 7.251238886375514e-42 or 0.0002637073173922211 < x < 4.735150776778642e+127

    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 add-sqr-sqrt15.7

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\]
    4. Applied associate-/r*15.8

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

    if -1.0494610473739957e-90 < x < 5.481288829847034e-119 or 7.251238886375514e-42 < x < 0.0002637073173922211

    1. Initial program 26.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.15431295039553488213566106957485115951 \cdot 10^{123}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.049461047373995695414776940334688667457 \cdot 10^{-90}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 5.481288829847034474742950694868171684444 \cdot 10^{-119}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 7.251238886375513779793874451315946152856 \cdot 10^{-42}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 2.637073173922210812467059604102814773796 \cdot 10^{-4}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.73515077677864244964006142406283884833 \cdot 10^{127}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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