Average Error: 31.8 → 12.3
Time: 2.8s
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.1009678461595335 \cdot 10^{-279}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.3515556900183252 \cdot 10^{-150}:\\ \;\;\;\;\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 5.9556908252936597 \cdot 10^{-131}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 7.1565475002938845 \cdot 10^{289}:\\ \;\;\;\;\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{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.1009678461595335 \cdot 10^{-279}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 2.3515556900183252 \cdot 10^{-150}:\\
\;\;\;\;\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 5.9556908252936597 \cdot 10^{-131}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 7.1565475002938845 \cdot 10^{289}:\\
\;\;\;\;\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{else}:\\
\;\;\;\;1\\

\end{array}
double f(double x, double y) {
        double r582272 = x;
        double r582273 = r582272 * r582272;
        double r582274 = y;
        double r582275 = 4.0;
        double r582276 = r582274 * r582275;
        double r582277 = r582276 * r582274;
        double r582278 = r582273 - r582277;
        double r582279 = r582273 + r582277;
        double r582280 = r582278 / r582279;
        return r582280;
}

double f(double x, double y) {
        double r582281 = x;
        double r582282 = r582281 * r582281;
        double r582283 = 1.1009678461595335e-279;
        bool r582284 = r582282 <= r582283;
        double r582285 = -1.0;
        double r582286 = 2.3515556900183252e-150;
        bool r582287 = r582282 <= r582286;
        double r582288 = y;
        double r582289 = 4.0;
        double r582290 = r582288 * r582289;
        double r582291 = r582290 * r582288;
        double r582292 = fma(r582281, r582281, r582291);
        double r582293 = r582292 / r582281;
        double r582294 = r582281 / r582293;
        double r582295 = r582292 / r582288;
        double r582296 = r582290 / r582295;
        double r582297 = r582294 - r582296;
        double r582298 = 5.95569082529366e-131;
        bool r582299 = r582282 <= r582298;
        double r582300 = 7.1565475002938845e+289;
        bool r582301 = r582282 <= r582300;
        double r582302 = 1.0;
        double r582303 = r582301 ? r582297 : r582302;
        double r582304 = r582299 ? r582285 : r582303;
        double r582305 = r582287 ? r582297 : r582304;
        double r582306 = r582284 ? r582285 : r582305;
        return r582306;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.8
Target31.5
Herbie12.3
\[\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.1009678461595335e-279 or 2.3515556900183252e-150 < (* x x) < 5.95569082529366e-131

    1. Initial program 29.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 0 10.2

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

    if 1.1009678461595335e-279 < (* x x) < 2.3515556900183252e-150 or 5.95569082529366e-131 < (* x x) < 7.1565475002938845e+289

    1. Initial program 16.1

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

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

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

      \[\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 7.1565475002938845e+289 < (* x x)

    1. Initial program 61.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 inf 8.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 1.1009678461595335 \cdot 10^{-279}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.3515556900183252 \cdot 10^{-150}:\\ \;\;\;\;\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 5.9556908252936597 \cdot 10^{-131}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 7.1565475002938845 \cdot 10^{289}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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