Average Error: 31.3 → 12.3
Time: 2.5s
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.6533496348093263 \cdot 10^{136}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -8.5079988842821871 \cdot 10^{-92}:\\ \;\;\;\;\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 5.33120441752882848 \cdot 10^{-100}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.6140055087642122 \cdot 10^{150}:\\ \;\;\;\;\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{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.6533496348093263 \cdot 10^{136}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -8.5079988842821871 \cdot 10^{-92}:\\
\;\;\;\;\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 5.33120441752882848 \cdot 10^{-100}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 1.6140055087642122 \cdot 10^{150}:\\
\;\;\;\;\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{else}:\\
\;\;\;\;1\\

\end{array}
double f(double x, double y) {
        double r637712 = x;
        double r637713 = r637712 * r637712;
        double r637714 = y;
        double r637715 = 4.0;
        double r637716 = r637714 * r637715;
        double r637717 = r637716 * r637714;
        double r637718 = r637713 - r637717;
        double r637719 = r637713 + r637717;
        double r637720 = r637718 / r637719;
        return r637720;
}

double f(double x, double y) {
        double r637721 = x;
        double r637722 = -1.6533496348093263e+136;
        bool r637723 = r637721 <= r637722;
        double r637724 = 1.0;
        double r637725 = -8.507998884282187e-92;
        bool r637726 = r637721 <= r637725;
        double r637727 = y;
        double r637728 = 4.0;
        double r637729 = r637727 * r637728;
        double r637730 = r637729 * r637727;
        double r637731 = fma(r637721, r637721, r637730);
        double r637732 = r637731 / r637721;
        double r637733 = r637721 / r637732;
        double r637734 = r637731 / r637727;
        double r637735 = r637729 / r637734;
        double r637736 = r637733 - r637735;
        double r637737 = 5.331204417528828e-100;
        bool r637738 = r637721 <= r637737;
        double r637739 = -1.0;
        double r637740 = 1.6140055087642122e+150;
        bool r637741 = r637721 <= r637740;
        double r637742 = r637741 ? r637736 : r637724;
        double r637743 = r637738 ? r637739 : r637742;
        double r637744 = r637726 ? r637736 : r637743;
        double r637745 = r637723 ? r637724 : r637744;
        return r637745;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.3
Target31.0
Herbie12.3
\[\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 3 regimes
  2. if x < -1.6533496348093263e+136 or 1.6140055087642122e+150 < x

    1. Initial program 60.3

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

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

    if -1.6533496348093263e+136 < x < -8.507998884282187e-92 or 5.331204417528828e-100 < x < 1.6140055087642122e+150

    1. Initial program 15.6

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

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

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

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

    if -8.507998884282187e-92 < x < 5.331204417528828e-100

    1. Initial program 27.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.6533496348093263 \cdot 10^{136}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -8.5079988842821871 \cdot 10^{-92}:\\ \;\;\;\;\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 5.33120441752882848 \cdot 10^{-100}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.6140055087642122 \cdot 10^{150}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2020100 +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))))