Average Error: 32.0 → 3.8
Time: 4.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}\;y \le -8.629188524547341 \cdot 10^{-170} \lor \neg \left(y \le 1.9187342776890177 \cdot 10^{-228}\right):\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(4, \frac{y}{\frac{x}{y}}, x\right)} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(4, \frac{y}{\frac{x}{y}}, x\right)} - 0\\ \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 -8.629188524547341 \cdot 10^{-170} \lor \neg \left(y \le 1.9187342776890177 \cdot 10^{-228}\right):\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(4, \frac{y}{\frac{x}{y}}, x\right)} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(4, \frac{y}{\frac{x}{y}}, x\right)} - 0\\

\end{array}
double f(double x, double y) {
        double r675887 = x;
        double r675888 = r675887 * r675887;
        double r675889 = y;
        double r675890 = 4.0;
        double r675891 = r675889 * r675890;
        double r675892 = r675891 * r675889;
        double r675893 = r675888 - r675892;
        double r675894 = r675888 + r675892;
        double r675895 = r675893 / r675894;
        return r675895;
}

double f(double x, double y) {
        double r675896 = y;
        double r675897 = -8.629188524547341e-170;
        bool r675898 = r675896 <= r675897;
        double r675899 = 1.9187342776890177e-228;
        bool r675900 = r675896 <= r675899;
        double r675901 = !r675900;
        bool r675902 = r675898 || r675901;
        double r675903 = x;
        double r675904 = 4.0;
        double r675905 = r675903 / r675896;
        double r675906 = r675896 / r675905;
        double r675907 = fma(r675904, r675906, r675903);
        double r675908 = r675903 / r675907;
        double r675909 = r675896 * r675904;
        double r675910 = 2.0;
        double r675911 = pow(r675903, r675910);
        double r675912 = r675911 / r675896;
        double r675913 = fma(r675904, r675896, r675912);
        double r675914 = r675909 / r675913;
        double r675915 = r675908 - r675914;
        double r675916 = 0.0;
        double r675917 = r675908 - r675916;
        double r675918 = r675902 ? r675915 : r675917;
        return r675918;
}

Error

Bits error versus x

Bits error versus y

Target

Original32.0
Target31.7
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.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 < -8.629188524547341e-170 or 1.9187342776890177e-228 < y

    1. Initial program 32.2

      \[\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-sub32.2

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

      \[\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. Simplified31.4

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

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

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

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

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

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

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

    if -8.629188524547341e-170 < y < 1.9187342776890177e-228

    1. Initial program 31.0

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

      \[\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. Simplified31.0

      \[\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. Simplified31.0

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -8.629188524547341 \cdot 10^{-170} \lor \neg \left(y \le 1.9187342776890177 \cdot 10^{-228}\right):\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(4, \frac{y}{\frac{x}{y}}, x\right)} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(4, \frac{y}{\frac{x}{y}}, x\right)} - 0\\ \end{array}\]

Reproduce

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