Average Error: 31.3 → 4.0
Time: 3.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.5004990530179034 \cdot 10^{152}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.3929248153997159 \cdot 10^{-162}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{elif}\;x \le 8.39893520792411963 \cdot 10^{-184}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.34095967395193592 \cdot 10^{153}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \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}\;x \le -1.5004990530179034 \cdot 10^{152}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \le 8.39893520792411963 \cdot 10^{-184}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 1.34095967395193592 \cdot 10^{153}:\\
\;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \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 r647329 = x;
        double r647330 = r647329 * r647329;
        double r647331 = y;
        double r647332 = 4.0;
        double r647333 = r647331 * r647332;
        double r647334 = r647333 * r647331;
        double r647335 = r647330 - r647334;
        double r647336 = r647330 + r647334;
        double r647337 = r647335 / r647336;
        return r647337;
}

double f(double x, double y) {
        double r647338 = x;
        double r647339 = -1.5004990530179034e+152;
        bool r647340 = r647338 <= r647339;
        double r647341 = 1.0;
        double r647342 = -1.3929248153997159e-162;
        bool r647343 = r647338 <= r647342;
        double r647344 = y;
        double r647345 = 4.0;
        double r647346 = r647344 * r647345;
        double r647347 = r647346 * r647344;
        double r647348 = fma(r647338, r647338, r647347);
        double r647349 = r647348 / r647338;
        double r647350 = r647338 / r647349;
        double r647351 = 2.0;
        double r647352 = pow(r647338, r647351);
        double r647353 = r647352 / r647344;
        double r647354 = fma(r647345, r647344, r647353);
        double r647355 = r647346 / r647354;
        double r647356 = r647350 - r647355;
        double r647357 = 8.39893520792412e-184;
        bool r647358 = r647338 <= r647357;
        double r647359 = -1.0;
        double r647360 = 1.340959673951936e+153;
        bool r647361 = r647338 <= r647360;
        double r647362 = r647361 ? r647356 : r647341;
        double r647363 = r647358 ? r647359 : r647362;
        double r647364 = r647343 ? r647356 : r647363;
        double r647365 = r647340 ? r647341 : r647364;
        return r647365;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.3
Target31.0
Herbie4.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 3 regimes
  2. if x < -1.5004990530179034e+152 or 1.340959673951936e+153 < x

    1. Initial program 63.5

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

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

    if -1.5004990530179034e+152 < x < -1.3929248153997159e-162 or 8.39893520792412e-184 < x < 1.340959673951936e+153

    1. Initial program 15.9

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

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

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

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

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

    if -1.3929248153997159e-162 < x < 8.39893520792412e-184

    1. Initial program 31.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 7.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.5004990530179034 \cdot 10^{152}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.3929248153997159 \cdot 10^{-162}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{elif}\;x \le 8.39893520792411963 \cdot 10^{-184}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.34095967395193592 \cdot 10^{153}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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