Average Error: 31.3 → 12.6
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 \cdot x \le 1.04662384361210072 \cdot 10^{-202}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.3005275433696336 \cdot 10^{250}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \mathbf{elif}\;x \cdot x \le 2.97717800904674578 \cdot 10^{272}:\\ \;\;\;\;-1\\ \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 \cdot x \le 1.04662384361210072 \cdot 10^{-202}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \cdot x \le 2.97717800904674578 \cdot 10^{272}:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r679967 = x;
        double r679968 = r679967 * r679967;
        double r679969 = y;
        double r679970 = 4.0;
        double r679971 = r679969 * r679970;
        double r679972 = r679971 * r679969;
        double r679973 = r679968 - r679972;
        double r679974 = r679968 + r679972;
        double r679975 = r679973 / r679974;
        return r679975;
}

double f(double x, double y) {
        double r679976 = x;
        double r679977 = r679976 * r679976;
        double r679978 = 1.0466238436121007e-202;
        bool r679979 = r679977 <= r679978;
        double r679980 = -1.0;
        double r679981 = 1.3005275433696336e+250;
        bool r679982 = r679977 <= r679981;
        double r679983 = y;
        double r679984 = 4.0;
        double r679985 = r679983 * r679984;
        double r679986 = r679985 * r679983;
        double r679987 = fma(r679976, r679976, r679986);
        double r679988 = r679987 / r679976;
        double r679989 = r679976 / r679988;
        double r679990 = r679987 / r679983;
        double r679991 = r679985 / r679990;
        double r679992 = r679989 - r679991;
        double r679993 = 2.977178009046746e+272;
        bool r679994 = r679977 <= r679993;
        double r679995 = 1.0;
        double r679996 = r679994 ? r679980 : r679995;
        double r679997 = r679982 ? r679992 : r679996;
        double r679998 = r679979 ? r679980 : r679997;
        return r679998;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.3
Target31.0
Herbie12.6
\[\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 x) < 1.0466238436121007e-202 or 1.3005275433696336e+250 < (* x x) < 2.977178009046746e+272

    1. Initial program 25.6

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

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

    if 1.0466238436121007e-202 < (* x x) < 1.3005275433696336e+250

    1. Initial program 15.7

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

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

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

      \[\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}}}\]

    if 2.977178009046746e+272 < (* x x)

    1. Initial program 59.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 1.04662384361210072 \cdot 10^{-202}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.3005275433696336 \cdot 10^{250}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \mathbf{elif}\;x \cdot x \le 2.97717800904674578 \cdot 10^{272}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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