Average Error: 31.6 → 15.2
Time: 1.8s
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 -63251142091289.1171875:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.290862168683378961818111596644617079501 \cdot 10^{-48}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -8.787782021166910304238432501004388722475 \cdot 10^{-128}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \mathbf{elif}\;x \le 257159.2504167575680185109376907348632812:\\ \;\;\;\;-1\\ \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 -63251142091289.1171875:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -1.290862168683378961818111596644617079501 \cdot 10^{-48}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -8.787782021166910304238432501004388722475 \cdot 10^{-128}:\\
\;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\

\mathbf{elif}\;x \le 257159.2504167575680185109376907348632812:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r967760 = x;
        double r967761 = r967760 * r967760;
        double r967762 = y;
        double r967763 = 4.0;
        double r967764 = r967762 * r967763;
        double r967765 = r967764 * r967762;
        double r967766 = r967761 - r967765;
        double r967767 = r967761 + r967765;
        double r967768 = r967766 / r967767;
        return r967768;
}

double f(double x, double y) {
        double r967769 = x;
        double r967770 = -63251142091289.12;
        bool r967771 = r967769 <= r967770;
        double r967772 = 1.0;
        double r967773 = -1.290862168683379e-48;
        bool r967774 = r967769 <= r967773;
        double r967775 = -1.0;
        double r967776 = -8.78778202116691e-128;
        bool r967777 = r967769 <= r967776;
        double r967778 = y;
        double r967779 = 4.0;
        double r967780 = r967778 * r967779;
        double r967781 = r967780 * r967778;
        double r967782 = fma(r967769, r967769, r967781);
        double r967783 = r967782 / r967769;
        double r967784 = r967769 / r967783;
        double r967785 = r967782 / r967778;
        double r967786 = r967780 / r967785;
        double r967787 = r967784 - r967786;
        double r967788 = 257159.25041675757;
        bool r967789 = r967769 <= r967788;
        double r967790 = r967789 ? r967775 : r967772;
        double r967791 = r967777 ? r967787 : r967790;
        double r967792 = r967774 ? r967775 : r967791;
        double r967793 = r967771 ? r967772 : r967792;
        return r967793;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.6
Target31.3
Herbie15.2
\[\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 < -63251142091289.12 or 257159.25041675757 < x

    1. Initial program 40.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 15.0

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

    if -63251142091289.12 < x < -1.290862168683379e-48 or -8.78778202116691e-128 < x < 257159.25041675757

    1. Initial program 24.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 15.4

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

    if -1.290862168683379e-48 < x < -8.78778202116691e-128

    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 div-sub15.7

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

      \[\leadsto \color{blue}{\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    5. Simplified15.2

      \[\leadsto \frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \color{blue}{\frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification15.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -63251142091289.1171875:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.290862168683378961818111596644617079501 \cdot 10^{-48}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -8.787782021166910304238432501004388722475 \cdot 10^{-128}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \mathbf{elif}\;x \le 257159.2504167575680185109376907348632812:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019362 +o rules:numerics
(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))))