Average Error: 32.1 → 5.7
Time: 3.2s
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 -5.29734148790873495 \cdot 10^{156}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le 1.3249836726640813 \cdot 10^{154}:\\ \;\;\;\;\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, x \cdot \frac{x}{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 -5.29734148790873495 \cdot 10^{156}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le 1.3249836726640813 \cdot 10^{154}:\\
\;\;\;\;\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, x \cdot \frac{x}{y}\right)}\\

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

\end{array}
double f(double x, double y) {
        double r602290 = x;
        double r602291 = r602290 * r602290;
        double r602292 = y;
        double r602293 = 4.0;
        double r602294 = r602292 * r602293;
        double r602295 = r602294 * r602292;
        double r602296 = r602291 - r602295;
        double r602297 = r602291 + r602295;
        double r602298 = r602296 / r602297;
        return r602298;
}

double f(double x, double y) {
        double r602299 = x;
        double r602300 = -5.297341487908735e+156;
        bool r602301 = r602299 <= r602300;
        double r602302 = 1.0;
        double r602303 = 1.3249836726640813e+154;
        bool r602304 = r602299 <= r602303;
        double r602305 = y;
        double r602306 = 4.0;
        double r602307 = r602305 * r602306;
        double r602308 = r602307 * r602305;
        double r602309 = fma(r602299, r602299, r602308);
        double r602310 = r602309 / r602299;
        double r602311 = r602299 / r602310;
        double r602312 = r602299 / r602305;
        double r602313 = r602299 * r602312;
        double r602314 = fma(r602306, r602305, r602313);
        double r602315 = r602307 / r602314;
        double r602316 = r602311 - r602315;
        double r602317 = r602304 ? r602316 : r602302;
        double r602318 = r602301 ? r602302 : r602317;
        return r602318;
}

Error

Bits error versus x

Bits error versus y

Target

Original32.1
Target31.8
Herbie5.7
\[\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 x < -5.297341487908735e+156 or 1.3249836726640813e+154 < x

    1. Initial program 64.0

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

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

    if -5.297341487908735e+156 < x < 1.3249836726640813e+154

    1. Initial program 21.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-sub21.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. Simplified21.3

      \[\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. Simplified21.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 4.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. Simplified4.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. Using strategy rm
    9. Applied *-un-lft-identity4.9

      \[\leadsto \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}}{\color{blue}{1 \cdot y}}\right)}\]
    10. Applied add-sqr-sqrt34.3

      \[\leadsto \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{{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}}^{2}}{1 \cdot y}\right)}\]
    11. Applied unpow-prod-down34.3

      \[\leadsto \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{\color{blue}{{\left(\sqrt{x}\right)}^{2} \cdot {\left(\sqrt{x}\right)}^{2}}}{1 \cdot y}\right)}\]
    12. Applied times-frac34.3

      \[\leadsto \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, \color{blue}{\frac{{\left(\sqrt{x}\right)}^{2}}{1} \cdot \frac{{\left(\sqrt{x}\right)}^{2}}{y}}\right)}\]
    13. Simplified34.3

      \[\leadsto \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, \color{blue}{x} \cdot \frac{{\left(\sqrt{x}\right)}^{2}}{y}\right)}\]
    14. Simplified4.8

      \[\leadsto \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, x \cdot \color{blue}{\frac{x}{y}}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification5.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.29734148790873495 \cdot 10^{156}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le 1.3249836726640813 \cdot 10^{154}:\\ \;\;\;\;\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, x \cdot \frac{x}{y}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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