Average Error: 31.7 → 14.8
Time: 2.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 -6.06717838938592463 \cdot 10^{31}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le 5.2797885245263103 \cdot 10^{-80}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 5.32364720038125515 \cdot 10^{39}:\\ \;\;\;\;\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}}\\ \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 -6.06717838938592463 \cdot 10^{31}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le 5.2797885245263103 \cdot 10^{-80}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 5.32364720038125515 \cdot 10^{39}:\\
\;\;\;\;\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}}\\

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

\end{array}
double f(double x, double y) {
        double r645856 = x;
        double r645857 = r645856 * r645856;
        double r645858 = y;
        double r645859 = 4.0;
        double r645860 = r645858 * r645859;
        double r645861 = r645860 * r645858;
        double r645862 = r645857 - r645861;
        double r645863 = r645857 + r645861;
        double r645864 = r645862 / r645863;
        return r645864;
}

double f(double x, double y) {
        double r645865 = x;
        double r645866 = -6.067178389385925e+31;
        bool r645867 = r645865 <= r645866;
        double r645868 = 1.0;
        double r645869 = 5.27978852452631e-80;
        bool r645870 = r645865 <= r645869;
        double r645871 = -1.0;
        double r645872 = 5.323647200381255e+39;
        bool r645873 = r645865 <= r645872;
        double r645874 = y;
        double r645875 = 4.0;
        double r645876 = r645874 * r645875;
        double r645877 = r645876 * r645874;
        double r645878 = fma(r645865, r645865, r645877);
        double r645879 = r645865 * r645865;
        double r645880 = r645879 - r645877;
        double r645881 = r645878 / r645880;
        double r645882 = r645868 / r645881;
        double r645883 = r645873 ? r645882 : r645868;
        double r645884 = r645870 ? r645871 : r645883;
        double r645885 = r645867 ? r645868 : r645884;
        return r645885;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.7
Target31.4
Herbie14.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 3 regimes
  2. if x < -6.067178389385925e+31 or 5.323647200381255e+39 < x

    1. Initial program 43.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 inf 14.1

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

    if -6.067178389385925e+31 < x < 5.27978852452631e-80

    1. Initial program 24.4

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

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

    if 5.27978852452631e-80 < x < 5.323647200381255e+39

    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 clear-num15.6

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    4. Simplified15.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.06717838938592463 \cdot 10^{31}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le 5.2797885245263103 \cdot 10^{-80}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 5.32364720038125515 \cdot 10^{39}:\\ \;\;\;\;\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}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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