Average Error: 31.2 → 3.0
Time: 4.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}\;y \le -2.2576090032348994 \cdot 10^{-207} \lor \neg \left(y \le 1.1707538281815936 \cdot 10^{-226}\right):\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(4, \frac{{y}^{1}}{\frac{x}{y}}, x\right)} - \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}\;y \le -2.2576090032348994 \cdot 10^{-207} \lor \neg \left(y \le 1.1707538281815936 \cdot 10^{-226}\right):\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(4, \frac{{y}^{1}}{\frac{x}{y}}, x\right)} - \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 r684073 = x;
        double r684074 = r684073 * r684073;
        double r684075 = y;
        double r684076 = 4.0;
        double r684077 = r684075 * r684076;
        double r684078 = r684077 * r684075;
        double r684079 = r684074 - r684078;
        double r684080 = r684074 + r684078;
        double r684081 = r684079 / r684080;
        return r684081;
}

double f(double x, double y) {
        double r684082 = y;
        double r684083 = -2.2576090032348994e-207;
        bool r684084 = r684082 <= r684083;
        double r684085 = 1.1707538281815936e-226;
        bool r684086 = r684082 <= r684085;
        double r684087 = !r684086;
        bool r684088 = r684084 || r684087;
        double r684089 = x;
        double r684090 = 4.0;
        double r684091 = 1.0;
        double r684092 = pow(r684082, r684091);
        double r684093 = r684089 / r684082;
        double r684094 = r684092 / r684093;
        double r684095 = fma(r684090, r684094, r684089);
        double r684096 = r684089 / r684095;
        double r684097 = r684082 * r684090;
        double r684098 = 2.0;
        double r684099 = pow(r684089, r684098);
        double r684100 = r684099 / r684082;
        double r684101 = fma(r684090, r684082, r684100);
        double r684102 = r684097 / r684101;
        double r684103 = r684096 - r684102;
        double r684104 = r684088 ? r684103 : r684091;
        return r684104;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.2
Target30.9
Herbie3.0
\[\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 2 regimes
  2. if y < -2.2576090032348994e-207 or 1.1707538281815936e-226 < y

    1. Initial program 31.1

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

      \[\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. Simplified30.8

      \[\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. Simplified30.3

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

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

      \[\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)}}\]
    8. Taylor expanded around 0 5.9

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

      \[\leadsto \frac{x}{\color{blue}{\mathsf{fma}\left(4, \frac{{y}^{2}}{x}, x\right)}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\]
    10. Using strategy rm
    11. Applied sqr-pow5.9

      \[\leadsto \frac{x}{\mathsf{fma}\left(4, \frac{\color{blue}{{y}^{\left(\frac{2}{2}\right)} \cdot {y}^{\left(\frac{2}{2}\right)}}}{x}, x\right)} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\]
    12. Applied associate-/l*2.6

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

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

    if -2.2576090032348994e-207 < y < 1.1707538281815936e-226

    1. Initial program 31.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.2576090032348994 \cdot 10^{-207} \lor \neg \left(y \le 1.1707538281815936 \cdot 10^{-226}\right):\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(4, \frac{{y}^{1}}{\frac{x}{y}}, x\right)} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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