Average Error: 32.4 → 12.2
Time: 5.0s
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.10209323570294511 \cdot 10^{154}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -7.05570383594217736 \cdot 10^{-134}:\\ \;\;\;\;\frac{1}{\sqrt[3]{{\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}\right)}^{3}}}\\ \mathbf{elif}\;x \le 3.30957855650517974 \cdot 10^{-97}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.70835173311075 \cdot 10^{105}:\\ \;\;\;\;\frac{1}{\sqrt[3]{{\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}\right)}^{3}}}\\ \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.10209323570294511 \cdot 10^{154}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -7.05570383594217736 \cdot 10^{-134}:\\
\;\;\;\;\frac{1}{\sqrt[3]{{\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}\right)}^{3}}}\\

\mathbf{elif}\;x \le 3.30957855650517974 \cdot 10^{-97}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 2.70835173311075 \cdot 10^{105}:\\
\;\;\;\;\frac{1}{\sqrt[3]{{\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}\right)}^{3}}}\\

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

\end{array}
double f(double x, double y) {
        double r794829 = x;
        double r794830 = r794829 * r794829;
        double r794831 = y;
        double r794832 = 4.0;
        double r794833 = r794831 * r794832;
        double r794834 = r794833 * r794831;
        double r794835 = r794830 - r794834;
        double r794836 = r794830 + r794834;
        double r794837 = r794835 / r794836;
        return r794837;
}

double f(double x, double y) {
        double r794838 = x;
        double r794839 = -1.1020932357029451e+154;
        bool r794840 = r794838 <= r794839;
        double r794841 = 1.0;
        double r794842 = -7.055703835942177e-134;
        bool r794843 = r794838 <= r794842;
        double r794844 = y;
        double r794845 = 4.0;
        double r794846 = r794844 * r794845;
        double r794847 = r794844 * r794846;
        double r794848 = fma(r794838, r794838, r794847);
        double r794849 = r794838 * r794838;
        double r794850 = r794849 - r794847;
        double r794851 = r794848 / r794850;
        double r794852 = 3.0;
        double r794853 = pow(r794851, r794852);
        double r794854 = cbrt(r794853);
        double r794855 = r794841 / r794854;
        double r794856 = 3.3095785565051797e-97;
        bool r794857 = r794838 <= r794856;
        double r794858 = -1.0;
        double r794859 = 2.70835173311075e+105;
        bool r794860 = r794838 <= r794859;
        double r794861 = r794860 ? r794855 : r794841;
        double r794862 = r794857 ? r794858 : r794861;
        double r794863 = r794843 ? r794855 : r794862;
        double r794864 = r794840 ? r794841 : r794863;
        return r794864;
}

Error

Bits error versus x

Bits error versus y

Target

Original32.4
Target32.1
Herbie12.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.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.1020932357029451e+154 or 2.70835173311075e+105 < x

    1. Initial program 57.5

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified57.5

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Taylor expanded around inf 9.0

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

    if -1.1020932357029451e+154 < x < -7.055703835942177e-134 or 3.3095785565051797e-97 < x < 2.70835173311075e+105

    1. Initial program 16.4

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified16.4

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Using strategy rm
    4. Applied clear-num16.4

      \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    5. Using strategy rm
    6. Applied add-cbrt-cube45.7

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{\color{blue}{\sqrt[3]{\left(\left(x \cdot x - \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)}}}}\]
    7. Applied add-cbrt-cube45.6

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt[3]{\left(\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}{\sqrt[3]{\left(\left(x \cdot x - \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)}}}\]
    8. Applied cbrt-undiv45.6

      \[\leadsto \frac{1}{\color{blue}{\sqrt[3]{\frac{\left(\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{\left(\left(x \cdot x - \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)}}}}\]
    9. Simplified16.4

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

    if -7.055703835942177e-134 < x < 3.3095785565051797e-97

    1. Initial program 28.8

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified28.8

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Taylor expanded around 0 10.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.10209323570294511 \cdot 10^{154}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -7.05570383594217736 \cdot 10^{-134}:\\ \;\;\;\;\frac{1}{\sqrt[3]{{\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}\right)}^{3}}}\\ \mathbf{elif}\;x \le 3.30957855650517974 \cdot 10^{-97}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.70835173311075 \cdot 10^{105}:\\ \;\;\;\;\frac{1}{\sqrt[3]{{\left(\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}\right)}^{3}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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