Average Error: 31.8 → 12.3
Time: 2.7s
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 r533397 = x;
        double r533398 = r533397 * r533397;
        double r533399 = y;
        double r533400 = 4.0;
        double r533401 = r533399 * r533400;
        double r533402 = r533401 * r533399;
        double r533403 = r533398 - r533402;
        double r533404 = r533398 + r533402;
        double r533405 = r533403 / r533404;
        return r533405;
}

double f(double x, double y) {
        double r533406 = x;
        double r533407 = r533406 * r533406;
        double r533408 = 1.1009678461595335e-279;
        bool r533409 = r533407 <= r533408;
        double r533410 = -1.0;
        double r533411 = 2.3515556900183252e-150;
        bool r533412 = r533407 <= r533411;
        double r533413 = y;
        double r533414 = 4.0;
        double r533415 = r533413 * r533414;
        double r533416 = r533415 * r533413;
        double r533417 = fma(r533406, r533406, r533416);
        double r533418 = r533417 / r533406;
        double r533419 = r533406 / r533418;
        double r533420 = r533417 / r533413;
        double r533421 = r533415 / r533420;
        double r533422 = r533419 - r533421;
        double r533423 = 5.95569082529366e-131;
        bool r533424 = r533407 <= r533423;
        double r533425 = 7.1565475002938845e+289;
        bool r533426 = r533407 <= r533425;
        double r533427 = 1.0;
        double r533428 = r533426 ? r533422 : r533427;
        double r533429 = r533424 ? r533410 : r533428;
        double r533430 = r533412 ? r533422 : r533429;
        double r533431 = r533409 ? r533410 : r533430;
        return r533431;
}

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))))