Average Error: 31.1 → 3.8
Time: 2.7s
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.331887172847139076544407291057659922741 \cdot 10^{154}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.570784445226952748816445846527769860735 \cdot 10^{-162}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{elif}\;x \le 6.596793469983033519295935857748423121887 \cdot 10^{-163}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.373484080558642358416244903315687209789 \cdot 10^{144}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \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.331887172847139076544407291057659922741 \cdot 10^{154}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \le 6.596793469983033519295935857748423121887 \cdot 10^{-163}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r602890 = x;
        double r602891 = r602890 * r602890;
        double r602892 = y;
        double r602893 = 4.0;
        double r602894 = r602892 * r602893;
        double r602895 = r602894 * r602892;
        double r602896 = r602891 - r602895;
        double r602897 = r602891 + r602895;
        double r602898 = r602896 / r602897;
        return r602898;
}

double f(double x, double y) {
        double r602899 = x;
        double r602900 = -1.3318871728471391e+154;
        bool r602901 = r602899 <= r602900;
        double r602902 = 1.0;
        double r602903 = -1.5707844452269527e-162;
        bool r602904 = r602899 <= r602903;
        double r602905 = y;
        double r602906 = 4.0;
        double r602907 = r602905 * r602906;
        double r602908 = r602907 * r602905;
        double r602909 = fma(r602899, r602899, r602908);
        double r602910 = r602909 / r602899;
        double r602911 = r602899 / r602910;
        double r602912 = 2.0;
        double r602913 = pow(r602899, r602912);
        double r602914 = r602913 / r602905;
        double r602915 = fma(r602906, r602905, r602914);
        double r602916 = r602907 / r602915;
        double r602917 = r602911 - r602916;
        double r602918 = 6.596793469983034e-163;
        bool r602919 = r602899 <= r602918;
        double r602920 = -1.0;
        double r602921 = 6.373484080558642e+144;
        bool r602922 = r602899 <= r602921;
        double r602923 = r602922 ? r602917 : r602902;
        double r602924 = r602919 ? r602920 : r602923;
        double r602925 = r602904 ? r602917 : r602924;
        double r602926 = r602901 ? r602902 : r602925;
        return r602926;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.1
Target30.8
Herbie3.8
\[\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.3318871728471391e+154 or 6.373484080558642e+144 < x

    1. Initial program 62.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 8.4

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

    if -1.3318871728471391e+154 < x < -1.5707844452269527e-162 or 6.596793469983034e-163 < x < 6.373484080558642e+144

    1. Initial program 15.9

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

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

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

      \[\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}}}\]
    6. Taylor expanded around 0 0.3

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

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

    if -1.5707844452269527e-162 < x < 6.596793469983034e-163

    1. Initial program 30.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 6.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.331887172847139076544407291057659922741 \cdot 10^{154}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.570784445226952748816445846527769860735 \cdot 10^{-162}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{elif}\;x \le 6.596793469983033519295935857748423121887 \cdot 10^{-163}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.373484080558642358416244903315687209789 \cdot 10^{144}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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